-
Notifications
You must be signed in to change notification settings - Fork 436
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: (), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the benefit of this? |
||
} | ||
|
||
impl DeltaTemporalitySelector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 | ||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Add PR #