-
Notifications
You must be signed in to change notification settings - Fork 2.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
[pkg/stanza] Upgrade to github.com/antonmedv/expr v1.12.7 breaks tests #24575
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
It looks like the Unfortunately, we already had added some custom behavior for the same keyword. The test failures quite clearly appear to be related:
I'm looking into it, but we likely need to lock in the version of the module for now. |
Fixes #24575 This upgrade involves a workaround for a grammar conflict introduced in [this PR](https://github.com/antonmedv/expr/pull/382/files). `pkg/stanza` previously added a custom function to the syntax called `env()`, which allows users to fetch values from OS environment variables. The latest version of the `expr` module introduced its own keyword `env`, but the meaning and usage were different. Still, the overlap was enough to cause failures in the compilation and rendering of expressions. The new syntax was introduced as a [Membership Operator](https://expr.medv.io/docs/Language-Definition#membership-operator), which means that the proper way to use it is with square brackets, `env[]`. This resulted in our custom `env()` syntax being flagged as invalid. More importantly, the meaning of the new `env[]` is not the same. While we use `env()` to lookup values from the OS environment, `env[]` is meant to pull values from an in-memory map. This map allows for customizations of the syntax, such as those that allow users to reference "body" or "attributes" within an expression, but it does not contain OS environment variables. Therefore, accessing it with the new syntax is of limited value to users. The solution used here is a [Patch](https://github.com/antonmedv/expr/blob/d2100ece96affe6766d97e2cf0e4ca4d145f0d30/expr.go#L98) option which allows us to inspect and modify elements of the grammar as an expression is being compiled. Fortunately, `env()` is understood to be a function call, while `env[]` is otherwise. This makes it possible to detect usage of our custom syntax and rename the function internally without any impact to the user. The PR also standardizes all uses of `expr.Compile` within `pkg/stanza` to ensure they are using the new patch option.
Hmm. env is very popular keyword. I will change it to something less popular. |
Component(s)
pkg/stanza
What happened?
See CI failure: https://github.com/open-telemetry/opentelemetry-collector-contrib/actions/runs/5650490793/job/15307018157?pr=24536
To reproduce, update
github.com/antonmedv/expr
to v1.12.7 in pkg/stanza/go.mod, then run the tests withmake test
.Collector version
n/a
Environment information
Environment
OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")
OpenTelemetry Collector configuration
No response
Log output
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: