chore(parsers.csv): Add benchmark test (#14257)

This commit is contained in:
Joshua Powers 2023-11-10 09:17:41 -07:00 committed by GitHub
parent 06959a1c78
commit 0d106d5822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 62 additions and 0 deletions

View File

@ -1515,3 +1515,65 @@ func TestParseCSVLinewiseResetModeAlways(t *testing.T) {
`parsing time "garbage nonsense that needs be skipped" as "2006-01-02T15:04:05Z07:00": cannot parse "garbage nonsense that needs be skipped" as "2006"`, `parsing time "garbage nonsense that needs be skipped" as "2006-01-02T15:04:05Z07:00": cannot parse "garbage nonsense that needs be skipped" as "2006"`,
) )
} }
const benchmarkData = `tags_host,tags_platform,tags_sdkver,value,timestamp
myhost,python,3.11.5,5,1653643420
myhost,python,3.11.4,4,1653643420
`
func TestBenchmarkData(t *testing.T) {
plugin := &Parser{
MetricName: "benchmark",
HeaderRowCount: 1,
TimestampColumn: "timestamp",
TimestampFormat: "unix",
TagColumns: []string{"tags_host", "tags_platform", "tags_sdkver"},
}
require.NoError(t, plugin.Init())
expected := []telegraf.Metric{
metric.New(
"benchmark",
map[string]string{
"tags_host": "myhost",
"tags_platform": "python",
"tags_sdkver": "3.11.5",
},
map[string]interface{}{
"value": 5,
},
time.Unix(1653643420, 0),
),
metric.New(
"benchmark",
map[string]string{
"tags_host": "myhost",
"tags_platform": "python",
"tags_sdkver": "3.11.4",
},
map[string]interface{}{
"value": 4,
},
time.Unix(1653643420, 0),
),
}
actual, err := plugin.Parse([]byte(benchmarkData))
require.NoError(t, err)
testutil.RequireMetricsEqual(t, expected, actual)
}
func BenchmarkParsing(b *testing.B) {
plugin := &Parser{
MetricName: "benchmark",
HeaderRowCount: 1,
TimestampColumn: "timestamp",
TimestampFormat: "unix",
TagColumns: []string{"tags_host", "tags_platform", "tags_sdkver"},
}
require.NoError(b, plugin.Init())
for n := 0; n < b.N; n++ {
_, _ = plugin.Parse([]byte(benchmarkData))
}
}