Skip to content

Commit

Permalink
[config] Implement temporality preference option (#10796)
Browse files Browse the repository at this point in the history
#### Description
adds temporality preference option for internal telemetry exported via
OTLP

#### Link to tracking issue
(partly) fixes #10745

#### Testing
unit tests

#### Documentation
Feature is already documented, but not implemented yet.

---------

Co-authored-by: Alex Boten <[email protected]>
  • Loading branch information
pirgeo and codeboten authored Aug 6, 2024
1 parent 6cf71b8 commit 41fa6ff
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 21 deletions.
25 changes: 25 additions & 0 deletions .chloggen/int-telemetry-otlp-options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: service

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Implement the `temporality_preference` setting for internal telemetry exported via OTLP"

# One or more tracking issues or pull requests related to the change
issues: [ 10745 ]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [ user ]
51 changes: 51 additions & 0 deletions service/internal/proctelemetry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
"go.opentelemetry.io/otel/sdk/instrumentation"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
"go.opentelemetry.io/otel/sdk/metric/metricdata"
"go.opentelemetry.io/otel/sdk/resource"

"go.opentelemetry.io/collector/processor/processorhelper"
Expand Down Expand Up @@ -252,6 +253,18 @@ func initOTLPgRPCExporter(ctx context.Context, otlpConfig *config.OTLPMetric) (s
if len(otlpConfig.Headers) > 0 {
opts = append(opts, otlpmetricgrpc.WithHeaders(otlpConfig.Headers))
}
if otlpConfig.TemporalityPreference != nil {
switch *otlpConfig.TemporalityPreference {
case "delta":
opts = append(opts, otlpmetricgrpc.WithTemporalitySelector(temporalityPreferenceDelta))
case "cumulative":
opts = append(opts, otlpmetricgrpc.WithTemporalitySelector(temporalityPreferenceCumulative))
case "lowmemory":
opts = append(opts, otlpmetricgrpc.WithTemporalitySelector(temporalityPreferenceLowMemory))
default:
return nil, fmt.Errorf("unsupported temporality preference %q", *otlpConfig.TemporalityPreference)
}
}

return otlpmetricgrpc.New(ctx, opts...)
}
Expand Down Expand Up @@ -289,6 +302,44 @@ func initOTLPHTTPExporter(ctx context.Context, otlpConfig *config.OTLPMetric) (s
if len(otlpConfig.Headers) > 0 {
opts = append(opts, otlpmetrichttp.WithHeaders(otlpConfig.Headers))
}
if otlpConfig.TemporalityPreference != nil {
switch *otlpConfig.TemporalityPreference {
case "delta":
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(temporalityPreferenceDelta))
case "cumulative":
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(temporalityPreferenceCumulative))
case "lowmemory":
opts = append(opts, otlpmetrichttp.WithTemporalitySelector(temporalityPreferenceLowMemory))
default:
return nil, fmt.Errorf("unsupported temporality preference %q", *otlpConfig.TemporalityPreference)
}
}

return otlpmetrichttp.New(ctx, opts...)
}

func temporalityPreferenceCumulative(_ sdkmetric.InstrumentKind) metricdata.Temporality {
return metricdata.CumulativeTemporality
}

func temporalityPreferenceDelta(ik sdkmetric.InstrumentKind) metricdata.Temporality {
switch ik {
case sdkmetric.InstrumentKindCounter, sdkmetric.InstrumentKindObservableCounter, sdkmetric.InstrumentKindHistogram:
return metricdata.DeltaTemporality
case sdkmetric.InstrumentKindObservableUpDownCounter, sdkmetric.InstrumentKindUpDownCounter:
return metricdata.CumulativeTemporality
default:
return metricdata.DeltaTemporality
}
}

func temporalityPreferenceLowMemory(ik sdkmetric.InstrumentKind) metricdata.Temporality {
switch ik {
case sdkmetric.InstrumentKindCounter, sdkmetric.InstrumentKindHistogram:
return metricdata.DeltaTemporality
case sdkmetric.InstrumentKindObservableCounter, sdkmetric.InstrumentKindObservableUpDownCounter, sdkmetric.InstrumentKindUpDownCounter:
return metricdata.CumulativeTemporality
default:
return metricdata.DeltaTemporality
}
}
Loading

0 comments on commit 41fa6ff

Please sign in to comment.