@@ -340,26 +340,27 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
340
340
metric , exists := metricCache [metricKey ]
341
341
// If the metric does not exist, we create an empty metric and add it to the cache.
342
342
if ! exists {
343
- metric = scope .Metrics ().AppendEmpty ()
344
- metric .SetName (metricName )
345
- metric .SetUnit (unit )
346
- metric .SetDescription (description )
347
-
348
343
switch ts .Metadata .Type {
349
344
case writev2 .Metadata_METRIC_TYPE_GAUGE :
345
+ metric = setMetric (scope , metricName , unit , description )
350
346
metric .SetEmptyGauge ()
351
347
case writev2 .Metadata_METRIC_TYPE_COUNTER :
348
+ metric = setMetric (scope , metricName , unit , description )
352
349
sum := metric .SetEmptySum ()
353
350
sum .SetIsMonotonic (true )
354
351
sum .SetAggregationTemporality (pmetric .AggregationTemporalityCumulative )
355
352
case writev2 .Metadata_METRIC_TYPE_HISTOGRAM :
356
353
// Histograms that comes with samples are considered as classic histograms and are not supported.
357
- if len (ts .Samples ) = = 0 {
358
- hist := metric . SetEmptyExponentialHistogram ()
359
- hist . SetAggregationTemporality ( pmetric . AggregationTemporalityCumulative )
354
+ if len (ts .Samples ) ! = 0 {
355
+ // Drop classic histogram series as we will not handle them.
356
+ continue
360
357
}
358
+ metric = setMetric (scope , metricName , unit , description )
359
+ hist := metric .SetEmptyExponentialHistogram ()
360
+ hist .SetAggregationTemporality (pmetric .AggregationTemporalityCumulative )
361
361
case writev2 .Metadata_METRIC_TYPE_SUMMARY :
362
- metric .SetEmptySummary ()
362
+ // Drop summary series as we will not handle them.
363
+ continue
363
364
}
364
365
365
366
metricCache [metricKey ] = metric
@@ -378,12 +379,14 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
378
379
case writev2 .Metadata_METRIC_TYPE_COUNTER :
379
380
addNumberDatapoints (metric .Sum ().DataPoints (), ls , ts , & stats )
380
381
case writev2 .Metadata_METRIC_TYPE_HISTOGRAM :
381
- // Histograms that comes with samples are considered as classic histograms and are not supported.
382
- if len ( ts . Samples ) == 0 {
383
- addExponentialHistogramDatapoints ( metric . ExponentialHistogram (). DataPoints (), ls , ts , & stats )
382
+ if len ( ts . Samples ) != 0 {
383
+ // Drop classic histogram series as we will not handle them.
384
+ continue
384
385
}
386
+ addExponentialHistogramDatapoints (metric .ExponentialHistogram ().DataPoints (), ls , ts , & stats )
385
387
case writev2 .Metadata_METRIC_TYPE_SUMMARY :
386
- addSummaryDatapoints (metric .Summary ().DataPoints (), ls , ts )
388
+ // Drop summary series as we will not handle them.
389
+ continue
387
390
default :
388
391
badRequestErrors = errors .Join (badRequestErrors , fmt .Errorf ("unsupported metric type %q for metric %q" , ts .Metadata .Type , metricName ))
389
392
}
@@ -392,6 +395,15 @@ func (prw *prometheusRemoteWriteReceiver) translateV2(_ context.Context, req *wr
392
395
return otelMetrics , stats , badRequestErrors
393
396
}
394
397
398
+ // setMetric append a new empty metric and assign the name, unit and description to it.
399
+ func setMetric (scope pmetric.ScopeMetrics , metricName , unit , description string ) pmetric.Metric {
400
+ metric := scope .Metrics ().AppendEmpty ()
401
+ metric .SetName (metricName )
402
+ metric .SetUnit (unit )
403
+ metric .SetDescription (description )
404
+ return metric
405
+ }
406
+
395
407
// parseJobAndInstance turns the job and instance labels service resource attributes.
396
408
// Following the specification at https://opentelemetry.io/docs/specs/otel/compatibility/prometheus_and_openmetrics/
397
409
func parseJobAndInstance (dest pcommon.Map , job , instance string ) {
@@ -425,10 +437,6 @@ func addNumberDatapoints(datapoints pmetric.NumberDataPointSlice, ls labels.Labe
425
437
stats .Samples += len (ts .Samples )
426
438
}
427
439
428
- func addSummaryDatapoints (_ pmetric.SummaryDataPointSlice , _ labels.Labels , _ writev2.TimeSeries ) {
429
- // TODO: Implement this function
430
- }
431
-
432
440
func addExponentialHistogramDatapoints (datapoints pmetric.ExponentialHistogramDataPointSlice , ls labels.Labels , ts writev2.TimeSeries , stats * promremote.WriteResponseStats ) {
433
441
for _ , histogram := range ts .Histograms {
434
442
// Drop histograms with RESET_HINT_GAUGE or negative counts.
0 commit comments