chore(otel): Push a metric for Loki exporter (#17521)

pull/17031/head^2
Shantanu Alshi 3 weeks ago committed by GitHub
parent 3da9f2cae6
commit 6eab6dc5e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 13
      pkg/loghttp/push/otlp.go
  2. 6
      pkg/loghttp/push/push.go

@ -112,6 +112,9 @@ func otlpToLokiPushRequest(ctx context.Context, ld plog.Logs, userID string, otl
rls := ld.ResourceLogs()
pushRequestsByStream := make(map[string]logproto.Stream, rls.Len())
// Track if request used the Loki OTLP exporter label
var usingLokiExporter bool
for i := 0; i < rls.Len(); i++ {
sls := rls.At(i).ScopeLogs()
res := rls.At(i).Resource()
@ -206,6 +209,11 @@ func otlpToLokiPushRequest(ctx context.Context, ld plog.Logs, userID string, otl
retentionPeriodForUser := streamResolver.RetentionPeriodFor(lbs)
policy := streamResolver.PolicyFor(lbs)
// Check if the stream has the exporter=OTLP label; set flag instead of incrementing per stream
if value, ok := streamLabels[model.LabelName("exporter")]; ok && value == "OTLP" {
usingLokiExporter = true
}
if _, ok := stats.StructuredMetadataBytes[policy]; !ok {
stats.StructuredMetadataBytes[policy] = make(map[time.Duration]int64)
}
@ -369,6 +377,11 @@ func otlpToLokiPushRequest(ctx context.Context, ld plog.Logs, userID string, otl
}
}
// Increment exporter streams metric once per request if seen
if usingLokiExporter {
otlpExporterStreams.WithLabelValues(userID).Inc()
}
return pr
}

@ -57,6 +57,12 @@ var (
Help: "The total number of lines received per tenant",
}, []string{"tenant", "aggregated_metric", "policy"})
otlpExporterStreams = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: constants.Loki,
Name: "distributor_otlp_exporter_streams_total",
Help: "The total number of streams with exporter=OTLP label",
}, []string{"tenant"})
bytesReceivedStats = analytics.NewCounter("distributor_bytes_received")
structuredMetadataBytesReceivedStats = analytics.NewCounter("distributor_structured_metadata_bytes_received")
linesReceivedStats = analytics.NewCounter("distributor_lines_received")

Loading…
Cancel
Save