census-instrumentation / opencensus-go

A stats collection and distributed tracing framework
http://opencensus.io
Apache License 2.0
2.06k stars 327 forks source link

Allow custom view.Meters to export metrics for other Resources #1212

Closed evankanderson closed 4 years ago

evankanderson commented 4 years ago

Working with #1196, I discovered that metricexport.Reader collects metrics from all registered Producers, but doesn't provide a way to distinguish between different Meters. (With RegisterExporter, I can hand off a different exporter for each Meter and curry the Resource that way.)

This fills in the existing metricdata.Resource field when available, which looks like it should already work with Stackdriver. Prometheus seems to ignore the Resource field; I can send a PR for that if desired.

jjzeng-seattle commented 4 years ago

We need a minor fix for stackdriver though. resource is overwritten by ResourceByDescriptor. https://github.com/census-ecosystem/opencensus-go-exporter-stackdriver/blob/master/metrics.go#L173

evankanderson commented 4 years ago

I'm wondering if we can leverage resource.MultiDetector for this:

https://github.com/census-instrumentation/opencensus-go/blob/master/resource/resource.go#L146

evankanderson commented 4 years ago

Alternatively, we could do the conversion on the recording side for Stackdriver in Knative, and retire the use of ResourceByDescriptor from Stackdriver.