node_exporter icon indicating copy to clipboard operation
node_exporter copied to clipboard

Refactor collector package configuration

Open SuperQ opened this issue 2 years ago • 8 comments
trafficstars

Add a new pattern to allow moving the flag handling out of the collector package and into a separate package. This allows collector package users to create their own config or flag handling.

SuperQ avatar Jul 21 '23 13:07 SuperQ

What is the use case here? I think keeping the flag definitions in the collector where they are used is better.

discordianfish avatar Jul 31 '23 12:07 discordianfish

Hey @discordianfish, the idea is to decouple flags (which in this case is an specific way of configuring the exporter as a standalone program) from the exporter's collectors providing a config struct The use case is make node exporter embeddable in grafana agent without having to depend on global state (i.e flags) to configure the collectors. In the future, this would allow users to configure multiple instances of node exporters (with the support of Flow modules) without worrying about potential race conditions.

More info/context here:

  • https://github.com/grafana/alloy/issues/548
  • https://github.com/grafana/agent/issues/3155

marctc avatar Jul 31 '23 16:07 marctc

@discordianfish Yes, the idea is to make the collector package more reusable as a library. I'm planning to do similar changes to other exporters.

SuperQ avatar Aug 01 '23 14:08 SuperQ

Ok but what about having collector specific config structs instead of one big node collector config?

discordianfish avatar Aug 08 '23 12:08 discordianfish

In https://github.com/prometheus/node_exporter/pull/2755/files#diff-b218d36a43d2b16cbfe05c8c78206818b70f54a802ee76ed990b5dc749ce6326R23-R26 ArpConfig struct is defined. I think it would make more sense to have those structs inside individual collector files IMHO.

marctc avatar Aug 08 '23 12:08 marctc

@discordianfish We need one top-level config struct so that we can pass it all to NewNodeCollector().

We will need to create a number of collector_common.go files in order to contain the per-collector structs so that they always exist even if the collector itself not compiled in (BSDs, Darwin, etc)

SuperQ avatar Aug 15 '23 09:08 SuperQ

A top level config for NewNodeCollector makes sense but not sure about passing that to each collector.. For most collectors we could also just pass the flag values to the constructor. We might also reconsider this init() based registration which I assume is also making consuming this as a module harder.

That being said, if you prefer this way here this is fine for me as well.

discordianfish avatar Aug 18 '23 11:08 discordianfish