-
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
[DO NOT MERGE] Demonstrate various usages of pdata Range functions #29613
Conversation
|
||
signature := timeseriesSignature(il.Name(), metric, ip.Attributes(), resourceAttrs) | ||
if ip.Flags().NoRecordedValue() { | ||
a.registeredMetrics.Delete(signature) | ||
return 0 |
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.
This is probably the worst case I ran into. We want to be able to short circuit the loop in order to stop accumulating into n
, but we can't use n
itself to check if we should stop aggregating. Therefore, a completely unrelated variable is introduced to control whether the loop actually executes.
if err != nil { | ||
return err | ||
return // Would use RangeWhile instead if available |
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.
This was another situation where not being able to short circuit the loop resulted in unintuitive code. Instead of immediately returning an error, we have to save it, and then use it to determine whether or not each subsequent iteration should actually do anything.
Here are the improvements we could make here if using a |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Demonstrates functions proposed in open-telemetry/opentelemetry-collector#8938
The main takeaway for me is that
Range
is quite useful, but there are quite a lot of situations where short circuiting the loop would be useful. It's possible to handle these with theRange
func as is, but it feels unintuitive because it has to rely on checking an external value in each iteration. I think it's worth exploring whether it feels too intrusive to add a bool to indicate continuation of the loop.