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,6 +197,7 @@ 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 {
|
||||||
|
if prefix != "" {
|
||||||
for _, c := range prefix {
|
for _, c := range prefix {
|
||||||
if _, err := buf.WriteRune(c); err != nil {
|
if _, err := buf.WriteRune(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -205,6 +206,7 @@ func writeMetrics(w io.Writer, mfs []*dto.MetricFamily, useTags bool, prefix str
|
||||||
if err := buf.WriteByte('.'); err != nil {
|
if err := buf.WriteByte('.'); err != nil {
|
||||||
return err
|
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
|
||||||
|
if 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,
|
||||||
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