grafana / alloy

OpenTelemetry Collector distribution with programmable pipelines
https://grafana.com/oss/alloy
Apache License 2.0
979 stars 103 forks source link

Syntax: Expose command-line flag values to standard library #604

Open rfratto opened 2 months ago

rfratto commented 2 months ago

Request

I want to expose all command-line flag values to the standard library.

I'm not sure where the best place for this would be, and more discussion is needed. To kickstart discussions, this proposal will use a new top-level value called flags, a counterpart to constants:

Here, the flag names are transformed so that - is replaced with _ to be useable as an Alloy syntax identifier.

I initially proposed adding these as a sub-key in options (options.settings.FLAG_PATH) but the names were very unwieldy.

Use case

I deploy Alloy on my systems with a non-default listen port (usually 12380) to not collide with local development. I would like to be able to not have to hard-code the listen address into my configuration files, and use an expression instead. Normally I'd be able to use alloy.internal:12345, but even that is configurable, and doesn't work in all cases (see #603).

While I personally really only need constants.options.server.http.listen_addr and constants.options.server.http.memory_addr, I do think it would be generally a good idea to expose all of the command-line flags, as I'm sure use cases would arise where other values are useful (I can imagine constants.options.stability.level becoming more useful over time in modules to enable different behaviour at runtime within a module source).

mattdurham commented 2 months ago

To be clear you are wanting them to be read/write?

rfratto commented 2 months ago

No, read only.

mattdurham commented 2 months ago

Apologies, I misinterpreted I would like to be able to not have to hard-code the listen address into my configuration files, and use an expression instead. seems totally fine to me.

tpaschalis commented 2 months ago

How would you feel about starting off with a subset of these?

Eg. I can't see how someone could use the value of flags.disable_reporting or flags.extra_args to configure a component and I'm wary that someone will try to use these in a 'smart' way to pass values around instead of grafana/alloy#308 or grafana/agent#2772

rfratto commented 2 months ago

How would you feel about starting off with a subset of these?

I think it's a worthwhile discussion to have. Normally I prefer consistency, where exposing every flag would achieve that. Exposing a subset of flags also runs the risk of asking users to wait for future releases if someone does identify a use case for a flag value we chose not to expose initially.

github-actions[bot] commented 1 month ago

This issue has not had any activity in the past 30 days, so the needs-attention label has been added to it. If the opened issue is a bug, check to see if a newer release fixed your issue. If it is no longer relevant, please feel free to close this issue. The needs-attention label signals to maintainers that something has fallen through the cracks. No action is needed by you; your issue will be kept open and you do not have to respond to this comment. The label will be removed the next time this job runs if there is new activity. Thank you for your contributions!