diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c08c50b5b..e8c38456e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -39,7 +39,7 @@ type Plugin interface { type Accumulator interface { Add(measurement string, value interface{}, tags map[string]string) - AddValuesWithTime(measurement string, + AddFieldsWithTime(measurement string, values map[string]interface{}, tags map[string]string, timestamp time.Time) @@ -63,7 +63,7 @@ The `Add` function takes 3 arguments: about the metric. For instance, the `net` plugin adds a tag named `"interface"` set to the name of the network interface, like `"eth0"`. -The `AddValuesWithTime` allows multiple values for a point to be passed. The values +The `AddFieldsWithTime` allows multiple values for a point to be passed. The values used are the same type profile as **value** above. The **timestamp** argument allows a point to be registered as having occurred at an arbitrary time. diff --git a/accumulator.go b/accumulator.go index ea90b6620..6c1962ac4 100644 --- a/accumulator.go +++ b/accumulator.go @@ -62,12 +62,60 @@ func (bp *BatchPoints) Add( }) } -// AddValuesWithTime adds a measurement with a provided timestamp -func (bp *BatchPoints) AddValuesWithTime( +// AddFieldsWithTime adds a measurement with a provided timestamp +func (bp *BatchPoints) AddFieldsWithTime( measurement string, - values map[string]interface{}, + fields map[string]interface{}, tags map[string]string, timestamp time.Time, +) { + // TODO this function should add the fields with the timestamp, but that will + // need to wait for the InfluxDB point precision/unit to be fixed + bp.AddFields(measurement, fields, tags) + // bp.mu.Lock() + // defer bp.mu.Unlock() + + // measurement = bp.Prefix + measurement + + // if bp.Config != nil { + // if !bp.Config.ShouldPass(measurement, tags) { + // return + // } + // } + + // if bp.Debug { + // var tg []string + + // for k, v := range tags { + // tg = append(tg, fmt.Sprintf("%s=\"%s\"", k, v)) + // } + + // var vals []string + + // for k, v := range fields { + // vals = append(vals, fmt.Sprintf("%s=%v", k, v)) + // } + + // sort.Strings(tg) + // sort.Strings(vals) + + // fmt.Printf("> [%s] %s %s\n", strings.Join(tg, " "), measurement, strings.Join(vals, " ")) + // } + + // bp.Points = append(bp.Points, client.Point{ + // Measurement: measurement, + // Tags: tags, + // Fields: fields, + // Time: timestamp, + // }) +} + +// AddFields will eventually replace the Add function, once we move to having a +// single plugin as a single measurement with multiple fields +func (bp *BatchPoints) AddFields( + measurement string, + fields map[string]interface{}, + tags map[string]string, ) { bp.mu.Lock() defer bp.mu.Unlock() @@ -89,7 +137,7 @@ func (bp *BatchPoints) AddValuesWithTime( var vals []string - for k, v := range values { + for k, v := range fields { vals = append(vals, fmt.Sprintf("%s=%v", k, v)) } @@ -102,7 +150,6 @@ func (bp *BatchPoints) AddValuesWithTime( bp.Points = append(bp.Points, client.Point{ Measurement: measurement, Tags: tags, - Fields: values, - Time: timestamp, + Fields: fields, }) } diff --git a/plugins/kafka_consumer/kafka_consumer.go b/plugins/kafka_consumer/kafka_consumer.go index 53fc8d110..538dcc7eb 100644 --- a/plugins/kafka_consumer/kafka_consumer.go +++ b/plugins/kafka_consumer/kafka_consumer.go @@ -93,7 +93,7 @@ func emitMetrics(k *Kafka, acc plugins.Accumulator, metricConsumer <-chan []byte } for _, point := range points { - acc.AddValuesWithTime(point.Name(), point.Fields(), point.Tags(), point.Time()) + acc.AddFieldsWithTime(point.Name(), point.Fields(), point.Tags(), point.Time()) } case <-timeout: return nil diff --git a/plugins/mongodb/mongodb_data.go b/plugins/mongodb/mongodb_data.go index ba6cc8d95..bb9b7b2a4 100644 --- a/plugins/mongodb/mongodb_data.go +++ b/plugins/mongodb/mongodb_data.go @@ -89,7 +89,7 @@ func (d *MongodbData) addStat(acc plugins.Accumulator, statLine reflect.Value, s } func (d *MongodbData) add(acc plugins.Accumulator, key string, val interface{}) { - acc.AddValuesWithTime( + acc.AddFieldsWithTime( key, map[string]interface{}{ "value": val, diff --git a/plugins/registry.go b/plugins/registry.go index 2b6c9e4cd..b6c9b7989 100644 --- a/plugins/registry.go +++ b/plugins/registry.go @@ -10,8 +10,8 @@ type Accumulator interface { // Create a point with a set of values, decorating it with tags // NOTE: tags and values are expected to be owned by the caller, don't mutate - // them after passing to AddValuesWithTime. - AddValuesWithTime( + // them after passing to AddFieldsWithTime. + AddFieldsWithTime( measurement string, values map[string]interface{}, tags map[string]string, diff --git a/testutil/accumulator.go b/testutil/accumulator.go index 3d9d40827..10d35a77e 100644 --- a/testutil/accumulator.go +++ b/testutil/accumulator.go @@ -34,8 +34,8 @@ func (a *Accumulator) Add(measurement string, value interface{}, tags map[string ) } -// AddValuesWithTime adds a measurement point with a specified timestamp. -func (a *Accumulator) AddValuesWithTime( +// AddFieldsWithTime adds a measurement point with a specified timestamp. +func (a *Accumulator) AddFieldsWithTime( measurement string, values map[string]interface{}, tags map[string]string,