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 otlpmetric Temporality Preference env var #4287

Merged
merged 9 commits into from
Jul 20, 2023
38 changes: 38 additions & 0 deletions exporters/otlp/otlpmetric/internal/oconf/envconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"time"

"go.opentelemetry.io/otel/exporters/otlp/internal/envconfig"
"go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// DefaultEnvOptionsReader is the default environments reader.
Expand Down Expand Up @@ -96,6 +98,7 @@
WithEnvCompression("METRICS_COMPRESSION", func(c Compression) { opts = append(opts, WithCompression(c)) }),
envconfig.WithDuration("TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }),
envconfig.WithDuration("METRICS_TIMEOUT", func(d time.Duration) { opts = append(opts, WithTimeout(d)) }),
withEnvTemporalityPreference("METRICS_TEMPORALITY_PREFERENCE", func(t metric.TemporalitySelector) { opts = append(opts, WithTemporalitySelector(t)) }),

Check warning on line 101 in exporters/otlp/otlpmetric/internal/oconf/envconfig.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/internal/oconf/envconfig.go#L101

Added line #L101 was not covered by tests
)

return opts
Expand Down Expand Up @@ -148,3 +151,38 @@
}
}
}

func withEnvTemporalityPreference(n string, fn func(metric.TemporalitySelector)) func(e *envconfig.EnvOptionsReader) {
return func(e *envconfig.EnvOptionsReader) {
if s, ok := e.GetEnvValue(n); ok {
switch strings.ToLower(s) {
case "cumulative":
fn(cumulativeTemporality)
case "delta":
fn(deltaTemporality)
case "lowmemory":
fn(lowMemory)

Check warning on line 164 in exporters/otlp/otlpmetric/internal/oconf/envconfig.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/internal/oconf/envconfig.go#L158-L164

Added lines #L158 - L164 were not covered by tests
}
MadVikingGod marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

func cumulativeTemporality(metric.InstrumentKind) metricdata.Temporality {
return metricdata.CumulativeTemporality

Check warning on line 171 in exporters/otlp/otlpmetric/internal/oconf/envconfig.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/internal/oconf/envconfig.go#L170-L171

Added lines #L170 - L171 were not covered by tests
}
MadVikingGod marked this conversation as resolved.
Show resolved Hide resolved
func deltaTemporality(ik metric.InstrumentKind) metricdata.Temporality {
switch ik {
case metric.InstrumentKindCounter, metric.InstrumentKindHistogram, metric.InstrumentKindObservableCounter:
return metricdata.DeltaTemporality
default:
return metricdata.CumulativeTemporality

Check warning on line 178 in exporters/otlp/otlpmetric/internal/oconf/envconfig.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/internal/oconf/envconfig.go#L173-L178

Added lines #L173 - L178 were not covered by tests
}
}
MadVikingGod marked this conversation as resolved.
Show resolved Hide resolved
func lowMemory(ik metric.InstrumentKind) metricdata.Temporality {
switch ik {
case metric.InstrumentKindCounter, metric.InstrumentKindHistogram:
return metricdata.DeltaTemporality
default:
return metricdata.CumulativeTemporality

Check warning on line 186 in exporters/otlp/otlpmetric/internal/oconf/envconfig.go

View check run for this annotation

Codecov / codecov/patch

exporters/otlp/otlpmetric/internal/oconf/envconfig.go#L181-L186

Added lines #L181 - L186 were not covered by tests
}
}
Loading