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

[WIP] Fix incorrect metrics getting generated from multiple readers #5900

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pree-dew
Copy link
Contributor

@pree-dew pree-dew commented Oct 19, 2024

Will fix #5866

@dmathieu dmathieu marked this pull request as draft October 19, 2024 11:15
@dashpole dashpole added this to the v1.32.0 milestone Oct 21, 2024
@dashpole dashpole added bug Something isn't working area:metrics Part of OpenTelemetry Metrics labels Oct 21, 2024
@dashpole dashpole self-assigned this Oct 21, 2024
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking great overall.

switch o := inst.(type) {
case int64Observable:
if e := o.registerable(m); e != nil {
if !errors.Is(e, errEmptyAgg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will return the same error multiple times (once for each pipeline). I think we should iterate over instruments once to see if it is registerable, and construct a list of valid instruments. Then iterate over valid instruments once for each pipe and register the valid ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. I will make the change

for i, pipe := range p {
unregs[i] = pipe.addMultiCallback(c)
}
func (p pipelines) registerMultiCallbacks(unregs []func()) metric.Registration {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: consider removing this function, and just returning unregisterFuncs{f: unregs} from RegisterCallback

}

type observer struct {
embedded.Observer

pipe *pipeline
float64 map[observableID[float64]]struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take my advice above to do validation once for all pipelines, you should be able to remove these maps from the observer. IIRC, they are only used for validation, so you could just create these maps at the beginning of RegisterCallback.

@@ -530,7 +546,10 @@ func (r observer) ObserveFloat64(o metric.Float64Observable, v float64, opts ...
return
}
c := metric.NewObserveConfig(opts)
oImpl.observe(v, c.Attributes())
measures := r.pipe.float64Measures[oImpl.observableID]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to lock around this? It would be good to ensure our parallel tests Invoke a callback in parallel with RegisterCallbacks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will make the change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple periodic readers increment the counter abnormaly
2 participants