Skip to content

Commit

Permalink
metrics return bytes instead of string for more flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
davemay99 authored and fredrikhgrelland committed Oct 22, 2020
1 parent 9b90f5a commit af213e4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
9 changes: 4 additions & 5 deletions api/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,20 @@ func (op *Operator) LicenseGet(q *QueryOptions) (*LicenseReply, *QueryMeta, erro
return &reply, qm, nil
}

func (op *Operator) Metrics(q *QueryOptions) (string, error) {
func (op *Operator) Metrics(q *QueryOptions) ([]byte, error) {
if q == nil {
q = &QueryOptions{}
}

metricsReader, err := op.c.rawQuery("/v1/metrics", q)
if err != nil {
return "", err
return nil, err
}

metricsBytes, err := ioutil.ReadAll(metricsReader)
if err != nil {
return "", err
return nil, err
}

metrics := string(metricsBytes[:])
return metrics, nil
return metricsBytes, nil
}
4 changes: 3 additions & 1 deletion command/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ func (c *OperatorMetricsCommand) Run(args []string) int {
Params: params,
}

resp, err := client.Operator().Metrics(query)
bs, err := client.Operator().Metrics(query)
if err != nil {
c.Ui.Error(fmt.Sprintf("Error getting metrics: %v", err))
return 1
}

resp := string(bs[:])
c.Ui.Output(resp)

return 0
}
9 changes: 4 additions & 5 deletions vendor/github.com/hashicorp/nomad/api/operator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af213e4

Please sign in to comment.