How do you test a modified input plugin (lustre2) in go?

Greetings,

I’ve never modified telegraf source or tested plugins before, tried to google and stumble my way through it but I seem to be missing some arg or step.

I added some data points to telegraf/plugins/input/lustre2. Modified both lustre2.go and lustre2_test.go. lustre2_test.go creates a test tree and test files for lustre2.go to parse and create output. I cannot seem to make it create any output, I just get OK at the various steps and no data string of what the module would output using the test tree and test files.

go test -v plugins/inputs/lustre2/lustre2.go plugins/inputs/lustre2/lustre2_test.go
=== RUN TestLustre2GeneratesMetrics
— PASS: TestLustre2GeneratesMetrics (0.00s)
=== RUN TestLustre2GeneratesClientMetrics
— PASS: TestLustre2GeneratesClientMetrics (0.00s)
=== RUN TestLustre2GeneratesJobstatsMetrics
— PASS: TestLustre2GeneratesJobstatsMetrics (0.00s)
=== RUN TestLustre2CanParseConfiguration
— PASS: TestLustre2CanParseConfiguration (0.00s)
PASS
ok command-line-arguments (cached)

I was assuming I’d get the output string where I could make sure I was sourcing the correct fields in my modification.

lustre2,host=oss2,jobid=42990218,name=wrk-OST0041 jobstats_ost_setattr=0i,jobstats_ost_sync=0i,jobstats_punch=0i,jobstats_read_bytes=4096i,jobstats_read_calls=1i,jobstats_read_max_size=4096i,jobstats_read_min_size=4096i,jobstats_write_bytes=310206488i,jobstats_write_calls=7423i,jobstats_write_max_size=53048i,jobstats_write_min_size=8820i 1556525847000000000

Can someone give me some pointers or insight to what I am doing wrong or how to properly test the modifications I made (sourcing other files, new fields, etc).

Many thanks!

Hi,

I added some data points to telegraf/plugins/input/lustre2. Modified both lustre2.go and lustre2_test.go. lustre2_test.go creates a test tree and test files for lustre2.go to parse and create output

If you look through the plugins you will find some plugins have a testcases directory (e.g. zfs, gnmi, upsd) with specific expected input, a config, and expected output in line protocol format. This is our preferred way of creating new tests.

An alternative is a testdata directory (e.g. cgroup, ecs, kernel, nvidia_smi) that has various files to read in and parse.

I cannot seem to make it create any output, I just get OK at the various steps and no data string of what the module would output using the test tree and test files.

When Go tests pass no output will be provided. What I typically do when developing a test, if I want to see some output is to force a failure, then any print statements, logs, or other data to stdout is returned:

require.True(t, false)

I was assuming I’d get the output string where I could make sure I was sourcing the correct fields in my modification.

Once you run gather you can see what metrics you collected via the testutil.PrintMetrics helper function like this:

testutil.PrintMetrics(acc.GetTelegrafMetrics())

Which will print the metrics to stdout in line protocol.

Hope that helps and answers your question!