|
5 | 5 | # include <sstream>
|
6 | 6 | # include <utility>
|
7 | 7 | # include <vector>
|
| 8 | +# include "prometheus/metric_family.h" |
8 | 9 |
|
9 | 10 | # include <prometheus/metric_type.h>
|
10 | 11 | # include "opentelemetry/exporters/prometheus/exporter_utils.h"
|
@@ -74,12 +75,38 @@ std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateT
|
74 | 75 | SetData(std::vector<double>{sum, (double)histogram_point_data.count_}, boundaries,
|
75 | 76 | counts, point_data_attr.attributes, time, &metric_family);
|
76 | 77 | }
|
| 78 | + else if (type == prometheus_client::MetricType::Gauge) |
| 79 | + { |
| 80 | + if (nostd::holds_alternative<sdk::metrics::LastValuePointData>( |
| 81 | + point_data_attr.point_data)) |
| 82 | + { |
| 83 | + auto last_value_point_data = |
| 84 | + nostd::get<sdk::metrics::LastValuePointData>(point_data_attr.point_data); |
| 85 | + std::vector<metric_sdk::ValueType> values{last_value_point_data.value_}; |
| 86 | + SetData(values, point_data_attr.attributes, type, time, &metric_family); |
| 87 | + } |
| 88 | + else |
| 89 | + { |
| 90 | + OTEL_INTERNAL_LOG_WARN( |
| 91 | + "[Prometheus Exporter] TranslateToPrometheus - " |
| 92 | + "invalid LastValuePointData type"); |
| 93 | + } |
| 94 | + } |
77 | 95 | else // Counter, Untyped
|
78 | 96 | {
|
79 |
| - auto sum_point_data = |
80 |
| - nostd::get<sdk::metrics::SumPointData>(point_data_attr.point_data); |
81 |
| - std::vector<metric_sdk::ValueType> values{sum_point_data.value_}; |
82 |
| - SetData(values, point_data_attr.attributes, type, time, &metric_family); |
| 97 | + if (nostd::holds_alternative<sdk::metrics::SumPointData>(point_data_attr.point_data)) |
| 98 | + { |
| 99 | + auto sum_point_data = |
| 100 | + nostd::get<sdk::metrics::SumPointData>(point_data_attr.point_data); |
| 101 | + std::vector<metric_sdk::ValueType> values{sum_point_data.value_}; |
| 102 | + SetData(values, point_data_attr.attributes, type, time, &metric_family); |
| 103 | + } |
| 104 | + else |
| 105 | + { |
| 106 | + OTEL_INTERNAL_LOG_WARN( |
| 107 | + "[Prometheus Exporter] TranslateToPrometheus - " |
| 108 | + "invalid SumPointData type"); |
| 109 | + } |
83 | 110 | }
|
84 | 111 | }
|
85 | 112 | output.emplace_back(metric_family);
|
@@ -140,6 +167,8 @@ prometheus_client::MetricType PrometheusExporterUtils::TranslateType(
|
140 | 167 | return prometheus_client::MetricType::Counter;
|
141 | 168 | case metric_sdk::AggregationType::kHistogram:
|
142 | 169 | return prometheus_client::MetricType::Histogram;
|
| 170 | + case metric_sdk::AggregationType::kLastValue: |
| 171 | + return prometheus_client::MetricType::Gauge; |
143 | 172 | default:
|
144 | 173 | return prometheus_client::MetricType::Untyped;
|
145 | 174 | }
|
@@ -276,6 +305,10 @@ void PrometheusExporterUtils::SetValue(std::vector<T> values,
|
276 | 305 | metric->counter.value = value;
|
277 | 306 | break;
|
278 | 307 | }
|
| 308 | + case prometheus_client::MetricType::Gauge: { |
| 309 | + metric->gauge.value = value; |
| 310 | + break; |
| 311 | + } |
279 | 312 | case prometheus_client::MetricType::Untyped: {
|
280 | 313 | metric->untyped.value = value;
|
281 | 314 | break;
|
|
0 commit comments