Skip to content

Commit 205e976

Browse files
authored
Add predicate to MetricReader and MetricProducer (open-telemetry#3566)
1 parent 9ad03b4 commit 205e976

File tree

3 files changed

+96
-5
lines changed

3 files changed

+96
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ release.
4242

4343
### Metrics
4444

45+
- Define experimental MetricFilter as a mechanism to filter collected metrics by the MetricReader
46+
([#3566](https://github.com/open-telemetry/opentelemetry-specification/pull/3566))
4547
- Add optional configuration for Prometheus exporters to promote resource attributes to metric attributes
4648
([#3761](https://github.com/open-telemetry/opentelemetry-specification/pull/3761))
4749
- Clarifications and flexibility in Exemplar speicification.

spec-compliance-matrix.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ formats is required. Implementing more than one format is optional.
212212
| The metrics SDK provides an `AlignedHistogramBucketExemplarReservoir` that is used by default for `ExplicitBucketHistogram` aggregation. | | | + | | - | | | | | | - | |
213213
| The metrics SDK provides an `ExemplarFilter` interface or extension point. | X | | - | | - | | | + | | | - | |
214214
| An `ExemplarFilter` has access to the measurement value, attributes, `Context` and timestamp. | X | | - | | - | | | + | | | - | |
215+
| A metric Producer accepts an optional metric Filter | | | | | | | | | | | | |
216+
| The metric Reader implementation supports registering metric Filter and passing them its registered metric Producers | | | | | | | | | | | | |
217+
| The metric SDK's metric Producer implementations uses the metric Filter | | | | | | | | | | | | |
215218

216219
## Logs
217220

specification/metrics/sdk.md

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ linkTitle: SDK
7474
* [Pull Metric Exporter](#pull-metric-exporter)
7575
- [MetricProducer](#metricproducer)
7676
* [Interface Definition](#interface-definition-1)
77-
+ [Produce() batch](#produce-batch)
77+
+ [Produce batch](#produce-batch)
78+
- [MetricFilter](#metricfilter)
79+
* [Interface Definition](#interface-definition-2)
80+
+ [TestMetric](#testmetric)
81+
+ [TestAttributes](#testattributes)
7882
- [Defaults and configuration](#defaults-and-configuration)
7983
- [Numerical limits handling](#numerical-limits-handling)
8084
- [Compatibility requirements](#compatibility-requirements)
@@ -1113,8 +1117,12 @@ SHOULD provide at least the following:
11131117
* The default output `aggregation` (optional), a function of instrument kind. If not configured, the [default aggregation](#default-aggregation) SHOULD be used.
11141118
* The default output `temporality` (optional), a function of instrument kind. If not configured, the Cumulative temporality SHOULD be used.
11151119
* **Status**: [Experimental](../document-status.md) - The default aggregation cardinality limit to use, a function of instrument kind. If not configured, a default value of 2000 SHOULD be used.
1120+
* **Status**: [Experimental](../document-status.md) - The [MetricFilter](#metricfilter) to apply to metrics and attributes during `MetricReader#Collect`.
11161121
* Zero of more [MetricProducer](#metricproducer)s (optional) to collect metrics from in addition to metrics from the SDK.
11171122

1123+
**Status**: [Experimental](../document-status.md) - A `MetricReader` SHOULD provide the [MetricFilter](#metricfilter) to the SDK or registered [MetricProducer](#metricproducer)(s)
1124+
when calling the `Produce` operation.
1125+
11181126
The [MetricReader.Collect](#collect) method allows general-purpose
11191127
`MetricExporter` instances to explicitly initiate collection, commonly
11201128
used with pull-based metrics collection. A common implementation of
@@ -1502,10 +1510,10 @@ modeled to interact with other components in the SDK:
15021510

15031511
## MetricProducer
15041512

1505-
**Status**: [Stable](../document-status.md)
1513+
**Status**: [Stable](../document-status.md) except where otherwise specified
15061514

15071515
`MetricProducer` defines the interface which bridges to third-party metric
1508-
sources MUST implement so they can be plugged into an OpenTelemetry
1516+
sources MUST implement, so they can be plugged into an OpenTelemetry
15091517
[MetricReader](#metricreader) as a source of aggregated metric data. The SDK's
15101518
in-memory state MAY implement the `MetricProducer` interface for convenience.
15111519

@@ -1535,10 +1543,14 @@ bridge pre-processed data.
15351543

15361544
A `MetricProducer` MUST support the following functions:
15371545

1538-
#### Produce() batch
1546+
#### Produce batch
15391547

15401548
`Produce` provides metrics from the MetricProducer to the caller. `Produce`
1541-
MUST return a batch of [Metric points](./data-model.md#metric-points).
1549+
MUST return a batch of [Metric points](./data-model.md#metric-points), filtered by the optional
1550+
`metricFilter` parameter. Implementation SHOULD use the filter as early as
1551+
possible to gain as much performance gain possible (memory allocation,
1552+
internal metric fetching, etc).
1553+
15421554
If the batch of [Metric points](./data-model.md#metric-points) includes
15431555
resource information, `Produce` SHOULD require a resource as a parameter.
15441556
`Produce` does not have any other required parameters, however, [OpenTelemetry
@@ -1555,6 +1567,80 @@ If a batch of [Metric points](./data-model.md#metric-points) can include
15551567
`Produce` SHOULD include a single InstrumentationScope which identifies the
15561568
`MetricProducer`.
15571569

1570+
**Parameters:**
1571+
1572+
**Status**: [Experimental](../document-status.md) `metricFilter`: An optional [MetricFilter](#metricfilter).
1573+
1574+
## MetricFilter
1575+
1576+
**Status**: [Experimental](../document-status.md)
1577+
1578+
`MetricFilter` defines the interface which enables the [MetricReader](#metricreader)'s
1579+
registered [MetricProducers](#metricproducer) or the SDK's [MetricProducer](#metricproducer) to filter aggregated data points
1580+
([Metric points](./data-model.md#metric-points)) inside its `Produce` operation.
1581+
The filtering is done at the [MetricProducer](#metricproducer) for performance reasons.
1582+
1583+
The `MetricFilter` allows filtering an entire metric stream - dropping or allowing all its attribute sets -
1584+
by its `TestMetric` operation, which accepts the metric stream information
1585+
(scope, name, kind and unit) and returns an enumeration: `Accept`, `Drop`
1586+
or `Allow_Partial`. If the latter returned, the `TestAttributes` operation
1587+
is to be called per attribute set of that metric stream, returning an enumeration
1588+
determining if the data point for that (metric stream, attributes) pair is to be
1589+
allowed in the result of the [MetricProducer](#metricproducer) `Produce` operation.
1590+
1591+
### Interface Definition
1592+
1593+
A `MetricFilter` MUST support the following functions:
1594+
1595+
#### TestMetric
1596+
1597+
This operation is called once for every metric stream, in each [MetricProducer](#metricproducer) `Produce`
1598+
operation.
1599+
1600+
**Parameters:**
1601+
1602+
- `instrumentationScope`: the metric stream instrumentation scope
1603+
- `name`: the name of the metric stream
1604+
- `kind`: the metric stream [kind](./data-model.md#point-kinds)
1605+
- `unit`: the metric stream unit
1606+
1607+
Returns: `MetricFilterResult`
1608+
1609+
`MetricFilterResult` is one of:
1610+
1611+
* `Accept` - All attributes of the given metric stream are allowed (not to be filtered).
1612+
This provides a "short-circuit" as there is no need to call `TestAttributes` operation
1613+
for each attribute set.
1614+
* `Drop` - All attributes of the given metric stream are NOT allowed (filtered out - dropped).
1615+
This provides a "short-circuit" as there is no need to call `TestAttributes` operation
1616+
for each attribute set, and no need to collect those data points be it synchronous or asynchronous:
1617+
e.g. the callback for this given instrument does not need to be invoked.
1618+
* `Accept_Partial` - Some attributes are allowed and some aren't, hence `TestAttributes`
1619+
operation must be called for each attribute set of that instrument.
1620+
1621+
#### TestAttributes
1622+
1623+
An operation which determines for a given metric stream and attribute set if it should be allowed
1624+
or filtered out.
1625+
1626+
This operation should only be called if `TestMetric` operation returned `Accept_Partial` for
1627+
the given metric stream arguments (`instrumentationScope`, `name`, `kind`, `unit`).
1628+
1629+
**Parameters:**
1630+
1631+
- `instrumentationScope`: the metric stream instrumentation scope
1632+
- `name`: the name of the metric stream
1633+
- `kind`: the metric stream kind
1634+
- `unit`: the metric stream unit
1635+
- `attributes`: the attributes
1636+
1637+
Returns: `AttributesFilterResult`
1638+
1639+
`AttributesFilterResult` is one of:
1640+
1641+
* `Accept` - This given `attributes` are allowed (not to be filtered).
1642+
* `Drop` - This given `attributes` are NOT allowed (filtered out - dropped).
1643+
15581644
## Defaults and configuration
15591645

15601646
The SDK MUST provide configuration according to the [SDK environment

0 commit comments

Comments
 (0)