Skip to content

Commit 2acff12

Browse files
committed
show tests fail at CI without the change
Signed-off-by: emdneto <[email protected]>
1 parent 9e94fd2 commit 2acff12

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

exporter/opentelemetry-exporter-prometheus/src/opentelemetry/exporter/prometheus/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,14 @@ def _translate_to_prometheus(
224224
metrics.append(metric)
225225

226226
for metric in metrics:
227-
label_valuess = []
227+
label_values_data_points = []
228+
label_keys_data_points = []
228229
values = []
229230

230-
pre_metric_family_ids = []
231+
per_metric_family_ids = []
231232

232233
metric_name = sanitize_full_name(metric.name)
233-
234234
metric_description = metric.description or ""
235-
236235
metric_unit = map_unit(metric.unit)
237236

238237
for number_data_point in metric.data.data_points:
@@ -243,7 +242,7 @@ def _translate_to_prometheus(
243242
label_keys.append(sanitize_attribute(key))
244243
label_values.append(self._check_value(value))
245244

246-
pre_metric_family_ids.append(
245+
per_metric_family_ids.append(
247246
"|".join(
248247
[
249248
metric_name,
@@ -254,7 +253,8 @@ def _translate_to_prometheus(
254253
)
255254
)
256255

257-
label_valuess.append(label_values)
256+
label_values_data_points.append(label_values)
257+
label_keys_data_points.append(label_keys)
258258
if isinstance(number_data_point, HistogramDataPoint):
259259
values.append(
260260
{
@@ -269,7 +269,7 @@ def _translate_to_prometheus(
269269
values.append(number_data_point.value)
270270

271271
for pre_metric_family_id, label_values, value in zip(
272-
pre_metric_family_ids, label_valuess, values
272+
per_metric_family_ids, label_values_data_points, values
273273
):
274274
is_non_monotonic_sum = (
275275
isinstance(metric.data, Sum)

exporter/opentelemetry-exporter-prometheus/tests/test_prometheus_exporter.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,3 +638,59 @@ def test_semconv(self):
638638
"""
639639
),
640640
)
641+
642+
def test_multiple_data_points_with_different_label_sets(self):
643+
hist_point_1 = HistogramDataPoint(
644+
attributes={"http_target": "/foobar", "net_host_port": 8080},
645+
start_time_unix_nano=1641946016139533244,
646+
time_unix_nano=1641946016139533244,
647+
count=6,
648+
sum=579.0,
649+
bucket_counts=[1, 3, 2],
650+
explicit_bounds=[123.0, 456.0],
651+
min=1,
652+
max=457,
653+
)
654+
hist_point_2 = HistogramDataPoint(
655+
attributes={"net_host_port": 8080},
656+
start_time_unix_nano=1641946016139533245,
657+
time_unix_nano=1641946016139533245,
658+
count=7,
659+
sum=579.0,
660+
bucket_counts=[1, 3, 3],
661+
explicit_bounds=[123.0, 456.0],
662+
min=1,
663+
max=457,
664+
)
665+
666+
metric = Metric(
667+
name="http.server.request.duration",
668+
description="test multiple label sets",
669+
unit="s",
670+
data=Histogram(
671+
data_points=[hist_point_1, hist_point_2],
672+
aggregation_temporality=AggregationTemporality.CUMULATIVE,
673+
),
674+
)
675+
676+
self.verify_text_format(
677+
metric,
678+
dedent(
679+
"""\
680+
# HELP http_server_request_duration_seconds test multiple label sets
681+
# TYPE http_server_request_duration_seconds histogram
682+
http_server_request_duration_seconds_bucket{http_target="/foobar",le="123.0",net_host_port="8080"} 1.0
683+
http_server_request_duration_seconds_bucket{http_target="/foobar",le="456.0",net_host_port="8080"} 4.0
684+
http_server_request_duration_seconds_bucket{http_target="/foobar",le="+Inf",net_host_port="8080"} 6.0
685+
http_server_request_duration_seconds_count{http_target="/foobar",net_host_port="8080"} 6.0
686+
http_server_request_duration_seconds_sum{http_target="/foobar",net_host_port="8080"} 579.0
687+
# HELP http_server_request_duration_seconds test multiple label sets
688+
# TYPE http_server_request_duration_seconds histogram
689+
http_server_request_duration_seconds_bucket{le="123.0",net_host_port="8080"} 1.0
690+
http_server_request_duration_seconds_bucket{le="456.0",net_host_port="8080"} 4.0
691+
http_server_request_duration_seconds_bucket{le="+Inf",net_host_port="8080"} 7.0
692+
http_server_request_duration_seconds_count{net_host_port="8080"} 7.0
693+
http_server_request_duration_seconds_sum{net_host_port="8080"} 579.0
694+
"""
695+
),
696+
)

0 commit comments

Comments
 (0)