Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

djaglowski
Copy link
Member

@djaglowski djaglowski commented Dec 1, 2023

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 the Range 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.


signature := timeseriesSignature(il.Name(), metric, ip.Attributes(), resourceAttrs)
if ip.Flags().NoRecordedValue() {
a.registeredMetrics.Delete(signature)
return 0
Copy link
Member Author

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
Copy link
Member Author

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.

@djaglowski
Copy link
Member Author

Here are the improvements we could make here if using a RangeIf for short circuiting: djaglowski/opentelemetry-collector-contrib@pdata-range-demo...djaglowski:opentelemetry-collector-contrib:pdata-rangeif-demo

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Dec 16, 2023
Copy link
Contributor

Closed as inactive. Feel free to reopen if this PR is still being worked on.

@github-actions github-actions bot closed this Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant