forked from influxdata/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating branch with upstream version 1.31.3
- Loading branch information
Showing
6 changed files
with
1,265 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,38 @@ | ||
package all | ||
|
||
import ( | ||
_ "github.com/influxdata/telegraf/plugins/outputs/amon" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/amqp" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/application_insights" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/azure_monitor" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/cloud_pubsub" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/cloudwatch" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/cratedb" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/datadog" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/discard" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/elasticsearch" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/exec" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/file" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/graphite" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/graylog" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/health" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/http" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/influxdb" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/influxdb_v2" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/instrumental" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/kafka" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/kinesis" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/librato" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/mqtt" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/nats" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/nsq" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/opentsdb" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/prometheus_client" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/riemann" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/signalfx" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/socket_writer" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/stackdriver" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/syslog" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/warp10" | ||
_ "github.com/influxdata/telegraf/plugins/outputs/wavefront" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package parse | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// RemoveSFXDimensions removes dimensions used only to identify special metrics for SignalFx | ||
func RemoveSFXDimensions(metricDims map[string]string) { | ||
// remove the sf_metric dimension | ||
delete(metricDims, "sf_metric") | ||
} | ||
|
||
// SetPluginDimension sets the plugin dimension to the metric name if it is not already supplied | ||
func SetPluginDimension(metricName string, metricDims map[string]string) { | ||
// If the plugin doesn't define a plugin name use metric.Name() | ||
if _, in := metricDims["plugin"]; !in { | ||
metricDims["plugin"] = metricName | ||
} | ||
} | ||
|
||
// GetMetricName combines telegraf fields and tags into a full metric name | ||
func GetMetricName(metric string, field string, dims map[string]string) (string, bool) { | ||
// If sf_metric is provided | ||
if sfmetric, isSFX := dims["sf_metric"]; isSFX { | ||
return sfmetric, isSFX | ||
} | ||
|
||
// If it isn't a sf_metric then use metric name | ||
name := metric | ||
|
||
// Include field in metric name when it adds to the metric name | ||
if field != "value" { | ||
name = fmt.Sprintf("%s.%s", name, field) | ||
} | ||
|
||
return name, false | ||
} | ||
|
||
// ExtractProperty of the metric according to the following rules | ||
func ExtractProperty(name string, dims map[string]string) (map[string]interface{}, error) { | ||
props := make(map[string]interface{}, 1) | ||
// if the metric is a metadata object | ||
if name == "objects.host-meta-data" { | ||
// If property exists remap it | ||
if _, in := dims["property"]; !in { | ||
return props, fmt.Errorf("E! objects.host-metadata object doesn't have a property") | ||
} | ||
props["property"] = dims["property"] | ||
delete(dims, "property") | ||
} | ||
return props, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
package parse | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestRemoveSFXDimensions(t *testing.T) { | ||
type args struct { | ||
metricDims map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "remove sf_metric from sfx dimensions", | ||
args: args{ | ||
metricDims: map[string]string{ | ||
"sf_metric": "", | ||
"dimensionKey": "dimensionVal", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
RemoveSFXDimensions(tt.args.metricDims) | ||
if _, isIn := tt.args.metricDims["sf_metric"]; isIn { | ||
t.Errorf("RemoveSFXDimensions() got metricDims %v, but 'sf_metric' shouldn't be in it", tt.args.metricDims) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestSetPluginDimension(t *testing.T) { | ||
type args struct { | ||
metricName string | ||
metricDims map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
}{ | ||
{ | ||
name: "", | ||
args: args{ | ||
metricName: "metricName", | ||
metricDims: map[string]string{ | ||
"dimensionKey": "dimensionVal", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if original, in := tt.args.metricDims["plugin"]; !in { | ||
SetPluginDimension(tt.args.metricName, tt.args.metricDims) | ||
if val, in := tt.args.metricDims["plugin"]; !in || val != tt.args.metricName { | ||
t.Errorf("SetPluginDimension() got %v but wanted plugin dimension with value %s", tt.args.metricDims, tt.args.metricName) | ||
} | ||
} else { | ||
SetPluginDimension(tt.args.metricName, tt.args.metricDims) | ||
if val, in := tt.args.metricDims["plugin"]; !in || val != original { | ||
t.Errorf("SetPluginDImension() got %v but wanted plugin dimension with value %s", tt.args.metricDims, original) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestGetMetricName(t *testing.T) { | ||
type args struct { | ||
metric string | ||
field string | ||
dims map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
wantsfx bool | ||
}{ | ||
{ | ||
name: "use sf_metric tag as metric name", | ||
args: args{ | ||
metric: "datapoint", | ||
field: "test", | ||
dims: map[string]string{ | ||
"sf_metric": "sfxtestmetricname", | ||
}, | ||
}, | ||
want: "sfxtestmetricname", | ||
wantsfx: true, | ||
}, | ||
{ | ||
name: "fields that equal value should not be append to metricname", | ||
args: args{ | ||
metric: "datapoint", | ||
field: "value", | ||
dims: map[string]string{ | ||
"testDimKey": "testDimVal", | ||
}, | ||
}, | ||
want: "datapoint", | ||
wantsfx: false, | ||
}, | ||
{ | ||
name: "fields other than 'value' with out sf_metric dim should return measurement.fieldname as metric name", | ||
args: args{ | ||
metric: "datapoint", | ||
field: "test", | ||
dims: map[string]string{ | ||
"testDimKey": "testDimVal", | ||
}, | ||
}, | ||
want: "datapoint.test", | ||
wantsfx: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, got1 := GetMetricName(tt.args.metric, tt.args.field, tt.args.dims) | ||
if got != tt.want { | ||
t.Errorf("GetMetricName() got = %v, want %v", got, tt.want) | ||
} | ||
if got1 != tt.wantsfx { | ||
t.Errorf("GetMetricName() got1 = %v, want %v", got1, tt.wantsfx) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestExtractProperty(t *testing.T) { | ||
type args struct { | ||
name string | ||
dims map[string]string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantProps map[string]interface{} | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "ensure that sfx host metadata events remap dimension with key 'property' to properties", | ||
args: args{ | ||
name: "objects.host-meta-data", | ||
dims: map[string]string{ | ||
"property": "propertyValue", | ||
"dimensionKey": "dimensionValue", | ||
}, | ||
}, | ||
wantProps: map[string]interface{}{ | ||
"property": "propertyValue", | ||
}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "malformed sfx host metadata event should return an error", | ||
args: args{ | ||
name: "objects.host-meta-data", | ||
dims: map[string]string{ | ||
"dimensionKey": "dimensionValue", | ||
}, | ||
}, | ||
wantProps: map[string]interface{}{}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotProps, err := ExtractProperty(tt.args.name, tt.args.dims) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ExtractProperty() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(gotProps, tt.wantProps) { | ||
t.Errorf("ExtractProperty() = %v, want %v", gotProps, tt.wantProps) | ||
} | ||
if _, ok := tt.args.dims["property"]; ok { | ||
t.Errorf("ExtractProperty() did not remove property from dims %v", tt.args.dims) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.