fix(outputs.graphite): Add custom regex to outputs (#12908)
This commit is contained in:
parent
02eea01397
commit
3c8277d502
|
|
@ -25,6 +25,7 @@ type Graphite struct {
|
||||||
GraphiteTagSupport bool `toml:"graphite_tag_support"`
|
GraphiteTagSupport bool `toml:"graphite_tag_support"`
|
||||||
GraphiteTagSanitizeMode string `toml:"graphite_tag_sanitize_mode"`
|
GraphiteTagSanitizeMode string `toml:"graphite_tag_sanitize_mode"`
|
||||||
GraphiteSeparator string `toml:"graphite_separator"`
|
GraphiteSeparator string `toml:"graphite_separator"`
|
||||||
|
GraphiteStrictRegex string `toml:"graphite_strict_sanitize_regex"`
|
||||||
// URL is only for backwards compatibility
|
// URL is only for backwards compatibility
|
||||||
Servers []string `toml:"servers"`
|
Servers []string `toml:"servers"`
|
||||||
Prefix string `toml:"prefix"`
|
Prefix string `toml:"prefix"`
|
||||||
|
|
@ -165,7 +166,15 @@ func (g *Graphite) checkEOF(conn net.Conn) error {
|
||||||
func (g *Graphite) Write(metrics []telegraf.Metric) error {
|
func (g *Graphite) Write(metrics []telegraf.Metric) error {
|
||||||
// Prepare data
|
// Prepare data
|
||||||
var batch []byte
|
var batch []byte
|
||||||
s, err := serializers.NewGraphiteSerializer(g.Prefix, g.Template, "", g.GraphiteTagSupport, g.GraphiteTagSanitizeMode, g.GraphiteSeparator, g.Templates)
|
s, err := serializers.NewGraphiteSerializer(
|
||||||
|
g.Prefix,
|
||||||
|
g.Template,
|
||||||
|
g.GraphiteStrictRegex,
|
||||||
|
g.GraphiteTagSupport,
|
||||||
|
g.GraphiteTagSanitizeMode,
|
||||||
|
g.GraphiteSeparator,
|
||||||
|
g.Templates,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,45 @@ func TestGraphiteOK(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGraphiteStrictRegex(t *testing.T) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(1)
|
||||||
|
t.Log("Starting server")
|
||||||
|
tcpServer, err := net.Listen("tcp", "127.0.0.1:12042")
|
||||||
|
require.NoError(t, err)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
conn, _ := (tcpServer).Accept()
|
||||||
|
reader := bufio.NewReader(conn)
|
||||||
|
tp := textproto.NewReader(reader)
|
||||||
|
data1, _ := tp.ReadLine()
|
||||||
|
require.Equal(t, "192_168_0_1.|us-west-2|.mymeasurement.myfield 0.123 1289430000", data1)
|
||||||
|
require.NoError(t, conn.Close())
|
||||||
|
require.NoError(t, tcpServer.Close())
|
||||||
|
}()
|
||||||
|
|
||||||
|
m := metric.New(
|
||||||
|
"mymeasurement",
|
||||||
|
map[string]string{
|
||||||
|
"host": "192.168.0.1",
|
||||||
|
"datacenter": "|us-west-2|",
|
||||||
|
},
|
||||||
|
map[string]interface{}{"myfield": float64(0.123)},
|
||||||
|
time.Date(2010, time.November, 10, 23, 0, 0, 0, time.UTC),
|
||||||
|
)
|
||||||
|
|
||||||
|
g := Graphite{
|
||||||
|
Servers: []string{"localhost:12042"},
|
||||||
|
Log: testutil.Logger{},
|
||||||
|
GraphiteStrictRegex: `[^a-zA-Z0-9-:._=|\p{L}]`,
|
||||||
|
}
|
||||||
|
require.NoError(t, g.Connect())
|
||||||
|
require.NoError(t, g.Write([]telegraf.Metric{m}))
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
require.NoError(t, g.Close())
|
||||||
|
}
|
||||||
|
|
||||||
func TestGraphiteOkWithSeparatorDot(t *testing.T) {
|
func TestGraphiteOkWithSeparatorDot(t *testing.T) {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
// Start TCP server
|
// Start TCP server
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue