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 OTLPMetricPipeline builder methods for delta and lowmemory #1057

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions opentelemetry-otlp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Changelog

## Unreleased

### Added
- Added builder methods to configure delta, low-memory temporality for OTLP
Metric pipeline
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Add PR #


## v0.12.0

### Added
Expand Down
72 changes: 72 additions & 0 deletions opentelemetry-otlp/src/metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,56 @@ impl From<TonicExporterBuilder> for MetricsExporterBuilder {
}
}

/// Configure delta temporality for all [InstrumentKind]
///
/// [Temporality::Delta] will be used for Counter, Asynchronous Counter and Histogram
/// [Temporality::Cumulative] will be used for UpDownCounter and Asynchronous UpDownCounter
#[derive(Clone, Default, Debug)]
struct DeltaTemporalitySelector {
pub(crate) _private: (),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of this?

}

impl DeltaTemporalitySelector {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same thing defined in benches currently. Is it worthwhile to consolidate this into a common place?

/// Create a new default temporality selector.
fn new() -> Self {
Self::default()
}
}

impl TemporalitySelector for DeltaTemporalitySelector {
fn temporality(&self, _kind: InstrumentKind) -> Temporality {
Temporality::Delta
}
}

/// Configure low memory temporality for all [InstrumentKind]
///
/// [Temporality::Delta] will be used for Counter and Histogram
/// [Temporality::Cumulative] will be used for UpDownCounter, Asynchronous Counter and Asynchronous UpDownCounter
#[derive(Clone, Default, Debug)]
struct LowMemoryTemporalitySelector {
pub(crate) _private: (),
}

impl LowMemoryTemporalitySelector {
/// Create a new default temporality selector.
fn new() -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: as the lint is pointing out, are you intending this to be pub? or should this be removed as it's not used.

Self::default()
}
}

impl TemporalitySelector for LowMemoryTemporalitySelector {
fn temporality(&self, kind: InstrumentKind) -> Temporality {
match kind {
InstrumentKind::Counter | InstrumentKind::Histogram => Temporality::Delta,
InstrumentKind::UpDownCounter
| InstrumentKind::ObservableCounter
| InstrumentKind::ObservableGauge
| InstrumentKind::ObservableUpDownCounter => Temporality::Cumulative,
}
}
}

/// Pipeline to build OTLP metrics exporter
///
/// Note that currently the OTLP metrics exporter only supports tonic as it's grpc layer and tokio as
Expand Down Expand Up @@ -158,6 +208,28 @@ where
}
}

/// Build with Delta temporality
/// This choses Delta for Counter, Asynchronous Counter and Histogram,
/// and choses Cumulative for UpDownCounter and Asynchronous UpDownCounter
pub fn with_delta_temporality(self) -> Self {
// This implements Delta from : https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md#additional-configuration
OtlpMetricPipeline {
temporality_selector: Some(Box::new(DeltaTemporalitySelector::new())),
..self
}
}

/// Build with "LowMemory" temporality
/// This choses Delta for Synchronous Counter and Histogram,
/// and choses Cumulative for UpDownCounter, Asynchronous Counter and Asynchronous UpDownCounter
pub fn with_low_memory_temporality(self) -> Self {
// This implements LowMemory from : https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/sdk_exporters/otlp.md#additional-configuration
OtlpMetricPipeline {
temporality_selector: Some(Box::new(DeltaTemporalitySelector::new())),
..self
}
}

/// Build with the given aggregation selector
pub fn with_aggregation_selector<T: AggregationSelector + 'static>(self, selector: T) -> Self {
OtlpMetricPipeline {
Expand Down