forked from mirror/client_golang
When prefix is empty, no more dots should be written (#1005)
Signed-off-by: zhijian <djx@juicedata.io>
This commit is contained in:
parent
5d78aaad41
commit
36b47eb0ab
|
@ -197,14 +197,16 @@ func writeMetrics(w io.Writer, mfs []*dto.MetricFamily, useTags bool, prefix str
|
||||||
|
|
||||||
buf := bufio.NewWriter(w)
|
buf := bufio.NewWriter(w)
|
||||||
for _, s := range vec {
|
for _, s := range vec {
|
||||||
for _, c := range prefix {
|
if prefix != "" {
|
||||||
if _, err := buf.WriteRune(c); err != nil {
|
for _, c := range prefix {
|
||||||
|
if _, err := buf.WriteRune(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := buf.WriteByte('.'); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := buf.WriteByte('.'); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := writeMetric(buf, s.Metric, useTags); err != nil {
|
if err := writeMetric(buf, s.Metric, useTags); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,7 @@ func testWriteSummary(t *testing.T, useTags bool) {
|
||||||
{prefix: "prefix"},
|
{prefix: "prefix"},
|
||||||
{prefix: "pre/fix"},
|
{prefix: "pre/fix"},
|
||||||
{prefix: "pre.fix"},
|
{prefix: "pre.fix"},
|
||||||
|
{prefix: ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -141,10 +142,15 @@ func testWriteSummary(t *testing.T, useTags bool) {
|
||||||
t.Fatalf("error: %v", err)
|
t.Fatalf("error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
wantWithPrefix := fmt.Sprintf(want,
|
var wantWithPrefix string
|
||||||
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
if tc.prefix == "" {
|
||||||
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
wantWithPrefix = strings.ReplaceAll(want, "%s.", "")
|
||||||
)
|
} else {
|
||||||
|
wantWithPrefix = fmt.Sprintf(want,
|
||||||
|
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
||||||
|
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
got := buf.String()
|
got := buf.String()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue