Unable to add a new Aggregator Plugin to the telegraf build

Hi,

I posted this as a support issue on telegraf’s github issues page but they redirected me to this Community Blog for support questions.
Link to the issue - Unable to add a new Aggregator Plugin to the telegraf build · Issue #8879 · influxdata/telegraf (github.com)

To give context,

I am working on a customized version of telegraf to be used only for my purposes, For this I created a modified version of basicstats aggregator plugin, following the documentation at their github repo

However I can’t seem to add the absolute or relative path to my plugin file in the plugins/aggregators/all/all.go file. It shows an error saying -

plugins/aggregators/all/all.go:5:2: package plugins/aggregators/mdmratmetrics is not in GOROOT (/usr/local/go/src/plugins/aggregators/mdmratmetrics)

For context, I am creating the new plugin directory at the same directory structure as existing telegraf aggregator plugins.
and if I add it to the all.go in the same format as the existing aggregator plugin paths -

github.com/influxdata/telegraf/plugins/aggregators/mdmratmetrics

Then it ignores that file and doesn’t build it along with the binary. When I run the telegraf binary with my config it says -

2021-02-19T00:44:48Z E! [telegraf] Error running agent: Error parsing telegraf.d/network.conf, Undefined but requested aggregator: mdmratmetrics

Am I missing a step for linking/registering the plugin? I can confirm that I am calling the aggregators.Add in the init function as well. I am simply cloning the telegraf source code from a forked repo and running “make” to build telegraf and not through go get to clone the code, I did do the
go get github.com/influxdata/telegraf
during my debug to see if that helps with the build but that command exited instantly without any error

How do I provide the path to my local .go file containing the code for this custom aggregator plugin to be build within telegraf binary? Any help is appreciated! Thanks.

Did you perhaps miss the underscore _ before the path in your all.go file?

	_ "github.com/influxdata/telegraf/plugins/aggregators/mdmratmetrics"

No I have added it to the file. This is what my all.go looks like -
This is the whole all.go file. I am wondering if its possible to add local paths for the build file? Pretty sure adding the file under the github . com/influxdata/telegraf/ prefix is wrong (but it only builds if I add the path as that!

Hi there, if you’re still having this issue, adding the reference to the all.go file (which you have done correctly) should be enough. in your ‘mdmratmetrics’ init() function, it should be calling aggregators.Add(“mdmratmetrics”, (etc.)), could you check if your plugin does that? Perhaps you had left the ‘basicstats’ name there by mistake, which seems like the most likely cause. Is your package named ‘mdmratmetrics’?