mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-07 06:37:17 +02:00
Set metadata type as gauge in otelMetricTypeToPromMetric
Signed-off-by: Carrie Edwards <edwrdscarrie@gmail.com>
This commit is contained in:
parent
9c32a69bf3
commit
ff693401eb
@ -212,19 +212,8 @@ func createAttributes(resource pcommon.Resource, attributes pcommon.Map, scope s
|
|||||||
|
|
||||||
if metadata.Type != prompb.MetricMetadata_UNKNOWN {
|
if metadata.Type != prompb.MetricMetadata_UNKNOWN {
|
||||||
typeValue := strings.ToLower(metadata.Type.String())
|
typeValue := strings.ToLower(metadata.Type.String())
|
||||||
|
|
||||||
if settings.AllowDeltaTemporality && hasTemporality && temporality == pmetric.AggregationTemporalityDelta {
|
|
||||||
switch metadata.Type {
|
|
||||||
case prompb.MetricMetadata_COUNTER:
|
|
||||||
typeValue = "gauge"
|
|
||||||
case prompb.MetricMetadata_HISTOGRAM:
|
|
||||||
typeValue = "gaugehistogram"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
l["__type__"] = typeValue
|
l["__type__"] = typeValue
|
||||||
}
|
}
|
||||||
|
|
||||||
if metadata.Unit != "" {
|
if metadata.Unit != "" {
|
||||||
l["__unit__"] = unitNamer.Build(metadata.Unit)
|
l["__unit__"] = unitNamer.Build(metadata.Unit)
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func (c *PrometheusConverter) FromMetrics(ctx context.Context, md pmetric.Metric
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metadata := prompb.MetricMetadata{
|
metadata := prompb.MetricMetadata{
|
||||||
Type: otelMetricTypeToPromMetricType(metric),
|
Type: otelMetricTypeToPromMetricType(metric, settings.AllowDeltaTemporality),
|
||||||
MetricFamilyName: promName,
|
MetricFamilyName: promName,
|
||||||
Help: metric.Description(),
|
Help: metric.Description(),
|
||||||
Unit: metric.Unit(),
|
Unit: metric.Unit(),
|
||||||
|
@ -22,7 +22,10 @@ import (
|
|||||||
"github.com/prometheus/prometheus/prompb"
|
"github.com/prometheus/prometheus/prompb"
|
||||||
)
|
)
|
||||||
|
|
||||||
func otelMetricTypeToPromMetricType(otelMetric pmetric.Metric) prompb.MetricMetadata_MetricType {
|
// As part of implementing support for delta temporality, the metric type metadata for delta metrics
|
||||||
|
// will be "gauge"/"gaugehistogram".
|
||||||
|
// See proposal: https://github.com/prometheus/proposals/pull/48/
|
||||||
|
func otelMetricTypeToPromMetricType(otelMetric pmetric.Metric, allowDeltaTemporality bool) prompb.MetricMetadata_MetricType {
|
||||||
switch otelMetric.Type() {
|
switch otelMetric.Type() {
|
||||||
case pmetric.MetricTypeGauge:
|
case pmetric.MetricTypeGauge:
|
||||||
return prompb.MetricMetadata_GAUGE
|
return prompb.MetricMetadata_GAUGE
|
||||||
@ -31,26 +34,20 @@ func otelMetricTypeToPromMetricType(otelMetric pmetric.Metric) prompb.MetricMeta
|
|||||||
if otelMetric.Sum().IsMonotonic() {
|
if otelMetric.Sum().IsMonotonic() {
|
||||||
metricType = prompb.MetricMetadata_COUNTER
|
metricType = prompb.MetricMetadata_COUNTER
|
||||||
}
|
}
|
||||||
// We're in an early phase of implementing delta support (proposal: https://github.com/prometheus/proposals/pull/48/)
|
if otelMetric.Sum().AggregationTemporality() == pmetric.AggregationTemporalityDelta && allowDeltaTemporality {
|
||||||
// We don't have a proper way to flag delta metrics yet, therefore marking the metric type as unknown for now.
|
metricType = prompb.MetricMetadata_GAUGE
|
||||||
if otelMetric.Sum().AggregationTemporality() == pmetric.AggregationTemporalityDelta {
|
|
||||||
metricType = prompb.MetricMetadata_UNKNOWN
|
|
||||||
}
|
}
|
||||||
return metricType
|
return metricType
|
||||||
case pmetric.MetricTypeHistogram:
|
case pmetric.MetricTypeHistogram:
|
||||||
// We're in an early phase of implementing delta support (proposal: https://github.com/prometheus/proposals/pull/48/)
|
if otelMetric.Histogram().AggregationTemporality() == pmetric.AggregationTemporalityDelta && allowDeltaTemporality {
|
||||||
// We don't have a proper way to flag delta metrics yet, therefore marking the metric type as unknown for now.
|
return prompb.MetricMetadata_GAUGEHISTOGRAM
|
||||||
if otelMetric.Histogram().AggregationTemporality() == pmetric.AggregationTemporalityDelta {
|
|
||||||
return prompb.MetricMetadata_UNKNOWN
|
|
||||||
}
|
}
|
||||||
return prompb.MetricMetadata_HISTOGRAM
|
return prompb.MetricMetadata_HISTOGRAM
|
||||||
case pmetric.MetricTypeSummary:
|
case pmetric.MetricTypeSummary:
|
||||||
return prompb.MetricMetadata_SUMMARY
|
return prompb.MetricMetadata_SUMMARY
|
||||||
case pmetric.MetricTypeExponentialHistogram:
|
case pmetric.MetricTypeExponentialHistogram:
|
||||||
if otelMetric.ExponentialHistogram().AggregationTemporality() == pmetric.AggregationTemporalityDelta {
|
if otelMetric.ExponentialHistogram().AggregationTemporality() == pmetric.AggregationTemporalityDelta && allowDeltaTemporality {
|
||||||
// We're in an early phase of implementing delta support (proposal: https://github.com/prometheus/proposals/pull/48/)
|
return prompb.MetricMetadata_GAUGEHISTOGRAM
|
||||||
// We don't have a proper way to flag delta metrics yet, therefore marking the metric type as unknown for now.
|
|
||||||
return prompb.MetricMetadata_UNKNOWN
|
|
||||||
}
|
}
|
||||||
return prompb.MetricMetadata_HISTOGRAM
|
return prompb.MetricMetadata_HISTOGRAM
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user