open-telemetry / opentelemetry-specification

Specifications for OpenTelemetry
https://opentelemetry.io
Apache License 2.0
3.71k stars 887 forks source link

Clarify configuring aggregations with MetricReaders #2643

Open legendecas opened 2 years ago

legendecas commented 2 years ago

https://github.com/open-telemetry/opentelemetry-specification/pull/2404 updated the requirements to construct a metric reader:

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.12.0/specification/metrics/sdk.md#metricreader

To construct a MetricReader when setting up an SDK, the caller SHOULD provide at least the following: ...

  • The default output aggregation (optional), a function of instrument kind. If not configured, the default aggregation SHOULD be used.
  • The default output temporality (optional), a function of instrument kind. If not configured, the Cumulative temporality SHOULD be used.

It stated that a MetricReader can be constructed with a function to select aggregations for an instrument kind. However, the spec also says that aggregation is configured via the view APIs:

https://github.com/open-telemetry/opentelemetry-specification/blob/v1.12.0/specification/metrics/sdk.md#aggregation

An Aggregation, as configured via the View, informs the SDK on the ways and means to compute Aggregated Metrics from incoming Instrument Measurements.

AFAICT, aggregations configured with views are visible to all metric readers. There are two problems with configuring aggregation with MetricReaders:

  1. It is not clear if the aggregation configured by a MetricReader should be visible to other metric readers, as it is said that MetricReader.collect should not cause side-effects to other metric readers, but not mentioning other MetricReader methods like the constructor.
  2. How to handle conflicts since MetricReader can not change the name of the instrument like views?

The SDK MUST support multiple MetricReader instances to be registered on the same MeterProvider, and the MetricReader.Collect invocation on one MetricReader instance SHOULD NOT introduce side-effects to other MetricReader instances.

legendecas commented 2 years ago

@jsuereth hi, thank you for taking a look at this issue. But I'm not sure what the label "triaged-accepted" means -- as there aren't any resolutions settled yet for this issue.

jsuereth commented 2 years ago

It means this is an issue and should get worked on. We started a spec-triaging meeting Fridays to help get through the backlog of Specification issues. The result is either:

Hope that helps!

jsuereth commented 2 years ago

It is not clear if the aggregation configured by a MetricReader should be visible to other metric readers, as it is said that MetricReader.collect should not cause side-effects to other metric readers, but not mentioning other MetricReader methods like the constructor.

It (generally) should not be visible. The naive implementation of this specification would lead to a per-reader "in memory storage" of metrics. If SDKs can optimise metric storage to "share" between readers, that's up to them. However, practically, with these changes I'd almost think we're (mostly) forced into per-metric-reader storage.

@reyang had a design that allowed sharing of partial-aggregated data between metric readers however I think, in practice, this is at odds with the real goal of #2404 - Minimizing the amount of memory consumed based on who is using the metric, and letting the "best" knowledgeable component make that decision (the exporter).

In more succinct terms:

How to handle conflicts since MetricReader can not change the name of the instrument like views?

@reyang can confirm, but I think the intention here was always this order:

So to me that leaves two open AIs if you agree:

jmacd commented 2 years ago

See also https://github.com/open-telemetry/opentelemetry-specification/issues/2288

jsuereth commented 2 years ago

Discussed in Specificaiton SiG:

Action Items:

jmacd commented 1 year ago

I propose to close this issue in favor of https://github.com/open-telemetry/opentelemetry-specification/issues/2746 and https://github.com/open-telemetry/opentelemetry-specification/issues/2810.

legendecas commented 1 year ago

https://github.com/open-telemetry/opentelemetry-specification/issues/2643#issuecomment-1181900859 A PR to the specification to make it clear override semantics of Views + Reader defaults.

@jmacd I believe this action item is still applicable and distinct to this issue.