-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
An easier way to partial match metric attributes is needed for the metricdatatest assert functions #3435
Comments
This is probably about the default resources (sorry if it is not), would there be a way to create a mock for the default resources during tests, making them deterministic or at least using an empty resource for those cases? I feel like having exact matches for tests is better and lead to less buggy code than checking for a subset of things. |
It was for metric instruments: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/2962/files#diff-4952dc7ae3d29c757b4554040c9b95d338aeb80ce6f88691cf17f845280f78e6R378-R392 Though I do wonder if we should provide something that says "check for the default resource". |
#3487 adds a function to assert a type has a set of attributes, but it does not resolve this issue. It is still not possible to compare a minimal set of attributes are contained by a type. The function added in #3487 may need to be updated to accept a configuration to signal this type of comparison, or another function will need to be added. We need to have a plan prior to GA as this will be an API breaking change to add a config. |
#3487 does allow for a partial match. It specifically checks if Here is an example: https://go.dev/play/p/2gAJjYE_SC0 |
Hmm, yeah, that looks correct. I'm not sure why I thought otherwise 😕. Closing then as this looks resolved by #3487 |
Problem Statement
I'm always frustrated when I need to assert an incomplete set of attributes exist for a metric using the metricdatatest assert functions.
For example, I know all of my sums should contain the
attribute.String("statement", "INSERT")
attribute, but they will also contain an attribute describing the host. The host changes every test, therefore, I only want to assert the attribute set contains the known attribute and not fail because it also contains extra attributes.Proposed Solution
Add an option to support this
Alternatives
Define a new type in the
attribute
package that acts as a "minimal set" and when compared to aSet
it would do the desired comparison.The text was updated successfully, but these errors were encountered: