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

Expand test coverage of OpenCensus-Shim by testing metrics integrations. #3835

Merged
merged 12 commits into from Nov 10, 2021

Conversation

jsuereth
Copy link
Contributor

@jsuereth jsuereth commented Nov 6, 2021

  • Refresh the metric adapting code to account for all OpenCensus points.
  • Move code into an easier-to-unit-test location
  • Deprecate previous Exporter -> Exporter adaption process, favoring hooking the MetricReaderFactory as a better (available) option.
  • Add a lot more tests.
  • Update documentation based on new tests.

Things I did not do, but wish were easier

  • I'd like to have a hook in the autoconfigure module that detects the availability of this class and setting an environment flag, which would automatically attach OpenCensus metrics to any registered metric reader (or some such to-be-specified behavior).
  • I'd love if i could access the Resource off the SDK in some fashion. We could pass it down the MetricReaderFactory interface, but looking for opinions there.
  • I did not refresh / move the tracing testing nor did I get a trace + metrics test working. That would be a pending PR.

- Move metric conversion into its own utility (outside exporter)
- Add a series of tests for all open-census types.
- Update conversion code to work for ALL features of OTel metrics and
  OpenCensus metrics.  Notes:
  - OC exemplars have wonky trace-attachments.  Using crazy "no binary"
    workaround.
  - OC has gauge histogram.  Encoding as DELTA with same start/stop
    timestamp as closest OTEL equivalent
  - OC has summaries, so we'll need to keep that data type around for
    compatibility, unless we can tackle the raw measurements and push
    them into Histograms.
@codecov
Copy link

codecov bot commented Nov 6, 2021

Codecov Report

Merging #3835 (674db2b) into main (790215e) will increase coverage by 0.18%.
The diff coverage is 90.65%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #3835      +/-   ##
============================================
+ Coverage     89.19%   89.38%   +0.18%     
- Complexity     4040     4085      +45     
============================================
  Files           486      491       +5     
  Lines         12524    12650     +126     
  Branches       1221     1232      +11     
============================================
+ Hits          11171    11307     +136     
+ Misses          933      925       -8     
+ Partials        420      418       -2     
Impacted Files Coverage Δ
...opencensusshim/internal/metrics/MetricAdapter.java 89.07% <89.07%> (ø)
...y/opencensusshim/OpenTelemetryMetricsExporter.java 83.33% <100.00%> (+10.91%) ⬆️
...ry/opencensusshim/metrics/MultiMetricProducer.java 100.00% <100.00%> (ø)
...etrics/OpenCensusAttachingMetricReaderFactory.java 100.00% <100.00%> (ø)
...encensusshim/metrics/OpenCensusMetricProducer.java 100.00% <100.00%> (ø)
...etry/opencensusshim/metrics/OpenCensusMetrics.java 100.00% <100.00%> (ø)
...emetry/api/baggage/propagation/PercentEscaper.java 79.69% <0.00%> (-4.52%) ⬇️
...metry/sdk/metrics/export/PeriodicMetricReader.java 81.66% <0.00%> (-3.34%) ⬇️
...ntelemetry/sdk/extension/resources/OsResource.java 90.69% <0.00%> (+4.65%) ⬆️
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 790215e...674db2b. Read the comment docs.

* @param censusMetric The OpenCensus metric to convert.
*/
public static MetricData convert(Resource otelResource, Metric censusMetric) {
// Note: we can't just adapt interfaces, we need to do full copy because OTel data API uses
Copy link
Contributor

Choose a reason for hiding this comment

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

We changed it to an interface, is there something that still needs to be switched?

https://github.com/open-telemetry/opentelemetry-java/pull/3783/files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's an unimplementable interface because all of the methods return AutoValues that you can't implement.

String traceId = null;
if (exemplar.getAttachments().containsKey("SpanContext")) {
// We need to use `io.opencensus.contrib.exemplar.util.AttachmentValueSpanContext`
// The `toString` will be the following:
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As an FYI - I created a test directly against the exemplar-utils library, but still did not take a dependency on it in the shim.

import java.util.Collection;
import java.util.List;

/** Class that wraps multiple metric producers into one. */
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a similar class for exporter, should this be in the SDK as an official class? Or only has value for metrics shim since otherwise only the OTel SDK produces metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which class are you talking about? I think I use the composite pattern in a few places, but not this one just yet.

Regarding longer term plans, post SDK stable launch, I hope to expose (via specification) a hook on SdkMeterProvider to register something like this for adapting external metric systems. For now, I just wanted better code coverage and there was a quick win for a nicer hook with the new metrics SDK. (Note: Whatever we do here + in Go will drive the OpenCensus compatiblity specification

}

tasks.named<Test>("test") {
// We must force a fork per-test class because OpenCensus pollutes globals with no restorative
Copy link
Contributor

@anuraaga anuraaga Nov 9, 2021

Choose a reason for hiding this comment

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

Is it possible to split test sets to work around this to not fork on every test case? forkEvery(1) goes sloooow

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only for some of the tests. I've tried to limit what's there to just the ones we need, but for some of the coverage I do needs to actually set up OpenCensus.

OpenCensus itself tended to use heavy mocks/mocking for various metric things. Really appreciate in OTel the global-cleaning utiities.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah if we can identify those tests that need it and split them into test suites at least it doesn't have to fork for every single one.

@jkwatson
Copy link
Contributor

jkwatson commented Nov 9, 2021

I'd like to have a hook in the autoconfigure module that detects the availability of this class and setting an environment flag, which would automatically attach OpenCensus metrics to any registered metric reader (or some such to-be-specified behavior).

I think this is something that should go through the spec or something official, yes? Something like "how to enable the OpenCensus integration" so it's at least similar across languages?

@jsuereth
Copy link
Contributor Author

@jkwatson

I think this is something that should go through the spec or something official, yes? Something like "how to enable the OpenCensus integration" so it's at least similar across languages?

Yes, that's the plan. However, I'd like to get an implementation ahead of the spec to justify what will work across features. Also looking to make similar changes on the Go side over time (the current prototypes the OpenCensus spec is based on).

@jkwatson jkwatson merged commit 3b1be74 into open-telemetry:main Nov 10, 2021
@jsuereth jsuereth deleted the wip-census-shim-testing branch November 10, 2021 02:05
@sullis sullis mentioned this pull request Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants