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

Use view AttributeFilter #3390

Closed
1 task
MrAlias opened this issue Oct 21, 2022 · 4 comments · Fixed by #3396
Closed
1 task

Use view AttributeFilter #3390

MrAlias opened this issue Oct 21, 2022 · 4 comments · Fixed by #3396
Assignees
Labels
area:metrics Part of OpenTelemetry Metrics pkg:SDK Related to an SDK package

Comments

@MrAlias
Copy link
Contributor

MrAlias commented Oct 21, 2022

Currently the view.View type provides an AttributeFilter method and the related WithFilterAttributes option.

// AttributeFilter returns a function that returns only attributes specified by
// WithFilterAttributes. If no filter was provided nil is returned.
func (v View) AttributeFilter() func(attribute.Set) attribute.Set {
if v.filter == nil {
return nil
}
return func(input attribute.Set) attribute.Set {
out, _ := input.Filter(v.filter)
return out
}
}

// WithFilterAttributes will select attributes that have a matching key. If not used
// or empty no filter will be applied.
func WithFilterAttributes(keys ...attribute.Key) Option {
return optionFunc(func(v View) View {
if len(keys) == 0 {
return v
}
filterKeys := map[attribute.Key]struct{}{}
for _, key := range keys {
filterKeys[key] = struct{}{}
}
v.filter = attribute.Filter(func(kv attribute.KeyValue) bool {
_, ok := filterKeys[kv.Key]
return ok
})
return v
})
}

These are unused in the SDK.

  • Remove this method and option, or use this method in the SDK to filter attributes.
@MadVikingGod
Copy link
Contributor

I don't think we can just remove this. This is a feature described in the view specification.

When working on this I found that we have incorrect logic of the async sum aggregator. The scenario I have is if you have an async counter and a filter you can have two Observers that should be summed.

eg:

v, err := view.New(
	view.MatchInstrumentName("*"),
	view.WithFilterAttributes(attribute.Key("foo")),
)
...

mtr.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) {
	ctr.Observe(ctx, 10, attribute.Int("version", 1))
	ctr.Observe(ctx, 20, attribute.Int("version", 2))
})

I would expect this would return a sum of 30 on collect.

@MadVikingGod MadVikingGod linked a pull request Oct 25, 2022 that will close this issue
@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 25, 2022

I don't think we can just remove this. This is a feature described in the view specification.

When working on this I found that we have incorrect logic of the async sum aggregator. The scenario I have is if you have an async counter and a filter you can have two Observers that should be summed.

eg:

v, err := view.New(
	view.MatchInstrumentName("*"),
	view.WithFilterAttributes(attribute.Key("foo")),
)
...

mtr.RegisterCallback([]instrument.Asynchronous{ctr}, func(ctx context.Context) {
	ctr.Observe(ctx, 10, attribute.Int("version", 1))
	ctr.Observe(ctx, 20, attribute.Int("version", 2))
})

I would expect this would return a sum of 30 on collect.

Can you open an issue to track this bug?

@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 27, 2022

Given the mentioned bug, and #3396 (comment)

I think this bug is more subtle that just saying that it is in the sum aggregator (though, to be precise, it relates to the precomputedSum).

When a user passes a value to Observe it is interpreted as being the pre-compute cumulative sum value. If Observe is called twice in a callback and observed to be different values for the same attribute set, shouldn't the last value observed be used? It is the value the user is reporting the sum to be at. It seems to make sense in this situation that the last value is used.

However, the issue is the user didn't report the cumulative sum for the empty attribute set here, they report one for version 1 and one for 2. The question becomes, how should precomputed sums be combined when we know they are reported for different attribute sets? This means that the solution to this issue is going to revolve around the filter aggregation because that is the only place that know it is combining two distinct attribute sets (unless we redefine where attribute recording is done: #3030). The issue to resolve is it doesn't know it is combining them for the precomputedSum aggregator though.

We should probably look into how other SIGs are resolving this and if there is any specification on this behavior.

@MrAlias
Copy link
Contributor Author

MrAlias commented Oct 27, 2022

Specification issue related to behavior question: open-telemetry/opentelemetry-specification#2905

@MrAlias MrAlias added this to the Metric v0.34.0 milestone Oct 27, 2022
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 pkg:SDK Related to an SDK package
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants