diff --git a/plugins/parsers/xpath/parser_test.go b/plugins/parsers/xpath/parser_test.go index 4d9d4badc..e2fba76bc 100644 --- a/plugins/parsers/xpath/parser_test.go +++ b/plugins/parsers/xpath/parser_test.go @@ -1781,3 +1781,35 @@ func BenchmarkParsingMsgPack(b *testing.B) { _, _ = plugin.Parse(benchmarkDataMsgPack[n%2]) } } + +func BenchmarkParsingCBOR(b *testing.B) { + plugin := &Parser{ + DefaultMetricName: "benchmark", + Format: "xpath_cbor", + NativeTypes: true, + Configs: []Config{ + { + Selection: "//data", + Timestamp: "timestamp", + TimestampFmt: "unix_ns", + Tags: map[string]string{ + "source": "source", + "tags_sdkver": "tags_sdkver", + "tags_platform": "tags_platform", + }, + Fields: map[string]string{ + "value": "value", + }, + }, + }, + Log: testutil.Logger{Name: "parsers.xpath", Quiet: true}, + } + require.NoError(b, plugin.Init()) + + benchmarkData, err := os.ReadFile(filepath.Join("testcases", "cbor_benchmark", "message.bin")) + require.NoError(b, err) + + for n := 0; n < b.N; n++ { + _, _ = plugin.Parse(benchmarkData) + } +} diff --git a/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out b/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out new file mode 100644 index 000000000..8263f7ceb --- /dev/null +++ b/plugins/parsers/xpath/testcases/cbor_benchmark/expected.out @@ -0,0 +1,2 @@ +benchmark,source=myhost,tags_platform=python,tags_sdkver=3.11.5 value=5.0 1653643421000000000 +benchmark,source=myhost,tags_platform=python,tags_sdkver=3.11.4 value=4.0 1653643421000000000 diff --git a/plugins/parsers/xpath/testcases/cbor_benchmark/message.bin b/plugins/parsers/xpath/testcases/cbor_benchmark/message.bin new file mode 100644 index 000000000..a447911ae Binary files /dev/null and b/plugins/parsers/xpath/testcases/cbor_benchmark/message.bin differ diff --git a/plugins/parsers/xpath/testcases/cbor_benchmark/telegraf.conf b/plugins/parsers/xpath/testcases/cbor_benchmark/telegraf.conf new file mode 100644 index 000000000..4ceaf0eec --- /dev/null +++ b/plugins/parsers/xpath/testcases/cbor_benchmark/telegraf.conf @@ -0,0 +1,20 @@ +[[inputs.file]] + files = ["./testcases/cbor_benchmark/message.bin"] + data_format = "xpath_cbor" + + xpath_native_types = true + + [[inputs.file.xpath]] + metric_name = "'benchmark'" + metric_selection = "//data" + + timestamp = "timestamp" + timestamp_format = "unix_ns" + + [inputs.file.xpath.tags] + source = "source" + tags_sdkver = "tags_sdkver" + tags_platform = "tags_platform" + + [inputs.file.xpath.fields] + value = "value"