-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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/ottl] Change OTTL contexts to handle paths with context #36820
base: main
Are you sure you want to change the base?
[pkg/ottl] Change OTTL contexts to handle paths with context #36820
Conversation
…with-context' into change-contexts-to-support-path-with-context
Hi @TylerHelmuth @evan-bradley! I've marked this PR as a draft so I can double check my understanding on the final solution, and discuss/implement a topic before starting fully reviewing it. Should we support fully qualified paths? let's take the
The above example would infer the
In this case, the inferred context would be the No accepting fully qualified paths would make it impossible to users to enforce certain context without using it in the statement. That said, I think we could accept both scenarios, for example, unqualified but correctly inferred from the statement:
And fully qualified, aiming enforcing certain context:
WDYT? |
Thanks @edmocosta, really excited to see this one.
I think that's a great observation. I'm personally in favor of adding this to allow users the ability to manually specify a context, I think we need to retain the ability for users to set contexts in ways not obvious from the paths alone. However, for this case:
Could we (maybe in the future if fully-qualified paths will allow us to get around this) add an option to the context inferrer to use context-specific functions as hints for the context a statement should run in? I think this will offer the best UX and allow users to avoid needing to think about how to force a context. |
I agree that it seems like we need the function context to be a part of the equation. I'm glad you thought of this example now bc I don't think we discussed this before. |
Yes, we can definitely make the context inferrer smarter adding the functions hint, it would require extracting the functions usage from the parsed statements, and verifying if the configured context parsers supports it, prioritising them accordingly. Even though it would solve the functions issue, we would still need to deal with enums, which are prone to the exactly same problem. Differently from the functions, the We can solve both issues changing the context inferrer - with the cost of increasing complexity a bit - but I'm wondering if we're missing any other edge-case here? Anyway, I don't think it would be a problem if we are - at least for now - considering users are still able to express their Summarising:
That said, If you folks agree, I'll change the context inferrer as discussed, verifying the configured parsers functions, and trying to parse the enums. |
Ya I like this approach as it avoids users having to write |
Hey @TylerHelmuth @evan-bradley, thanks again for the help, I've opened a new PR changing the context inferrer as discussed, and including the extra changes of this PR (to make it smaller). Once we get that PR merged, I'll update this one and mark as ready to review. |
…lector-contrib into change-contexts-to-support-path-with-context # Conflicts: # pkg/ottl/contexts/internal/metric.go # pkg/ottl/contexts/internal/resource.go # pkg/ottl/contexts/internal/scope.go # pkg/ottl/contexts/internal/span.go # pkg/ottl/contexts/ottldatapoint/datapoint_test.go # pkg/ottl/contexts/ottllog/log_test.go # pkg/ottl/contexts/ottlscope/scope_test.go # pkg/ottl/contexts/ottlspan/span_test.go # pkg/ottl/contexts/ottlspanevent/span_events_test.go
Description
This PR is part of #29017, and changes all existing OTTL contexts to properly handle
ottl.Path
withottl.Path.Context
. (I'm sorry for the big PR, but splitting it wouldn't make much difference considering all changes are related)OTTL contexts changes:
EnablePathContextNames
, so API consumers can enable the support to path with context names, previously added through [pkg/ottl] Change grammar to support expressing statements context via path names #34875.parsePath
functions were modified to properly handle paths with contexts.ContextName
(it might be useful to configure the parser collection, for example, but I'm fine hiding it if folks think it's not necessary)Considering we might deprecate the path without context support in the future, and aiming to avoid copy and paste all the existing tests, I've included some logic to dynamically copy the "without path context" tests, into a "with path context" tests, ensuring all paths are tested with both scenarios. I understand those generated tests make it hard to read/understand, but given the above considerations, I think it may be worth it (please let me know if you think otherwise, so I can change the approach).
Other important changes:
Currently, it's possible to have paths to contexts root objects, for example:
set(attributes["body"], resource)
. Givenresource
has no dot separators on the path, the grammar extracts it into thepath.Fields
slice, letting thepath.Context
value empty. Why? This grammar behaviour is still necessary to keep backward compatibility with paths without context, otherwise it would start requiring contexts for all paths independently of the parser configuration.Previous PRs didn't take this edge case into consideration, and a few places needed to be changed to address it:
prependContextToStatementPaths
functioncontexts/internal
), to also handleottl.Path
with only theContext
set as an object root access (in addition to the exitingpath == nil
condition)When/If we reach the point to deprecate paths without context, all those conditions can be removed, and the grammar changed to require and extract the context properly.
Link to tracking issue
#29017
Testing
Unit tests
Documentation
No changes