feat(processors.starlark): Add starlark benchmark for tag-concatenation (#11306)

This commit is contained in:
Sven Rebhan 2022-08-04 18:30:03 +02:00 committed by GitHub
parent 60ddb12933
commit 75d766b715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 4 deletions

View File

@ -3183,6 +3183,68 @@ def apply(metric):
), ),
}, },
}, },
{
name: "concatenate 2 tags",
source: `
def apply(metric):
metric.tags["result"] = '_'.join(metric.tags.values())
return metric
`,
input: []telegraf.Metric{
testutil.MustMetric("cpu",
map[string]string{
"tag_1": "a",
"tag_2": "b",
},
map[string]interface{}{"value": 42},
time.Unix(0, 0),
),
},
},
{
name: "concatenate 4 tags",
source: `
def apply(metric):
metric.tags["result"] = '_'.join(metric.tags.values())
return metric
`,
input: []telegraf.Metric{
testutil.MustMetric("cpu",
map[string]string{
"tag_1": "a",
"tag_2": "b",
"tag_3": "c",
"tag_4": "d",
},
map[string]interface{}{"value": 42},
time.Unix(0, 0),
),
},
},
{
name: "concatenate 8 tags",
source: `
def apply(metric):
metric.tags["result"] = '_'.join(metric.tags.values())
return metric
`,
input: []telegraf.Metric{
testutil.MustMetric("cpu",
map[string]string{
"tag_1": "a",
"tag_2": "b",
"tag_3": "c",
"tag_4": "d",
"tag_5": "e",
"tag_6": "f",
"tag_7": "g",
"tag_8": "h",
},
map[string]interface{}{"value": 42},
time.Unix(0, 0),
),
},
},
} }
for _, tt := range tests { for _, tt := range tests {

View File

@ -20,6 +20,10 @@ type metricDiff struct {
Time time.Time Time time.Time
} }
type helper interface {
Helper()
}
func lessFunc(lhs, rhs *metricDiff) bool { func lessFunc(lhs, rhs *metricDiff) bool {
if lhs.Measurement != rhs.Measurement { if lhs.Measurement != rhs.Measurement {
return lhs.Measurement < rhs.Measurement return lhs.Measurement < rhs.Measurement
@ -140,8 +144,10 @@ func MetricEqual(expected, actual telegraf.Metric, opts ...cmp.Option) bool {
// RequireMetricEqual halts the test with an error if the metrics are not // RequireMetricEqual halts the test with an error if the metrics are not
// equal. // equal.
func RequireMetricEqual(t *testing.T, expected, actual telegraf.Metric, opts ...cmp.Option) { func RequireMetricEqual(t testing.TB, expected, actual telegraf.Metric, opts ...cmp.Option) {
t.Helper() if x, ok := t.(helper); ok {
x.Helper()
}
var lhs, rhs *metricDiff var lhs, rhs *metricDiff
if expected != nil { if expected != nil {
@ -159,8 +165,10 @@ func RequireMetricEqual(t *testing.T, expected, actual telegraf.Metric, opts ...
// RequireMetricsEqual halts the test with an error if the array of metrics // RequireMetricsEqual halts the test with an error if the array of metrics
// are not equal. // are not equal.
func RequireMetricsEqual(t *testing.T, expected, actual []telegraf.Metric, opts ...cmp.Option) { func RequireMetricsEqual(t testing.TB, expected, actual []telegraf.Metric, opts ...cmp.Option) {
t.Helper() if x, ok := t.(helper); ok {
x.Helper()
}
lhs := make([]*metricDiff, 0, len(expected)) lhs := make([]*metricDiff, 0, len(expected))
for _, m := range expected { for _, m := range expected {