-
Notifications
You must be signed in to change notification settings - Fork 850
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
Migrate Metrics SDK "data' package to Attributes #3352
Migrate Metrics SDK "data' package to Attributes #3352
Conversation
- Finish wiring through changes to all code/tests. - DOES NOT touch API - Update existing tests to use new testing library to be sensitive to attribute vs. label hashing alterations + equality of the metrics.data package types.
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.
Just some small comments, no blockers. Thanks!
exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/MetricAdapter.java
Show resolved
Hide resolved
labelNames.add(sanitizedLabelName); | ||
// TODO: We want to create an error-log if there is overlap in toString of attribute | ||
// values for the same key name. | ||
labelValues.add(value == null ? "" : value.toString()); |
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.
Don't believe we support null values anymore, think we may have at some point before
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.
should I remove the check or keep it for safety?
assertThat(pointData.getLabels().size()).isEqualTo(0); | ||
|
||
assertThat(metric) | ||
.hasName("double_gauge") |
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.
Nice
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.
Thanks!
.hasDescription("double gauge") | ||
.hasUnit("ms") | ||
.hasDoubleGauge() | ||
.points() |
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.
Tend to like not switching gears in an assertion (i.e., allowing a further assertion on the metric after this one) with something like pointsSatisfyExactly(...)
. One reason is for the indentation to match the structure. I guess it's mostly just personal preference though so don't mind too much
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.
I hear you. I chose the methods to match existing patterns in Assertj, particularly around Iterables/Collections.
The TL;DR: is this matches Assertj even if I'm more of a hamcrest fan myself (primarily for composability).
Want to call out two things:
- The goal of this library is folks STOP using exact ordering where it's not important (you can choose when, but prefer
inAnyOrder
if you don't know whether order matters). If you look at examples there's a lot of.points().satisfiesExactlyInAnyOrder
. - There's a lot of Iterable matches I don't want to do a combinatorial explosion on providing, similar for Attributes. I could take an approach here (similar to what I did for Attribtues) where you can go into a
.points
or use ahasPoints
that implicitly uses "containsInAnyOrder".
} | ||
|
||
description = "OpenTelemetry SDK Testing utilities" | ||
otelJava.moduleName.set("io.opentelemetry.sdk.metrics-testing") |
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.
We've generally suffixed with metrics
in all our packages (even had a gradle hack that matched the suffix before the more declarative gradle.properties
:P). Since alpha and eventually will be merged into testing doesn't matter too much though
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.
If possible, I'd like to avoid chaning the module name (and directory) because I have a slew of PRs lined up behind this one for the new metrics implementation and the least amount of major rebasing I need to do, the better.
If this were a fundamental naming issue (or something that wouldn't be resolved when metrics goes stable) I'd be happy to change it, but as things are my commits are starting to get unwieldy if I leave this two long (hence trying to piece out components like this one for review).
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.
we can always go back and change module names at the end of the PR chain, if anyone feels strongly about it.
} | ||
|
||
/** Ensures the {@link Resource} associated with a metric matches the expected value. */ | ||
public MetricDataAssert hasResource(Resource resource) { |
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.
What do you think about just hasResourceAttributes
and hasResourceAttributesSatisfying
? Resource only has one field, attributes
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.
While I half-agree, in practice almost all the tests (and code) just pass Resource
wholesale, and check for the one static instance that was given to an SDK. Very rarely are folks checking resource detection/attribute scenarios in Metrics code.
I imagine you could add those two methods, but I don't think I'd wind up using them for most of the metrics tests.
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.
just FYI, Resource also has schemaUrl
now; not sure if that alters the fundamentals, though.
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/aggregator/MetricDataUtils.java
Outdated
Show resolved
Hide resolved
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.
There seems to be an empty file named point.getAttributes())
in the repo root. Is this intentional?
@pirgeo No, that was a botched commit from windows on my part. Must have done something dumb w/ copy-paste on the terminal. Fixed. |
|
||
/** Test assertions for {@link PointData}. */ | ||
public class AbstractPointDataAssert< | ||
PointAssertT extends AbstractPointDataAssert<PointAssertT, PointT>, |
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 style of type declaration isn't something we've used in the project up until now. I'm not fundamentally opposed to it, but it's definitely more verbose. @anuraaga any thoughts on this? Otherwise, I would think we'd want to go with <A,P>
or something like that.
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.
If you think A/P is more readable, happy to change. I chose what I did because I kept messing up the letters, otherwise.
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.
let's not block this PR on it. It's a simple thing to change in the future.
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/GaugeData.java
Outdated
Show resolved
Hide resolved
sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/data/PointData.java
Outdated
Show resolved
Hide resolved
I will admit I did not look at every single converted assertion, but this looks pretty good. Thanks for all the effort! Just a couple tiny nits and one question about generic type naming. |
With the
Labels
removal in the new Metrics API, this is a first cut at changing the existing implementation in preparation for the new SDK.What this PR brings:
io.opentelmetry.sdk.metrics.data
package now uses theio.opentelemetry.api.common.Attributes
type instead of the oldLabels
type.*.metrics.data
package. This is designed to:Labels
or relied on ordering/equality ofLabels
instances to use new Assertj library for metrics.Note:
Summary
is effectively deprecated in the OTel Data model (for backwards compat primarily), so it remains for OpenCensus Shims (Summary is also deprecated in OpenCensus) and I did not provide convenience APIs for summary. In the new SDK no instrument will output a summary by default.