Remove debug fields from spunkmetric serializer (#7455)

This commit is contained in:
Daniel Nelson 2020-05-04 16:21:32 -07:00 committed by GitHub
parent 145bad6194
commit 973aec42b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 21 deletions

View File

@ -38,8 +38,6 @@ you can send all of your CPU stats in one JSON struct, an example event looks li
"event": "metric", "event": "metric",
"host": "mono.local", "host": "mono.local",
"fields": { "fields": {
"_config_hecRouting": false,
"_config_multiMetric": true,
"class": "osx", "class": "osx",
"cpu": "cpu0", "cpu": "cpu0",
"metric_name:telegraf.cpu.usage_guest": 0, "metric_name:telegraf.cpu.usage_guest": 0,

View File

@ -179,12 +179,7 @@ func (s *serializer) createObject(metric telegraf.Metric) (metricGroup []byte, e
// The tags are common to all events in this timeseries // The tags are common to all events in this timeseries
commonTags := CommonTags{} commonTags := CommonTags{}
commonObj := map[string]interface{}{} commonTags.Fields = map[string]interface{}{}
commonObj["config:hecRouting"] = s.HecRouting
commonObj["config:multiMetric"] = s.SplunkmetricMultiMetric
commonTags.Fields = commonObj
// Break tags out into key(n)=value(t) pairs // Break tags out into key(n)=value(t) pairs
for n, t := range metric.Tags() { for n, t := range metric.Tags() {

View File

@ -4,10 +4,9 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/influxdata/telegraf" "github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/metric" "github.com/influxdata/telegraf/metric"
"github.com/stretchr/testify/assert"
) )
func MustMetric(v telegraf.Metric, err error) telegraf.Metric { func MustMetric(v telegraf.Metric, err error) telegraf.Metric {
@ -33,7 +32,7 @@ func TestSerializeMetricFloat(t *testing.T) {
var buf []byte var buf []byte
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"_value":91.5,"config:hecRouting":false,"config:multiMetric":false,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":1529875740.819}` expS := `{"_value":91.5,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":1529875740.819}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -53,7 +52,7 @@ func TestSerializeMetricFloatHec(t *testing.T) {
var buf []byte var buf []byte
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"time":1529875740.819,"event":"metric","fields":{"_value":91.5,"config:hecRouting":true,"config:multiMetric":false,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}` expS := `{"time":1529875740.819,"event":"metric","fields":{"_value":91.5,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -73,7 +72,7 @@ func TestSerializeMetricInt(t *testing.T) {
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"_value":90,"config:hecRouting":false,"config:multiMetric":false,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":0}` expS := `{"_value":90,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":0}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -93,7 +92,7 @@ func TestSerializeMetricIntHec(t *testing.T) {
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"time":0,"event":"metric","fields":{"_value":90,"config:hecRouting":true,"config:multiMetric":false,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}` expS := `{"time":0,"event":"metric","fields":{"_value":90,"cpu":"cpu0","metric_name":"cpu.usage_idle"}}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -113,7 +112,7 @@ func TestSerializeMetricBool(t *testing.T) {
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"_value":1,"config:hecRouting":false,"config:multiMetric":false,"container-name":"telegraf-test","metric_name":"docker.oomkiller","time":0}` expS := `{"_value":1,"container-name":"telegraf-test","metric_name":"docker.oomkiller","time":0}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -133,7 +132,7 @@ func TestSerializeMetricBoolHec(t *testing.T) {
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"time":0,"event":"metric","fields":{"_value":0,"config:hecRouting":true,"config:multiMetric":false,"container-name":"telegraf-test","metric_name":"docker.oomkiller"}}` expS := `{"time":0,"event":"metric","fields":{"_value":0,"container-name":"telegraf-test","metric_name":"docker.oomkiller"}}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -154,7 +153,7 @@ func TestSerializeMetricString(t *testing.T) {
buf, err = s.Serialize(m) buf, err = s.Serialize(m)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"_value":5,"config:hecRouting":false,"config:multiMetric":false,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":0}` expS := `{"_value":5,"cpu":"cpu0","metric_name":"cpu.usage_idle","time":0}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -186,7 +185,7 @@ func TestSerializeBatch(t *testing.T) {
buf, err := s.SerializeBatch(metrics) buf, err := s.SerializeBatch(metrics)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"_value":42,"config:hecRouting":false,"config:multiMetric":false,"metric_name":"cpu.value","time":0}{"_value":92,"config:hecRouting":false,"config:multiMetric":false,"metric_name":"cpu.value","time":0}` expS := `{"_value":42,"metric_name":"cpu.value","time":0}{"_value":92,"metric_name":"cpu.value","time":0}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -208,7 +207,7 @@ func TestSerializeMulti(t *testing.T) {
buf, err := s.SerializeBatch(metrics) buf, err := s.SerializeBatch(metrics)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"config:hecRouting":false,"config:multiMetric":true,"metric_name:cpu.system":8,"metric_name:cpu.user":42,"time":0}` expS := `{"metric_name:cpu.system":8,"metric_name:cpu.user":42,"time":0}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -239,7 +238,7 @@ func TestSerializeBatchHec(t *testing.T) {
buf, err := s.SerializeBatch(metrics) buf, err := s.SerializeBatch(metrics)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"time":0,"event":"metric","fields":{"_value":42,"config:hecRouting":true,"config:multiMetric":false,"metric_name":"cpu.value"}}{"time":0,"event":"metric","fields":{"_value":92,"config:hecRouting":true,"config:multiMetric":false,"metric_name":"cpu.value"}}` expS := `{"time":0,"event":"metric","fields":{"_value":42,"metric_name":"cpu.value"}}{"time":0,"event":"metric","fields":{"_value":92,"metric_name":"cpu.value"}}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }
@ -261,6 +260,6 @@ func TestSerializeMultiHec(t *testing.T) {
buf, err := s.SerializeBatch(metrics) buf, err := s.SerializeBatch(metrics)
assert.NoError(t, err) assert.NoError(t, err)
expS := `{"time":0,"event":"metric","fields":{"config:hecRouting":true,"config:multiMetric":true,"metric_name:cpu.system":8,"metric_name:cpu.usage":42}}` expS := `{"time":0,"event":"metric","fields":{"metric_name:cpu.system":8,"metric_name:cpu.usage":42}}`
assert.Equal(t, string(expS), string(buf)) assert.Equal(t, string(expS), string(buf))
} }