-
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
[ottl] Demonstrate simpler context constructors #36188
base: main
Are you sure you want to change the base?
Conversation
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'm not opposed to refactoring these as they have been a source of pain as OTTL has grown. We've had to change them in the past to support new parameters.
I'd much rather introduce something that scales like Options or a struct or something that can easily take a new parameter without breaking the function signature. We keep saying "this is the last parameter we'll need bc that's all the proto defines" but then there are exceptions (like schema).
I see where you're coming from but I think with pdata not stable we can probably make some clearer decisions. Notably, we can separate it into two questions:
Here I think the answer is no. If we made anything optional it would force the functions to check for presense and act defensively, likely bail out. This is why I suggest changing the signature but not the information. The same information is available with fewer parameters because of changes to pdata that are now finalized. (e.g. don't need to pass in ScopeSpans and InstrumentationScope, because ScopeSpans has a 1:1 with InstrumentationScope and makes it available via Scope() method.
I can't give a clear answer here, but would note:
|
Your arguments are why we've stuck with parameters so far: we want to represent the information as required. I am ok continuing this pattern but since we're taking the opportunity to change the parameters it would be nice to do another review of pdata and make sure there isn't any remaining pieces of information we're missing in the TransformContext. |
I took a fresh look at the pdata packages and came away with a strategy that is pretty close to what I suggested, with an important difference. First, I think it's helpful to separate this analysis into two sections. The first looks at signal-specific contexts (log, metric, datapoint, span, spanevent), and the second looks at signal-agnostic contexts (resource, scope). There is a fundamentally different consideration for how these two categories need to be defined, which I will describe later. Signal Specific ContextsThe signal specific data models follow a consistent pattern. Obviously they are hierarchical, but they are somewhat difficult to understand at times because of all the overlapping names. I think it's easier to illustrate my point if we use a simple analogy, so imagine a tree structure where each node contains (1) multiple values and (2) child elements. type Node struct {
value1 any
value2 any
children []*Node
} Our The solution is to construct contexts from the nodes themselves. More specifically, a context should be the sequences of nodes in the hierarchy that leads to the lowest level node. i.e. Using
Based on this insight, my initial proposal falls short because it leaves out the root node, which means we don't have access to a value which may be useful, and we can't modify its slice of children even though we can modify other slices of children in the hierarchy. Now, I'm not certain we really need access to the Therefore, my recommendation is that for signal-specific contexts, we should construct each context starting from top level object, and include exactly the elements of the hierarchy which directly contain slices of sub-elements. This ensures that all possible values and slices are accessible.
Interestingly, the pattern is so consistent that we could even offer constructors based on indices. e.g. Signal Agnostic ContextsTo use another analogy, the difference between resource and scope contexts is similar to that between interfaces and structs. The resource and scope contexts are presented consistently across signals, but we're only able to do this by going into each different type of data and extracting from it that which is common. Specifically, However, we could in theory define signal-specific versions of the resource and scope contexts, e.g. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@djaglowski I like this approach. Due to increase interest in exposing the |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
@djaglowski if you've still got time for this we'd accept the change. |
Hopefully not long after the new year I can make this a priority. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
This is just a proof of concept PR, rather than an issue.
I've been working with OTTL contexts lately and noticed that some of the parameters seem to be redundant. Looking back at the commit history, I believe the context constructors were created prior to some refactoring in pdata packages, so the redundancy appears to have been inherited from upstream changes.
My question is whether or not we could introduce a simpler set of constructors at this point, and potentially deprecate the old ones, maybe even push these changes down into the functions (which could access the same information).