-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
receiver_creator: add dynamic configuration values #235
Conversation
This adds the ability to configure a receiver based on values from the observer. This might be from labels or some other metadata the user sets. This includes setting the port if the port is not able to be discovered through standard means. For example, in k8s it is optional for a pod to define the ports containers are listening on. Users may need to set those ports inside the config. This is possible with dynamic configuration. Will add docs to readme after other PR is merged. Example: ```yaml receivers: receiver_creator: redis: rule: type.pod && labels["app"] == "redis" config: endpoint: "`endpoint`:8382" ``` The text between backticks (in this case `endpoint`) is evaluated using expr (same type of expressions as with discovery rules).
Codecov Report
@@ Coverage Diff @@
## master #235 +/- ##
==========================================
- Coverage 77.86% 77.81% -0.05%
==========================================
Files 125 126 +1
Lines 6455 6528 +73
==========================================
+ Hits 5026 5080 +54
- Misses 1155 1167 +12
- Partials 274 281 +7
Continue to review full report at Codecov.
|
LGTM |
…ry-collector-contrib into dynamic-config
"github.com/antonmedv/expr" | ||
) | ||
|
||
func expandConfigValue(env endpointEnv, configValue string) (interface{}, error) { |
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.
Please add a comment to explain what does this expand and how.
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.
If I understand the code correctly this evaluates expressions inside backticks and replaces them with the result of evaluation. The name expandConfigValue
does not quite convey this. Perhaps evalBackticksInConfigValue
?
|
||
// expandMap recursively expands any expressions in backticks and returns a copy | ||
// of the resolved config. | ||
func expandMap(cfg map[string]interface{}, env endpointEnv) (map[string]interface{}, error) { |
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.
what does env
parameter do?
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.
Updated comment to include env.
// itself so that it retains the type returned by the expression. Might be a bool, int, etc. | ||
// instead of a string. | ||
if len(expansions) == 1 && output.String() == fmt.Sprintf("%v", expansions[0]) { | ||
return expansions[0], nil |
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 sure I understand this exception and how it behaves differently from the case when there are more than one expansions. Maybe add an example in the comment to make it clear.
Why does this function need to retain the type? Does this mean that:
`true` evaluates to boolean true
` true` evaluates to string " true"
This may be a surprising 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.
Yeah if you say:
`true``false` it will return string "truefalse" as there's really no way to concat true
and false
booleans. Same with numbers.
However if you say ` true` it will evaluate to true
boolean. The expression itself inside the backticks is not whitespace-sensitive. I've added a test case for it.
I'll also add some examples to the function doc.
An example where this matters might be:
config:
secure: `"secure" in labels`
There might be some magic in Viper/mapstructure that might check for "true" and "false" strings when deserializing but I thought it best to keep the types if possible.
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.
LGTM
This adds the ability to configure a receiver based on values from the observer. This might be from labels or some other metadata the user sets. This includes setting the port if the port is not able to be discovered through standard means. For example, in k8s it is optional for a pod to define the ports containers are listening on. Users may need to set those ports inside the config. This is possible with dynamic configuration. Will add docs to readme after other PR is merged. Example: ```yaml receivers: receiver_creator: redis: rule: type.pod && labels["app"] == "redis" config: endpoint: "`endpoint`:8382" ``` The text between backticks (in this case `endpoint`) is evaluated using expr (same type of expressions as with discovery rules).
- Exporters not used in any pipeline cause panic during shutting down. Signed-off-by: Hui Kang <kangh@us.ibm.com>
This adds the ability to configure a receiver based on values from the
observer. This might be from labels or some other metadata the user sets. This
includes setting the port if the port is not able to be discovered through
standard means.
For example, in k8s it is optional for a pod to define the ports containers are
listening on. Users may need to set those ports inside the config. This is
possible with dynamic configuration.
Will add docs to readme after other PR is merged.
Example: