Do not sanitize prefix in Graphite bridge
Refer to #418. Signed-off-by: neeral <neeral@users.noreply.github.com>
This commit is contained in:
parent
faf4ec335f
commit
fe6c0fa342
|
@ -191,8 +191,10 @@ func writeMetrics(w io.Writer, mfs []*dto.MetricFamily, prefix string, now model
|
||||||
|
|
||||||
buf := bufio.NewWriter(w)
|
buf := bufio.NewWriter(w)
|
||||||
for _, s := range vec {
|
for _, s := range vec {
|
||||||
if err := writeSanitized(buf, prefix); err != nil {
|
for _, c := range prefix {
|
||||||
return err
|
if _, err := buf.WriteRune(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err := buf.WriteByte('.'); err != nil {
|
if err := buf.WriteByte('.'); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -273,7 +275,7 @@ func replaceInvalidRune(c rune) rune {
|
||||||
if c == ' ' {
|
if c == ' ' {
|
||||||
return '.'
|
return '.'
|
||||||
}
|
}
|
||||||
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == ':' || (c >= '0' && c <= '9')) {
|
if !((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || c == ':' || c == '-' || (c >= '0' && c <= '9')) {
|
||||||
return '_'
|
return '_'
|
||||||
}
|
}
|
||||||
return c
|
return c
|
||||||
|
|
|
@ -3,6 +3,7 @@ package graphite
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
@ -25,6 +26,7 @@ func TestSanitize(t *testing.T) {
|
||||||
{in: "hE/l1o", out: "hE_l1o"},
|
{in: "hE/l1o", out: "hE_l1o"},
|
||||||
{in: "he,*ll(.o", out: "he_ll_o"},
|
{in: "he,*ll(.o", out: "he_ll_o"},
|
||||||
{in: "hello_there%^&", out: "hello_there_"},
|
{in: "hello_there%^&", out: "hello_there_"},
|
||||||
|
{in: "hell-.o", out: "hell-_o"},
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
@ -72,27 +74,41 @@ func TestWriteSummary(t *testing.T) {
|
||||||
t.Fatalf("error: %v", err)
|
t.Fatalf("error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
now := model.Time(1477043083)
|
testCases := []struct {
|
||||||
var buf bytes.Buffer
|
prefix string
|
||||||
err = writeMetrics(&buf, mfs, "prefix", now)
|
}{
|
||||||
if err != nil {
|
{prefix: "prefix"},
|
||||||
t.Fatalf("error: %v", err)
|
{prefix: "pre/fix"},
|
||||||
|
{prefix: "pre.fix"},
|
||||||
}
|
}
|
||||||
|
|
||||||
want := `prefix.name.constname.constvalue.labelname.val1.quantile.0_5 20 1477043
|
const want = `%s.name.constname.constvalue.labelname.val1.quantile.0_5 20 1477043
|
||||||
prefix.name.constname.constvalue.labelname.val1.quantile.0_9 30 1477043
|
%s.name.constname.constvalue.labelname.val1.quantile.0_9 30 1477043
|
||||||
prefix.name.constname.constvalue.labelname.val1.quantile.0_99 30 1477043
|
%s.name.constname.constvalue.labelname.val1.quantile.0_99 30 1477043
|
||||||
prefix.name_sum.constname.constvalue.labelname.val1 60 1477043
|
%s.name_sum.constname.constvalue.labelname.val1 60 1477043
|
||||||
prefix.name_count.constname.constvalue.labelname.val1 3 1477043
|
%s.name_count.constname.constvalue.labelname.val1 3 1477043
|
||||||
prefix.name.constname.constvalue.labelname.val2.quantile.0_5 30 1477043
|
%s.name.constname.constvalue.labelname.val2.quantile.0_5 30 1477043
|
||||||
prefix.name.constname.constvalue.labelname.val2.quantile.0_9 40 1477043
|
%s.name.constname.constvalue.labelname.val2.quantile.0_9 40 1477043
|
||||||
prefix.name.constname.constvalue.labelname.val2.quantile.0_99 40 1477043
|
%s.name.constname.constvalue.labelname.val2.quantile.0_99 40 1477043
|
||||||
prefix.name_sum.constname.constvalue.labelname.val2 90 1477043
|
%s.name_sum.constname.constvalue.labelname.val2 90 1477043
|
||||||
prefix.name_count.constname.constvalue.labelname.val2 3 1477043
|
%s.name_count.constname.constvalue.labelname.val2 3 1477043
|
||||||
`
|
`
|
||||||
|
for i, tc := range testCases {
|
||||||
|
|
||||||
if got := buf.String(); want != got {
|
now := model.Time(1477043083)
|
||||||
t.Fatalf("wanted \n%s\n, got \n%s\n", want, got)
|
var buf bytes.Buffer
|
||||||
|
err = writeMetrics(&buf, mfs, tc.prefix, now)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
wantWithPrefix := fmt.Sprintf(want,
|
||||||
|
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
||||||
|
tc.prefix, tc.prefix, tc.prefix, tc.prefix, tc.prefix,
|
||||||
|
)
|
||||||
|
if got := buf.String(); wantWithPrefix != got {
|
||||||
|
t.Fatalf("test case index %d: wanted \n%s\n, got \n%s\n", i, wantWithPrefix, got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue