Stats/Exemplar: Add a generic AttachmentValue class.#1779
Stats/Exemplar: Add a generic AttachmentValue class.#1779songy23 merged 11 commits intocensus-instrumentation:masterfrom
Conversation
|
This is still WIP, but before I move on to implementation I'd like to get some early feedback on how the API looks like |
3ed832d to
1fb8b23
Compare
| */ | ||
| @Immutable | ||
| @AutoValue | ||
| public abstract class AttachmentValueSpanContext extends AttachmentValue { |
There was a problem hiding this comment.
The idea is we cannot have Trace APIs dependency in Stats APIs, but we can extend the generic abstract class in a contrib util package and have the util depend on both Trace and Stats APIs.
There was a problem hiding this comment.
That is correct. Maybe put this in comment. Also say we try to avoid having the Trace API ....
| */ | ||
| @Immutable | ||
| @AutoValue | ||
| public abstract class AttachmentValueSpanContext extends AttachmentValue { |
There was a problem hiding this comment.
That is correct. Maybe put this in comment. Also say we try to avoid having the Trace API ....
| * | ||
| * @since 0.20 | ||
| */ | ||
| public abstract <T> T match( |
There was a problem hiding this comment.
I don't think the match pattern is a good option here. Just have a:
public abstract String getValue();We can do a bit of a hack in the exporter and have:
if (value instanceof AttachmentValueSpanContext) {
AttachmentValueSpanContext avsc = (AttachmentValueSpanContext) value;
avsc.getSpanContext();
}There was a problem hiding this comment.
Agree that match pattern is not very useful in this case since there's only one subclass in the API. Having a getValue instead makes sense to me.
a6f1bed to
f2854fc
Compare
Codecov Report
@@ Coverage Diff @@
## master #1779 +/- ##
============================================
- Coverage 82.45% 82.36% -0.09%
- Complexity 1993 1995 +2
============================================
Files 291 293 +2
Lines 9221 9234 +13
Branches 891 891
============================================
+ Hits 7603 7606 +3
- Misses 1320 1329 +9
- Partials 298 299 +1
Continue to review full report at Codecov.
|
| * @since 0.8 | ||
| */ | ||
| @Immutable | ||
| @javax.annotation.concurrent.Immutable |
There was a problem hiding this comment.
why full qualifier here?
There was a problem hiding this comment.
Without it, nullness checker framework would complain:
/usr/local/google/home/songya/Google/opencensus-java/api/src/main/java/io/opencensus/stats/AggregationData.java:261: error: cannot find symbol
@Immutable
^
symbol: class Immutable
location: class AggregationData
1 error@sebright Do you have any suggestion here?
There was a problem hiding this comment.
I checked out this branch, removed "javax.annotation.concurrent.", and ran ./gradlew assemble -PcheckerFramework, but I couldn't reproduce the error. Did you make another change that affects the null analysis in this file?
There was a problem hiding this comment.
See https://travis-ci.org/census-instrumentation/opencensus-java/jobs/501696694#L541 after 50a4033:
/home/travis/build/census-instrumentation/opencensus-java/api/src/main/java/io/opencensus/stats/AggregationData.java:261: error: cannot find symbol
@Immutable
^
symbol: class Immutable
location: class AggregationData
1 error
> Task :opencensus-api:compileJava **FAILED**I got the exact same error on my desktop by running ./gradlew clean assemble -PcheckerFramework.
There was a problem hiding this comment.
Thanks. I can't reproduce it locally, but I'll keep looking into the failure on Travis.
| * @return an {@code Exemplar}. | ||
| * @since 0.20 | ||
| */ | ||
| public static Exemplar createNew( |
There was a problem hiding this comment.
Why do you have a different name here?
There was a problem hiding this comment.
Because we already have an API with the same signature:
opencensus-java/api/src/main/java/io/opencensus/stats/AggregationData.java
Lines 494 to 495 in ffd2176
The only difference is the type argument in
Map and Java doesn't allow us to overload a method with just that.
Another option is to just remove the old API. This will be a breaking change but I don't think anyone except the Stats exporters are depending on this.
There was a problem hiding this comment.
Same argument for getAttachments, what do you think? I think removing this is the best option, we don't break any instrumented code with this.
There was a problem hiding this comment.
Agree that removing the deprecated APIs are the easiest. I won't expect any client code depending on those APIs since no backend supported Exemplar before. Going to make the change.
d537c30 to
d76abe3
Compare
| return labelValues; | ||
| } | ||
|
|
||
| static Map<String, String> toStringAttachments(Map<String, AttachmentValue> attachments) { |
There was a problem hiding this comment.
For the moment Exemplars in Metrics still have <string, stirng> attachments: https://github.com/census-instrumentation/opencensus-proto/blob/c9cc5de7251f8a320dd6cb4f92e5698ba86f284c/src/opencensus/proto/metrics/v1/metrics.proto#L263.
For now we need to convert AttachmentValue in Stats API to string in Metrics API.
There was a problem hiding this comment.
We can modify that because we respect the data model, the fact that we delay the string formatting doesn't mean we don't respect the proto. This is one of the reason we don't directly use the protos.
There was a problem hiding this comment.
That would be tricky since AttachmentValue is part of Stats APIs and Metrics APIs cannot have dependency on Stats APIs. If we really want to replace the <string, string> attachments in Metrics APIs, the only option I can see is to put Exemplar and AttachmentValue in common artifacts or a top-level API (which Go already does: https://github.com/census-instrumentation/opencensus-go/tree/master/exemplar).
Either way I would prefer to do it in a separate PR since this one is already large.
There was a problem hiding this comment.
Sure, agree, let's discuss in a separate PR.
|
Any reason to not merge this? |
|
@rghetia and @dinooliva mentioned they were also reviewing this PR - any comments/concerns on this? (More changes will follow in a follow-up PR.) |
|
Going to merge this PR by EOD today if there're no other comments. More refactoring is in #1791. |
Updates #1775.