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
143 changes: 143 additions & 0 deletions specification/metrics/sdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,149 @@ 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 [Aggregated Metrics](./datamodel.md#opentelemetry-protocol-data-model).

The [View](./sdk.md#view) informs the SDK on creation and configuration of
Aggregators. An [Aggregator Name](./sdk.md#aggregator-name) may be used to
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
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>("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. Temporality=Delta, Boundaries=[0, 10, 100]).
Default configuration parameters will be used unless overridden by
optional configuration parameters.

An `Aggregator` has a means to "update" its internal state with incoming
Instrument [Measurement](./api.md#measurement) data.

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

**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 used to select Aggregator by Instrument Kind.
See [Default Aggregators](./sdk.md#default-aggregators).

\[2\]: The name "None" is used to specify no Aggregator or
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 uses the Instrument Kind (e.g. at View registration)
to select the correct Aggregator and default configuration parameters.

| Instrument Kind | Default Aggregator | Default Configuration Parameters |
| --- | --- | --- |
| [Counter](./api.md#counter) | [Sum Aggregator](./sdk.md#sum-aggregator) | Temporality = Delta<br>SumType = Monotonic<sup>2</sup> |
jsuereth marked this conversation as resolved.
Show resolved Hide resolved
| [UpDownCounter](./api.md#updowncounter) | [Sum Aggregator](./sdk.md#sum-aggregator) | Temporality = Delta<br>SumType = Non-Monotonic<sup>2</sup> |
| [Asynchronous Counter](./api.md#asynchronous-counter) | [Sum Aggregator](./sdk.md#sum-aggregator) | Temporality = Cumulative<br>SumType = Monotonic<sup>2</sup> |
| [Asynchrounous UpDownCounter](./api.md#asynchronous-updowncounter) | [Sum Aggregator](./sdk.md#sum-aggregator) | Temporality = Cumulative<br>SumType = Non-Monotonic<sup>2</sup> |
| [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) | Default<sup>1</sup> |

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

\[2\]: **TBD**: See [PR#320](https:/open-telemetry/opentelemetry-proto/pull/320).

### Last Value Aggregator

The Last Value Aggregator collects data for the
[Gauge Metric Point](./datamodel.md#gauge).

This Aggregator does not have any configuration parameters.

This Aggregator collects:

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

### Sum Aggregator

The Sum Aggregator collects data for the [Sum Metric Point](./datamodel.md#sums).

This Aggregator honors the following configuration parameters:

| Key | Value | Default Value | Description |
| --- | --- | --- | --- |
| SumType<sup>2</sup> | Monotonic, Non-Monotonic, Other<sup>2</sup> | Depends<sup>1</sup> | See SumType<sup>2</sup> |
| 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\]: **TBD**: See [PR#320](https:/open-telemetry/opentelemetry-proto/pull/320).

This Aggregator collects:

- 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 collects data for the
[Histogram Metric Point](./datamodel.md#histogram). It supports a set of
explicit boundary values for histogram bucketing.

This Aggregator honors the following configuration parameters:

| Key | Value | Default Value | 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\[\] | (-&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;) | Array of increasing values representing explicit bucket boundary values. |

\[1\]: Language implementations may choose the best strategy for handling errors. (i.e. Log, Discard, etc...)

This Aggregator collects:

- 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