diff --git a/cmd/metrics/parser.go b/cmd/metrics/parser.go index 019cfcf..42566a4 100644 --- a/cmd/metrics/parser.go +++ b/cmd/metrics/parser.go @@ -58,6 +58,7 @@ var MetricCmd = &cobra.Command{ log.Debugf("start to parse metrics line by line\n") var rx []*metrics.MetricMatcher + scanner := bufio.NewScanner(r) for scanner.Scan() { line := scanner.Text() diff --git a/pkg/metrics/parser.go b/pkg/metrics/parser.go index 35ab005..11a1340 100644 --- a/pkg/metrics/parser.go +++ b/pkg/metrics/parser.go @@ -150,9 +150,13 @@ func init() { } func (mt *MetricMatcher) CopyData() *MetricMatcher { + var newLabel []Label + for _, label := range mt.Labels { + newLabel = append(newLabel, label) + } return &MetricMatcher{ - Name: mt.Name, - Header: mt.Header, - Labels: mt.Labels, + Name: strings.Clone(mt.Name), + Header: strings.Clone(mt.Header), + Labels: newLabel, } } diff --git a/pkg/metrics/resource.go b/pkg/metrics/resource.go index 8ad0982..2c112b8 100644 --- a/pkg/metrics/resource.go +++ b/pkg/metrics/resource.go @@ -4,9 +4,6 @@ import ( "encoding/json" "fmt" "io" - "os" - - log "github.com/sirupsen/logrus" ) type Resource struct { @@ -45,20 +42,9 @@ func (r *Resource) JSON() string { } func (rl *ResourceList) Print(writer ...io.Writer) { - var W io.Writer - if len(writer) == 0 { - W = os.Stdout - } else { - w := io.MultiWriter(writer...) - W = io.MultiWriter(os.Stdout, w) - } + var w io.Writer = io.MultiWriter(writer...) for _, r := range *rl { - data, err := json.Marshal(r.JSON()) - if err != nil { - log.Error(err) - return - } - _, _ = fmt.Fprintf(W, "%v\n", string(data)) + _, _ = fmt.Fprintf(w, "%v\n", r.JSON()) } }