Skip to content

Commit

Permalink
fix: bug of print error data
Browse files Browse the repository at this point in the history
  • Loading branch information
Esonhugh committed Dec 6, 2024
1 parent 48017dd commit dae0d7c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions cmd/metrics/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 7 additions & 3 deletions pkg/metrics/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
18 changes: 2 additions & 16 deletions pkg/metrics/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"os"

log "github.com/sirupsen/logrus"
)

type Resource struct {
Expand Down Expand Up @@ -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())
}
}

Expand Down

0 comments on commit dae0d7c

Please sign in to comment.