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 Metrics Spec. #1842

Merged
merged 17 commits into from
Aug 19, 2021
151 changes: 151 additions & 0 deletions specification/metrics/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,157 @@ meter_provider
.set_exporter(ConsoleExporter())
```

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

An `Aggregator` computes incoming Instrument [Measurements](./api.md#measurement)
into [Pre-Aggregated Metrics](./datamodel.md#opentelemetry-protocol-data-model).
victlu marked this conversation as resolved.
Show resolved Hide resolved

The [View](./sdk.md#view) informs the SDK on creation and configuration of
Aggregators. An [Aggregator Name](./sdk.md#aggregator-name) may be use to
victlu marked this conversation as resolved.
Show resolved Hide resolved
refer to an Aggregator and configuration.

e.g. The View specifies the string name of an Aggregator (i.e. "Histogram")
and an optional list of configuration parameter overrides.

```c#
// Use default Histogram
meter_provider
victlu marked this conversation as resolved.
Show resolved Hide resolved
.add_view(
instrument_name = "X",
aggregator = "Histogram");

// Use Histogram with custom boundaries and monotonic values
meter_provider
.add_view(
instrument_name = "X",
aggregator = "Histogram",
victlu marked this conversation as resolved.
Show resolved Hide resolved
aggregator_params = new KeyValuePair<string, object>[]
{
new KeyValuePair<string, object>("Monotonic", true),
victlu marked this conversation as resolved.
Show resolved Hide resolved
new KeyValuePair<string, object>("Boundaries", new double[] { 0.0, 10.0, 100.0 }),
});
```

The [View](./sdk.md#view) informs the SDK to provide correct
Instrument [Measurements](./api.md#measurement) to the correct Aggregators.

An `Aggregator` is created with optional configuration parameters
(i.e. Monotonic=true, Boundaries=[0, 10, 100]).
Default configuration parameters will be use unless overridden by
victlu marked this conversation as resolved.
Show resolved Hide resolved
optional configuration parameters.

An `Aggregator` has a means to "update" with incoming Instrument
victlu marked this conversation as resolved.
Show resolved Hide resolved
[Measurement](./api.md#measurement) data.

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

e.g. When "collect" is acted on a Sum Aggregator, configured for delta
victlu marked this conversation as resolved.
Show resolved Hide resolved
temporality, it will return a delta metric and reset its internal
counts and time-period window. A downstream Exporter, supporting only
cumulative temporality, may choose to 1. drop the delta metric
OR 2. support [Delta to Cumulative](./datamodel.md#sums-delta-to-cumulative)
conversion.

**TBD**:
The [View](./sdk.md#view) may inform an `Aggregator` to collect
[Examplars](./datamodel.md#exemplars).
victlu marked this conversation as resolved.
Show resolved Hide resolved

### Aggregator Name

The [View](./sdk.md#view) can refer to the following Aggregator by name.

| Name | Aggregator | Configuration Parameters |
| --- | --- | --- |
| Default<sup>1</sup> | Depends<sup>3</sup> | Depends<sup>3</sup> |
| None<sup>2</sup> | - | - |
| Sum | [Sum Aggregator](./sdk.md#sum-aggregator) | Depends<sup>3</sup> |
| Gauge | [Last Value Aggregator](./sdk.md#last-value-aggregator) | - |
| Histogram | [Explicit Bucket Histogram Aggregator](./sdk.md#explicit-bucket-histogram-aggregator) | Default |
jsuereth marked this conversation as resolved.
Show resolved Hide resolved

\[1\]: The name "Default" is use to select Aggregator by Instrument Kind.
victlu marked this conversation as resolved.
Show resolved Hide resolved
See [Default Aggregators](./sdk.md#default-aggregators).

\[2\]: The name "None" is use to specify no Aggregator or
victlu marked this conversation as resolved.
Show resolved Hide resolved
a "virtual" Aggregator which ignores all measurements.

\[3\]: Depends on the Instrument Kind. See [Default Aggregators](./sdk.md#default-aggregators).

### Default Aggregators

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

The "Default" Aggregator use the Instrument Kind (e.g. at View registration)
victlu marked this conversation as resolved.
Show resolved Hide resolved
to select the correct Aggregator and default configuration parameters.

| Instrument Kind | Default Aggregator | Monotonic | Temporality | Boundaries |
| --- | --- | --- | --- | --- |
| [Counter](./api.md#counter) | [Sum Aggregator](./sdk.md#sum-aggregator) | true | Delta | - |
| [UpDownCounter](./api.md#updowncounter) | [Sum Aggregator](./sdk.md#sum-aggregator) | false | Delta | - |
| [Asynchronous Counter](./api.md#asynchronous-counter) | [Sum Aggregator](./sdk.md#sum-aggregator) | true | Cumulative | - |
| [Asynchrounous UpDownCounter](./api.md#asynchronous-updowncounter) | [Sum Aggregator](./sdk.md#sum-aggregator) | false | Cumulative | - |
| [Asynchronous Gauge](./api.md#asynchronous-gauge) | [Last Value Aggregator](./sdk.md#last-value-aggregator) | - | - | - |
| [Histogram](./api.md#histogram) | [Explicit Bucket Histogram Aggregator](./sdk.md#explicit-bucket-histogram-aggregator) | true | Delta | Default<sup>1</sup> |

\[1\]: See Default Bucket Boundaries in [Explicit Bucket Histogram Aggregator](./sdk.md#explicit-bucket-histogram-aggregator).

### Last Value Aggregator

The Last Value Aggregator collect data for the
victlu marked this conversation as resolved.
Show resolved Hide resolved
[Gauge Metric Point](./datamodel.md#gauge).

This Aggregator does not have any configuration parameter keys.
victlu marked this conversation as resolved.
Show resolved Hide resolved

This Aggregator reports on:
victlu marked this conversation as resolved.
Show resolved Hide resolved

- The last `Measurement`.
victlu marked this conversation as resolved.
Show resolved Hide resolved

### Sum Aggregator

The Sum Aggregator collect data for the [Sum Metric Point](./datamodel.md#sums).
victlu marked this conversation as resolved.
Show resolved Hide resolved

This Aggregator honors the following configuration parameter keys:

| Key | Value | Default | Description |
| --- | --- | --- | --- |
| Monotonic | boolean | Depends<sup>1</sup> | if true, non-positive values are treated as errors<sup>2</sup>. |
victlu marked this conversation as resolved.
Show resolved Hide resolved
| Temporality | Delta, Cummulative | Depends<sup>1</sup> | See [Temporality](./datamodel.md#temporality). |

\[1\]: Depends on the Instrument Kind. See [Default Aggregators](./sdk.md#default-aggregators).

\[2\]: Language implementation may choose best strategy for handling errors. (i.e. Logged, Discard, etc...)

This Aggregator reports on:
victlu marked this conversation as resolved.
Show resolved Hide resolved

- The arithmetic sum of `Measurement` values.
victlu marked this conversation as resolved.
Show resolved Hide resolved

### Explicit Bucket Histogram Aggregator

The Explicit Bucket Histogram Aggregator collect data for the
victlu marked this conversation as resolved.
Show resolved Hide resolved
[Histogram Metric Point](./datamodel.md#histogram). It supports a set of
explicit boundary values for histogram bucketing.

This Aggregator honors the following configuration parameter keys:

| Key | Value | Default | Description |
| --- | --- | --- | --- |
| Monotonic | boolean | true | if true, non-positive values are treated as errors<sup>1</sup>. |
victlu marked this conversation as resolved.
Show resolved Hide resolved
| Temporality | Delta, Cummulative | Delta | See [Temporality](./datamodel.md#temporality). |
| Boundaries | double\[\] | Default<sup>2</sup> | Array of increasing values representing explicit bucket boundary values. |

\[1\]: Language implementation may choose best strategy for handling errors. (i.e. Logged, Discard, etc...)
victlu marked this conversation as resolved.
Show resolved Hide resolved

\[2\]: Default Bucket Boundaries: (-&infin;, 0], (0, 5.0], (5.0, 10.0], (10.0, 25.0], (25.0, 50.0], (50.0, 75.0], (75.0, 100.0], (100.0, 250.0], (250.0, 500.0], (500.0, 1000.0], (1000.0, +&infin;)

This Aggregator reports on:
victlu marked this conversation as resolved.
Show resolved Hide resolved

- Count of `Measurement` values falling within explicit bucket boundaries.
- Arithmetic sum of `Measurement` values in population.

## MeasurementProcessor

`MeasurementProcessor` is an interface which allows hooks when a
Expand Down