Skip to content

Commit 2925e8e

Browse files
committed
OTLP: Convert start timestamps to Mimir created timestamps
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
1 parent 4658643 commit 2925e8e

File tree

21 files changed

+169
-74
lines changed

21 files changed

+169
-74
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
* [ENHANCEMENT] Update runtime configuration to read gzip-compressed files with `.gz` extension. #9074
7777
* [ENHANCEMENT] Ingester: add `cortex_lifecycler_read_only` metric which is set to 1 when ingester's lifecycler is set to read-only mode. #9095
7878
* [ENHANCEMENT] Add a new field, `encode_time_seconds` to query stats log messages, to record the amount of time it takes the query-frontend to encode a response. This does not include any serialization time for downstream components. #9062
79+
* [ENHANCEMENT] OTLP: If the flag `-distributor.otel-created-timestamp-zero-ingestion-enabled` is true, OTel start timestamps are converted to Prometheus zero samples to mark series start. #9131
7980
* [BUGFIX] Ruler: add support for draining any outstanding alert notifications before shutting down. This can be enabled with the `-ruler.drain-notification-queue-on-shutdown=true` CLI flag. #8346
8081
* [BUGFIX] Query-frontend: fix `-querier.max-query-lookback` enforcement when `-compactor.blocks-retention-period` is not set, and viceversa. #8388
8182
* [BUGFIX] Ingester: fix sporadic `not found` error causing an internal server error if label names are queried with matchers during head compaction. #8391

