-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support in the confmap.Resolver to expand embedded config URIs inside configuration #4742
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where this functionality is going, I would love to hear from folks that are implementing downstream providers whether they have any concerns with this approach. To be clear this mean NewExpandConverter
remains as the public API to use moving forward?
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
This comment was marked as outdated.
This comment was marked as outdated.
Codecov Report
@@ Coverage Diff @@
## main #4742 +/- ##
==========================================
+ Coverage 91.65% 91.82% +0.16%
==========================================
Files 192 191 -1
Lines 11467 11521 +54
==========================================
+ Hits 10510 10579 +69
+ Misses 764 751 -13
+ Partials 193 191 -2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
This comment was marked as outdated.
This comment was marked as outdated.
This explains only how to provide the configuration via the `--config` file, after #4742 will update the embedded values option. Signed-off-by: Bogdan Drutu <[email protected]>
confmap/resolver.go
Outdated
return nil, err | ||
} | ||
mr.closers = append(mr.closers, ret.Close) | ||
return ret.AsRaw() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To confirm: we don't want to apply expandValue
recursively to the returned result here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How many times would we do this? Until no changes (can get into infinite loop, maybe try for 10 times if still resolving then return error?)?
I thought it is not useful, but I can see now point in having it (after you asked for it). Let's discuss the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can imagine 2 use cases:
- If you have a local config file where env variables are used (quite common, e.g. in Splunk distro) you may want to specify that the value must be retrieved from a remote source instead of providing it directly.
- The opposite: a config fetched from a remote location, but which refers to a local env variables (e.g. refer to $PATH or $TEMP).
How many times would we do this? Until no changes (can get into infinite loop, maybe try for 10 times if still resolving then return error?)?
Yeah, probably repeat until no more changes with some limit to avoid infinite looping. Any reasonable use case I can imagine should be 2 rounds, so limiting to something like 5 or 19 attempts should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest not introducing recursive expanding on this PR. We can forbid usage of $
, {
and }
in the URI on this PR and deal with this problem later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two problems, and probably we should address both, with different solutions:
- Embedding
${http://my.example.com?os=${env:OS_ENV}}
- Recursive
${file:/path/to/my/file}
which returns a section of the config as amap[string]interface{}
for example like{"key": ${env:VALUE}}
. Then should we expand${env:VALUE}
?
For 1. I think we can simply error now. For 2. I think we cannot error, we need to resolve that, and that is what @tigrannajaryan was referring to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I had the second case in my mind.
I am fine with deferring this to a future PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks both for clarifying. I think Tigran's suggestions above make sense and it's fine to support this now or later, whatever is easier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not clear at this point whether this can actually be introduced later. Will introducing embedding and recursive feature be an implementation detail or will it affect the user contract (like allowed symbols) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeromeinsf I think everyone agrees on leaving the implementation of (1) for later and restricting the allowed characters now. For (2), I believe @bogdandrutu wants to add support now with some recursion limit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(2) - Done
5b92e6a
to
d84b374
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only have one remaining question
func (mr *Resolver) expandValue(ctx context.Context, value interface{}) (interface{}, bool, error) { | ||
switch v := value.(type) { | ||
case string: | ||
// If it doesn't have the format "${scheme:opaque}" no need to expand. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like ${HOST_IP}:4317
does not get expanded then? Why don't we use os.Expand
like we are using on the expand provider?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because os.Expand
only supports returning strings (not a partial sub-map).
See https://pkg.go.dev/os#Expand
func Expand(s string, mapping func(string) string) string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but the problem of dealing with ${HOST_IP}:4317
still remains then? That would only be supported by environment variables?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to support this? What is a good use-case? I don't see a reason to have ${HOST_IP}:4317
, why hardcoded the port vs providing everything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some examples on contrib using this with environment variables:
- sapm exporter (see
endpoint
) - kubeletstats receiver (see
endpoint
) - basicauth extension (see
inline
) - Splunk's distro examples (this one is a host:port example actually :))
Why should environment variables work differently from other providers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ${THING_A}${THING_B}
pattern is also interesting. Right now, IIUC, we interpret this as "get the thing with URI THING_A}${THING_B
", which also seems counter to what I would expect to happen (I guess this relates to #5706 too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make progress, I disabled this feature from the Resolver. For the moment no way to enable this, but will send another PR that addresses the remaining issues and use a featuregate to enable this maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Sorry to bring this up so late, I hadn't realized until now
I created #5706 for the character set allowed in URIs. I think we can deal with this independently, since we potentially already have this problem with the environment variables (in principle any character except for |
978aa19
to
369aa72
Compare
…side configuration. Signed-off-by: Bogdan Drutu <[email protected]>
Based on this experiment we developed stable code fore: * Allowing support for multiple config "sources" via the "--config" flag and `confmap.Providers` * Work in progress support to allow support for embedding partial configs, see open-telemetry#4742 Signed-off-by: Bogdan Drutu <[email protected]>
Proposal on how we can extend our current config provider to support expanding (including) config "parts". This will fix #4231 and will fully implement same capabilities as proposed in #4468.
This design is based on the https://docs.google.com/document/d/1XlDpS8-a4Ds6uoe6C6WgO8mCpDaQNufcHSEmBpiCdI0/edit format which we already support for the "--config" flag.
confmap.Provider
changesExtend the capability of a
confmap.Provider
to return aProvided
value that can encapsulate aconfmap.Conf
or any partial config value (float64/int64/bool/string/map[string]interface{}/[]interface{} where map values or slice values have the same restrictions). The current design allowsrecursive
expansions, so values returned by expanding one embedded config URI will be searched for expanding again.Known caveats
${http://example.com/get_config?os=${env:OSNAME}}
will NOT expand first the OSNAME env var.Examples of usages
Retrieving token from zookeeper (scheme not yet defined)
Retrieving an entire exporter config from a file
Expanding env vars
Expand
Converter
vsembedded
configThe current proposal to support
embedding
config URIs, does not support the following cases that are supported by the expand envvarConverter
:$
without brackets:Because of these missing features the Expand
Converter
will be maintain for a period of time until a final decision between supporting or not the 2 missing features is made. If we decide to not support any of these features we can start at least by logging errors and disable the functionality behind a featuregate until we know if this is needed or not.Signed-off-by: Bogdan Drutu [email protected]