@@ -52,8 +52,7 @@ def setUp(self):
52
52
def test_constructor (self ):
53
53
"""Test the constructor."""
54
54
with self ._registry_register_patch :
55
- exporter = PrometheusMetricReader (prefix = "testprefix" )
56
- self .assertEqual (exporter ._collector ._prefix , "testprefix" )
55
+ _ = PrometheusMetricReader ()
57
56
self .assertTrue (self ._mock_registry_register .called )
58
57
59
58
def test_shutdown (self ):
@@ -102,21 +101,21 @@ def test_histogram_to_prometheus(self):
102
101
]
103
102
)
104
103
105
- collector = _CustomCollector ("testprefix" )
104
+ collector = _CustomCollector ()
106
105
collector .add_metrics_data (metrics_data )
107
106
result_bytes = generate_latest (collector )
108
107
result = result_bytes .decode ("utf-8" )
109
108
self .assertEqual (
110
109
result ,
111
110
dedent (
112
111
"""\
113
- # HELP testprefix_test_name_s foo
114
- # TYPE testprefix_test_name_s histogram
115
- testprefix_test_name_s_bucket {histo="1",le="123.0"} 1.0
116
- testprefix_test_name_s_bucket {histo="1",le="456.0"} 4.0
117
- testprefix_test_name_s_bucket {histo="1",le="+Inf"} 6.0
118
- testprefix_test_name_s_count {histo="1"} 6.0
119
- testprefix_test_name_s_sum {histo="1"} 579.0
112
+ # HELP test_name_s foo
113
+ # TYPE test_name_s histogram
114
+ test_name_s_bucket {histo="1",le="123.0"} 1.0
115
+ test_name_s_bucket {histo="1",le="456.0"} 4.0
116
+ test_name_s_bucket {histo="1",le="+Inf"} 6.0
117
+ test_name_s_count {histo="1"} 6.0
118
+ test_name_s_sum {histo="1"} 579.0
120
119
"""
121
120
),
122
121
)
@@ -147,14 +146,12 @@ def test_sum_to_prometheus(self):
147
146
]
148
147
)
149
148
150
- collector = _CustomCollector ("testprefix" )
149
+ collector = _CustomCollector ()
151
150
collector .add_metrics_data (metrics_data )
152
151
153
152
for prometheus_metric in collector .collect ():
154
153
self .assertEqual (type (prometheus_metric ), CounterMetricFamily )
155
- self .assertEqual (
156
- prometheus_metric .name , "testprefix_test_sum_testunit"
157
- )
154
+ self .assertEqual (prometheus_metric .name , "test_sum_testunit" )
158
155
self .assertEqual (prometheus_metric .documentation , "testdesc" )
159
156
self .assertTrue (len (prometheus_metric .samples ) == 1 )
160
157
self .assertEqual (prometheus_metric .samples [0 ].value , 123 )
@@ -192,14 +189,12 @@ def test_gauge_to_prometheus(self):
192
189
]
193
190
)
194
191
195
- collector = _CustomCollector ("testprefix" )
192
+ collector = _CustomCollector ()
196
193
collector .add_metrics_data (metrics_data )
197
194
198
195
for prometheus_metric in collector .collect ():
199
196
self .assertEqual (type (prometheus_metric ), GaugeMetricFamily )
200
- self .assertEqual (
201
- prometheus_metric .name , "testprefix_test_gauge_testunit"
202
- )
197
+ self .assertEqual (prometheus_metric .name , "test_gauge_testunit" )
203
198
self .assertEqual (prometheus_metric .documentation , "testdesc" )
204
199
self .assertTrue (len (prometheus_metric .samples ) == 1 )
205
200
self .assertEqual (prometheus_metric .samples [0 ].value , 123 )
@@ -217,13 +212,13 @@ def test_invalid_metric(self):
217
212
description = "testdesc" ,
218
213
unit = "testunit" ,
219
214
)
220
- collector = _CustomCollector ("testprefix" )
215
+ collector = _CustomCollector ()
221
216
collector .add_metrics_data ([record ])
222
217
collector .collect ()
223
218
self .assertLogs ("opentelemetry.exporter.prometheus" , level = "WARNING" )
224
219
225
220
def test_sanitize (self ):
226
- collector = _CustomCollector ("testprefix" )
221
+ collector = _CustomCollector ()
227
222
self .assertEqual (
228
223
collector ._sanitize ("1!2@3#4$5%6^7&8*9(0)_-" ),
229
224
"1_2_3_4_5_6_7_8_9_0___" ,
@@ -256,14 +251,12 @@ def test_list_labels(self):
256
251
)
257
252
]
258
253
)
259
- collector = _CustomCollector ("testprefix" )
254
+ collector = _CustomCollector ()
260
255
collector .add_metrics_data (metrics_data )
261
256
262
257
for prometheus_metric in collector .collect ():
263
258
self .assertEqual (type (prometheus_metric ), GaugeMetricFamily )
264
- self .assertEqual (
265
- prometheus_metric .name , "testprefix_test_gauge_testunit"
266
- )
259
+ self .assertEqual (prometheus_metric .name , "test_gauge_testunit" )
267
260
self .assertEqual (prometheus_metric .documentation , "testdesc" )
268
261
self .assertTrue (len (prometheus_metric .samples ) == 1 )
269
262
self .assertEqual (prometheus_metric .samples [0 ].value , 123 )
@@ -276,7 +269,7 @@ def test_list_labels(self):
276
269
277
270
def test_check_value (self ):
278
271
279
- collector = _CustomCollector ("" )
272
+ collector = _CustomCollector ()
280
273
281
274
self .assertEqual (collector ._check_value (1 ), "1" )
282
275
self .assertEqual (collector ._check_value (1.0 ), "1.0" )
@@ -290,7 +283,7 @@ def test_check_value(self):
290
283
291
284
def test_multiple_collection_calls (self ):
292
285
293
- metric_reader = PrometheusMetricReader (prefix = "prefix" )
286
+ metric_reader = PrometheusMetricReader ()
294
287
provider = MeterProvider (metric_readers = [metric_reader ])
295
288
meter = provider .get_meter ("getting-started" , "0.1.2" )
296
289
counter = meter .create_counter ("counter" )
0 commit comments