From af213e48ebe0d20a4aa0ceaf6a285c671d93b485 Mon Sep 17 00:00:00 2001 From: davemay99 Date: Tue, 6 Oct 2020 10:49:15 -0400 Subject: [PATCH] metrics return bytes instead of string for more flexibility --- api/operator.go | 9 ++++----- command/metrics.go | 4 +++- vendor/github.com/hashicorp/nomad/api/operator.go | 9 ++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/api/operator.go b/api/operator.go index e84dd1d4cec..de9fbd7fc7f 100644 --- a/api/operator.go +++ b/api/operator.go @@ -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 } diff --git a/command/metrics.go b/command/metrics.go index 43805c7e276..5ceb3977866 100644 --- a/command/metrics.go +++ b/command/metrics.go @@ -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 } diff --git a/vendor/github.com/hashicorp/nomad/api/operator.go b/vendor/github.com/hashicorp/nomad/api/operator.go index e84dd1d4cec..de9fbd7fc7f 100644 --- a/vendor/github.com/hashicorp/nomad/api/operator.go +++ b/vendor/github.com/hashicorp/nomad/api/operator.go @@ -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 }