cmd/mimir/config-descriptor.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4699,6 +4699,17 @@
46994699
"fieldType": "boolean",
47004700
"fieldCategory": "advanced"
47014701
},
4702+
{
4703+
"kind": "field",
4704+
"name": "otel_created_timestamp_zero_ingestion_enabled",
4705+
"required": false,
4706+
"desc": "Whether to enable translation of OTel start timestamps to Prometheus zero samples in the OTLP endpoint.",
4707+
"fieldValue": null,
4708+
"fieldDefaultValue": false,
4709+
"fieldFlag": "distributor.otel-created-timestamp-zero-ingestion-enabled",
4710+
"fieldType": "boolean",
4711+
"fieldCategory": "experimental"
4712+
},
47024713
{
47034714
"kind": "field",
47044715
"name": "ingest_storage_read_consistency",

cmd/mimir/help-all.txt.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,8 @@ Usage of ./cmd/mimir/mimir:
12151215
[experimental] Max size of the pooled buffers used for marshaling write requests. If 0, no max size is enforced.
12161216
-distributor.metric-relabeling-enabled
12171217
[experimental] Enable metric relabeling for the tenant. This configuration option can be used to forcefully disable metric relabeling on a per-tenant basis. (default true)
1218+
-distributor.otel-created-timestamp-zero-ingestion-enabled
1219+
[experimental] Whether to enable translation of OTel start timestamps to Prometheus zero samples in the OTLP endpoint.
12181220
-distributor.otel-metric-suffixes-enabled
12191221
Whether to enable automatic suffixes to names of metrics ingested through OTLP.
12201222
-distributor.remote-timeout duration

docs/sources/mimir/configure/about-versioning.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ The following features are currently experimental:
8181
- `-distributor.max-request-pool-buffer-size`
8282
- Enable direct translation from OTLP write requests to Mimir equivalents
8383
- `-distributor.direct-otlp-translation-enabled`
84+
- Enable conversion of OTel start timestamps to Prometheus zero samples to mark series start
85+
- `-distributor.otel-created-timestamp-zero-ingestion-enabled`
8486
- Hash ring
8587
- Disabling ring heartbeat timeouts
8688
- `-distributor.ring.heartbeat-timeout=0`

docs/sources/mimir/configure/configuration-parameters/index.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3707,6 +3707,11 @@ The `limits` block configures default and per-tenant limits imposed by component
37073707
# CLI flag: -distributor.otel-metric-suffixes-enabled
37083708
[otel_metric_suffixes_enabled: <boolean> | default = false]
37093709
3710+
# (experimental) Whether to enable translation of OTel start timestamps to
3711+
# Prometheus zero samples in the OTLP endpoint.
3712+
# CLI flag: -distributor.otel-created-timestamp-zero-ingestion-enabled
3713+
[otel_created_timestamp_zero_ingestion_enabled: <boolean> | default = false]
3714+
37103715
# (experimental) The default consistency level to enforce for queries when using
37113716
# the ingest storage. Supports values: strong, eventual.
37123717
# CLI flag: -ingest-storage.read-consistency

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ require (
278278
)
279279

280280
// Using a fork of Prometheus with Mimir-specific changes.
281-
replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20240826084742-bf5bf35a1b4d
281+
replace github.com/prometheus/prometheus => github.com/grafana/mimir-prometheus v0.0.0-20240829153637-b4b389431da8
282282

283283
// Replace memberlist with our fork which includes some fixes that haven't been
284284
// merged upstream yet:

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56 h1:X8IKQ0wu40wp
524524
github.com/grafana/gomemcache v0.0.0-20240229205252-cd6a66d6fb56/go.mod h1:PGk3RjYHpxMM8HFPhKKo+vve3DdlPUELZLSDEFehPuU=
525525
github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe h1:yIXAAbLswn7VNWBIvM71O2QsgfgW9fRXZNR0DXe6pDU=
526526
github.com/grafana/memberlist v0.3.1-0.20220714140823-09ffed8adbbe/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
527-
github.com/grafana/mimir-prometheus v0.0.0-20240826084742-bf5bf35a1b4d h1:wnVWb4mZzwcBKdzo2Tdazhq+ZNx5MZ93lcoraH1fLms=
528-
github.com/grafana/mimir-prometheus v0.0.0-20240826084742-bf5bf35a1b4d/go.mod h1:cNDAD0ooSyLfNtakmnGbChNg7JPYmKsRn7CQ01Rpu2E=
527+
github.com/grafana/mimir-prometheus v0.0.0-20240829153637-b4b389431da8 h1:dTCK21S9xnvQs8pOL9F29dh4nONuG0DL7qQh0MXwWZA=
528+
github.com/grafana/mimir-prometheus v0.0.0-20240829153637-b4b389431da8/go.mod h1:cNDAD0ooSyLfNtakmnGbChNg7JPYmKsRn7CQ01Rpu2E=
529529
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956 h1:em1oddjXL8c1tL0iFdtVtPloq2hRPen2MJQKoAWpxu0=
530530
github.com/grafana/opentracing-contrib-go-stdlib v0.0.0-20230509071955-f410e79da956/go.mod h1:qtI1ogk+2JhVPIXVc6q+NHziSmy2W5GbdQZFUHADCBU=
531531
github.com/grafana/prometheus-alertmanager v0.25.1-0.20240625192351-66ec17e3aa45 h1:AJKOtDKAOg8XNFnIZSmqqqutoTSxVlRs6vekL2p2KEY=

pkg/api/handlers.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func NewQuerierHandler(
250250

251251
const (
252252
remoteWriteEnabled = false
253-
oltpEnabled = false
253+
otlpEnabled = false
254254
)
255255

256256
api := v1.NewAPI(
@@ -281,7 +281,8 @@ func NewQuerierHandler(
281281
nil,
282282
remoteWriteEnabled,
283283
nil,
284-
oltpEnabled,
284+
otlpEnabled,
285+
true,
285286
)
286287

287288
api.InstallCodec(protobufCodec{})

pkg/distributor/otel.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949

5050
type OTLPHandlerLimits interface {
5151
OTelMetricSuffixesEnabled(id string) bool
52+
OTelCreatedTimestampZeroIngestionEnabled(id string) bool
5253
}
5354

5455
// OTLPHandler is an http.Handler accepting OTLP write requests.
@@ -162,18 +163,19 @@ func OTLPHandler(
162163
return err
163164
}
164165
addSuffixes := limits.OTelMetricSuffixesEnabled(tenantID)
166+
enableCTZeroIngestion := limits.OTelCreatedTimestampZeroIngestionEnabled(tenantID)
165167

166168
pushMetrics.IncOTLPRequest(tenantID)
167169
pushMetrics.ObserveUncompressedBodySize(tenantID, float64(uncompressedBodySize))
168170

169171
var metrics []mimirpb.PreallocTimeseries
170172
if directTranslation {
171-
metrics, err = otelMetricsToTimeseries(ctx, tenantID, addSuffixes, discardedDueToOtelParseError, logger, otlpReq.Metrics())
173+
metrics, err = otelMetricsToTimeseries(ctx, tenantID, addSuffixes, enableCTZeroIngestion, discardedDueToOtelParseError, logger, otlpReq.Metrics())
172174
if err != nil {
173175
return err
174176
}
175177
} else {
176-
metrics, err = otelMetricsToTimeseriesOld(ctx, tenantID, addSuffixes, discardedDueToOtelParseError, logger, otlpReq.Metrics())
178+
metrics, err = otelMetricsToTimeseriesOld(ctx, tenantID, addSuffixes, enableCTZeroIngestion, discardedDueToOtelParseError, logger, otlpReq.Metrics())
177179
if err != nil {
178180
return err
179181
}
@@ -401,10 +403,11 @@ func otelMetricsToMetadata(addSuffixes bool, md pmetric.Metrics) []*mimirpb.Metr
401403
return metadata
402404
}
403405

404-
func otelMetricsToTimeseries(ctx context.Context, tenantID string, addSuffixes bool, discardedDueToOtelParseError *prometheus.CounterVec, logger log.Logger, md pmetric.Metrics) ([]mimirpb.PreallocTimeseries, error) {
406+
func otelMetricsToTimeseries(ctx context.Context, tenantID string, addSuffixes, enableCTZeroIngestion bool, discardedDueToOtelParseError *prometheus.CounterVec, logger log.Logger, md pmetric.Metrics) ([]mimirpb.PreallocTimeseries, error) {
405407
converter := otlp.NewMimirConverter()
406408
errs := converter.FromMetrics(ctx, md, otlp.Settings{
407-
AddMetricSuffixes: addSuffixes,
409+
AddMetricSuffixes: addSuffixes,
410+
EnableCreatedTimestampZeroIngestion: enableCTZeroIngestion,
408411
})
409412
mimirTS := converter.TimeSeries()
410413
if errs != nil {
@@ -427,10 +430,11 @@ func otelMetricsToTimeseries(ctx context.Context, tenantID string, addSuffixes b
427430
}
428431

429432
// Old, less efficient, version of otelMetricsToTimeseries.
430-
func otelMetricsToTimeseriesOld(ctx context.Context, tenantID string, addSuffixes bool, discardedDueToOtelParseError *prometheus.CounterVec, logger log.Logger, md pmetric.Metrics) ([]mimirpb.PreallocTimeseries, error) {
433+
func otelMetricsToTimeseriesOld(ctx context.Context, tenantID string, addSuffixes, enableCTZeroIngestion bool, discardedDueToOtelParseError *prometheus.CounterVec, logger log.Logger, md pmetric.Metrics) ([]mimirpb.PreallocTimeseries, error) {
431434
converter := prometheusremotewrite.NewPrometheusConverter()
432435
errs := converter.FromMetrics(ctx, md, prometheusremotewrite.Settings{
433-
AddMetricSuffixes: addSuffixes,
436+
AddMetricSuffixes: addSuffixes,
437+
EnableCreatedTimestampZeroIngestion: enableCTZeroIngestion,
434438
})
435439
promTS := converter.TimeSeries()
436440
if errs != nil {

pkg/distributor/otlp/helper_generated.go

Lines changed: 32 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)