Remove Add() function from accumulator
This commit is contained in:
parent
03d8abccdd
commit
6dbbe65897
|
@ -6,11 +6,6 @@ type Accumulator interface {
|
|||
// Create a point with a value, decorating it with tags
|
||||
// NOTE: tags is expected to be owned by the caller, don't mutate
|
||||
// it after passing to Add.
|
||||
Add(measurement string,
|
||||
value interface{},
|
||||
tags map[string]string,
|
||||
t ...time.Time)
|
||||
|
||||
AddFields(measurement string,
|
||||
fields map[string]interface{},
|
||||
tags map[string]string,
|
||||
|
|
|
@ -38,22 +38,6 @@ type accumulator struct {
|
|||
errCount uint64
|
||||
}
|
||||
|
||||
func (ac *accumulator) Add(
|
||||
measurement string,
|
||||
value interface{},
|
||||
tags map[string]string,
|
||||
t ...time.Time,
|
||||
) {
|
||||
fields := make(map[string]interface{})
|
||||
fields["value"] = value
|
||||
|
||||
if !ac.inputConfig.Filter.ShouldNamePass(measurement) {
|
||||
return
|
||||
}
|
||||
|
||||
ac.AddFields(measurement, fields, tags, t...)
|
||||
}
|
||||
|
||||
func (ac *accumulator) AddFields(
|
||||
measurement string,
|
||||
fields map[string]interface{},
|
||||
|
|
|
@ -23,9 +23,15 @@ func TestAdd(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -50,9 +56,15 @@ func TestAddNoPrecisionWithInterval(t *testing.T) {
|
|||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.SetPrecision(0, time.Second)
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -77,9 +89,15 @@ func TestAddNoIntervalWithPrecision(t *testing.T) {
|
|||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.SetPrecision(time.Second, time.Millisecond)
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -105,9 +123,15 @@ func TestAddDisablePrecision(t *testing.T) {
|
|||
|
||||
a.SetPrecision(time.Second, time.Millisecond)
|
||||
a.DisablePrecision()
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -132,7 +156,9 @@ func TestDifferentPrecisions(t *testing.T) {
|
|||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.SetPrecision(0, time.Second)
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
assert.Equal(t,
|
||||
|
@ -140,7 +166,9 @@ func TestDifferentPrecisions(t *testing.T) {
|
|||
actual)
|
||||
|
||||
a.SetPrecision(0, time.Millisecond)
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
testm = <-a.metrics
|
||||
actual = testm.String()
|
||||
assert.Equal(t,
|
||||
|
@ -148,7 +176,9 @@ func TestDifferentPrecisions(t *testing.T) {
|
|||
actual)
|
||||
|
||||
a.SetPrecision(0, time.Microsecond)
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
testm = <-a.metrics
|
||||
actual = testm.String()
|
||||
assert.Equal(t,
|
||||
|
@ -156,7 +186,9 @@ func TestDifferentPrecisions(t *testing.T) {
|
|||
actual)
|
||||
|
||||
a.SetPrecision(0, time.Nanosecond)
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
testm = <-a.metrics
|
||||
actual = testm.String()
|
||||
assert.Equal(t,
|
||||
|
@ -172,9 +204,15 @@ func TestAddDefaultTags(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -342,9 +380,15 @@ func TestAddInts(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", int(101), map[string]string{})
|
||||
a.Add("acctest", int32(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", int64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": int(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": int32(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": int64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -369,8 +413,12 @@ func TestAddFloats(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", float32(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float32(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -391,8 +439,12 @@ func TestAddStrings(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", "test", map[string]string{"acc": "test"})
|
||||
a.Add("acctest", "foo", map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": "test"},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": "foo"},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -413,8 +465,10 @@ func TestAddBools(t *testing.T) {
|
|||
defer close(a.metrics)
|
||||
a.inputConfig = &models.InputConfig{}
|
||||
|
||||
a.Add("acctest", true, map[string]string{"acc": "test"})
|
||||
a.Add("acctest", false, map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": true}, map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": false}, map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
@ -440,9 +494,15 @@ func TestAccFilterTags(t *testing.T) {
|
|||
a.inputConfig = &models.InputConfig{}
|
||||
a.inputConfig.Filter = filter
|
||||
|
||||
a.Add("acctest", float64(101), map[string]string{})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"})
|
||||
a.Add("acctest", float64(101), map[string]string{"acc": "test"}, now)
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"})
|
||||
a.AddFields("acctest",
|
||||
map[string]interface{}{"value": float64(101)},
|
||||
map[string]string{"acc": "test"}, now)
|
||||
|
||||
testm := <-a.metrics
|
||||
actual := testm.String()
|
||||
|
|
|
@ -1478,19 +1478,23 @@ func (m *Mysql) gatherTableSchema(db *sql.DB, serv string, acc telegraf.Accumula
|
|||
tags["schema"] = tableSchema
|
||||
tags["table"] = tableName
|
||||
|
||||
acc.Add(newNamespace("info_schema", "table_rows"), tableRows, tags)
|
||||
acc.AddFields(newNamespace("info_schema", "table_rows"),
|
||||
map[string]interface{}{"value": tableRows}, tags)
|
||||
|
||||
dlTags := copyTags(tags)
|
||||
dlTags["component"] = "data_length"
|
||||
acc.Add(newNamespace("info_schema", "table_size", "data_length"), dataLength, dlTags)
|
||||
acc.AddFields(newNamespace("info_schema", "table_size", "data_length"),
|
||||
map[string]interface{}{"value": dataLength}, dlTags)
|
||||
|
||||
ilTags := copyTags(tags)
|
||||
ilTags["component"] = "index_length"
|
||||
acc.Add(newNamespace("info_schema", "table_size", "index_length"), indexLength, ilTags)
|
||||
acc.AddFields(newNamespace("info_schema", "table_size", "index_length"),
|
||||
map[string]interface{}{"value": indexLength}, ilTags)
|
||||
|
||||
dfTags := copyTags(tags)
|
||||
dfTags["component"] = "data_free"
|
||||
acc.Add(newNamespace("info_schema", "table_size", "data_free"), dataFree, dfTags)
|
||||
acc.AddFields(newNamespace("info_schema", "table_size", "data_free"),
|
||||
map[string]interface{}{"value": dataFree}, dfTags)
|
||||
|
||||
versionTags := copyTags(tags)
|
||||
versionTags["type"] = tableType
|
||||
|
@ -1498,7 +1502,8 @@ func (m *Mysql) gatherTableSchema(db *sql.DB, serv string, acc telegraf.Accumula
|
|||
versionTags["row_format"] = rowFormat
|
||||
versionTags["create_options"] = createOptions
|
||||
|
||||
acc.Add(newNamespace("info_schema", "table_version"), version, versionTags)
|
||||
acc.AddFields(newNamespace("info_schema", "table_version"),
|
||||
map[string]interface{}{"value": version}, versionTags)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -166,7 +166,9 @@ func (s *SQLServer) accRow(query Query, acc telegraf.Accumulator, row scanner) e
|
|||
|
||||
if query.ResultByRow {
|
||||
// add measurement to Accumulator
|
||||
acc.Add(measurement, *columnMap["value"], tags, time.Now())
|
||||
acc.AddFields(measurement,
|
||||
map[string]interface{}{"value": *columnMap["value"]},
|
||||
tags, time.Now())
|
||||
} else {
|
||||
// values
|
||||
for header, val := range columnMap {
|
||||
|
|
|
@ -53,7 +53,9 @@ func TestSqlServer_ParseMetrics(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
|
||||
// add value to Accumulator
|
||||
acc.Add(measurement, value, tags, time.Now())
|
||||
acc.AddFields(measurement,
|
||||
map[string]interface{}{"value": value},
|
||||
tags, time.Now())
|
||||
// assert
|
||||
acc.AssertContainsTaggedFields(t, measurement, map[string]interface{}{"value": value}, tags)
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ type PS interface {
|
|||
func add(acc telegraf.Accumulator,
|
||||
name string, val float64, tags map[string]string) {
|
||||
if val >= 0 {
|
||||
acc.Add(name, val, tags)
|
||||
acc.AddFields(name, map[string]interface{}{"value": val}, tags)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,17 +35,6 @@ type Accumulator struct {
|
|||
debug bool
|
||||
}
|
||||
|
||||
// Add adds a measurement point to the accumulator
|
||||
func (a *Accumulator) Add(
|
||||
measurement string,
|
||||
value interface{},
|
||||
tags map[string]string,
|
||||
t ...time.Time,
|
||||
) {
|
||||
fields := map[string]interface{}{"value": value}
|
||||
a.AddFields(measurement, fields, tags, t...)
|
||||
}
|
||||
|
||||
func (a *Accumulator) NMetrics() uint64 {
|
||||
return atomic.LoadUint64(&a.nMetrics)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue