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

Add details for Aggregator in Metric spec #1804

Closed
wants to merge 11 commits into from
142 changes: 142 additions & 0 deletions specification/metrics/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,148 @@ active span](../trace/api.md#context-interaction)).
+------------------+
```

### Aggregation MeasurementProcessor
victlu marked this conversation as resolved.
Show resolved Hide resolved

An `Aggregation` `MeasurementProcessor` is responsible for providing incoming
Instrument `Measurements` to the correct [`Aggregator`](#Aggregator) instances.

The `Aggregation` `MeasurementProcessor` MUST have access to `In-Memory State`.

The `Aggregation` `MeasurementProcessor` MUST create and configure
[`Aggregators`](#Aggregator) based on [View](./sdk.md) configuration.

e.g. Create a Sum Aggregator with monotonic values and delta temporality.

The `Aggregation` `MeasurementProcessor` MUST provide `Measurements` to the
properly configured `Aggregators` based on [View](./sdk.md) configuration.

e.g. A View re-configures a temperature Gauge Instrument to use a Histogram
aggregator with custom bucket boundaries and cumulative temporality.

e.g. A View re-configures a temperature Gauge Instrument to count by Attribute
"Location" (e.g. "Location=Portland" or "Location=Seattle"). The Aggregation
MeasurementProcessor provides measurements to the Aggregator instance that
handles the specific Attribute Key/Value combination.
(i.e. "Location=Portland" => Aggregator #1, "Location=Seattle" => Aggregator #2)

e.g. A View re-configures a temperature Gauge Instrument to be ignored and not
generate any metrics.

```text
+---------------------------+
| Aggregation |
| MeasurementProcessor |
| | +-----------------+
| ... | | |
[Measurements]-----> ... <--------------------->| In-Memory State |
| ... | | |
| | | +-----------------+
| | +--------------+ |
| | | Aggregator | |
| | | | |
| +---->"Update" | |
| | | ... | |
| | | "Collect"--------[Pre-Aggregated Metrics]-->
| | +--------------+ |
| | |
| | +--------------+ |
| | | Aggregator | |
| | | | |
| +---->"Update" | |
| | ... | |
| | "Collect"--------[Pre-Aggregated Metrics]-->
| +--------------+ |
| |
+---------------------------+
```

### Aggregator
victlu marked this conversation as resolved.
Show resolved Hide resolved

An `Aggregator` computes incoming [Measurements](./api.md#measurement) into
[Pre-Aggregated Metrics](./datamodel.md#opentelemetry-protocol-data-model).

An `Aggregator` MUST provide a mean to "update" itself given
[Measurement](./api.md#measurement) data.

An `Aggregator` MUST provide a mean to "collect"
[Pre-Aggregated Metric](./datamodel.md#timeseries-model) data.
The collect call should be treated as a stateful action and may reset its
internal state.

e.g. When an Exporter (support only Cumulative temporality) collects from
a SumAggregator with delta temporality, the Exporter may drop the metrics OR
support DELTA to CUMULATIVE conversion.

e.g. When an Exporter (support only Delta temporality) collects from
a SumAggregator with cumulative temporality, the Exporter may drop the metrics
OR support CUMULATIVE to DELTA conversion.

The SDK MUST provide the following Aggregators to support the
[Metric Points](./datamodel.md#metric-points) in the
[Metrics Data Model](./datamodel.md).

- [Sum Aggregator](#SumAggregator)
- [Last Value Aggregator](#LastValueAggregator) (For Gauge Metric Point)
- [Explicit Bucket Histogram Aggregator](#ExplicitBucketHistogramAggregator)

#### SumAggregator

The Sum Aggregator collect data for the
[Sum Metric Point](./datamodel.md#sums)
and reports the arithmetic sum of seen `Measurements`.
This Aggregator may be configured for monoticity and temporality.
victlu marked this conversation as resolved.
Show resolved Hide resolved

A [Default Aggregator](#DefaultAggregators) MUST be provided.

#### LastValueAggregator

The Last Value Aggregator collect data for the
[Gauge Metric Point](./datamodel.md#gauge)
and reports the last seen `Measurement`.

A [Default Aggregator](#DefaultAggregators) MUST be provided.

#### ExplicitBucketHistogramAggregator

The Explicit Bucket Histogram Aggregator collect data for the
[Histogram Metric Point](./datamodel.md#histogram)
and reports a histogram with explicit bucket boundaries of seen `Measurements`.
This Aggregator may be configured for custom bucket boundaries, monoticity, and
victlu marked this conversation as resolved.
Show resolved Hide resolved
temporality.

A [Default Aggregator](#DefaultAggregators) MUST be provided.

This Aggregator MUST also report on the arithmetic sum of seen `Measurements`.
The [Histogram Metric Point](./datamodel.md#histogram) requires Sum.

#### Example of In-Memory State

The following are examples of `In-Memory State`:

| Aggregator | In-Memory State |
| --- | --- |
| Sum | Start Time<sup>1</sup><br>Sum (arithmetic sum of measurements) |
| Last Value | Last Timestamp<sup>2</sup><br>Last Value<sup>2</sup> |
| Explicit Bucket Histogram | Start Time<sup>1</sup><br>Count (count of points in population)<br>Sum (arithmetic sum of point values in population)<br>Bucket Counts (count of values falling within configured Boundary Values) |

\[1\]: Start Time is exclusive (e.g. not inclusive) of the provided time.

\[2\]: From latest measurement given, avoiding any time comparison.

### DefaultAggregators

An `Aggregation` `MeasurementProcessor` MUST provide the following **DEFAULT**
`Aggregators` based on the reporting Instrument.

| Instrument Kind | Default Aggregator | Monotonic | Temporality | Notes |
| --- | --- | --- | --- | --- |
| [Counter](./api.md#counter) | [Sum Aggregator](#SumAggregator) | Monotonic | Delta | |
| [Asynchronous Counter](./api.md#asynchronous-counter) | [Sum Aggregator](#SumAggregator) | Monotonic | Cumulative | |
| [UpDownCounter](./api.md#updowncounter) | [Sum Aggregator](#SumAggregator) | Non-Monotonic | Delta | |
| [Asynchrounous UpDownCounter](./api.md#asynchronous-updowncounter) | [Sum Aggregator](#SumAggregator) | Non-Monotonic | Cumulative | |
| [Asynchronous Gauge](./api.md#asynchronous-gauge) | [Last Value Aggregator](#LastValueAggregator) | Non-Monotonic | Cumulative | |
| [Histogram](./api.md#histogram) | [Explicit Bucket Histogram Aggregator](#ExplicitBucketHistogramAggregator) | Monotonic | Delta | Default Bucket Boundaries |

victlu marked this conversation as resolved.
Show resolved Hide resolved
## MetricProcessor

`MetricProcessor` is an interface which allows hooks for [pre-aggregated metrics
Expand Down