@@ -31,6 +31,7 @@ class PrometheusWebTest(support.BaseWebTest, unittest.TestCase):
31
31
def get_app_settings (cls , extras = None ):
32
32
settings = super ().get_app_settings (extras )
33
33
settings ["includes" ] = "kinto.plugins.prometheus"
34
+ settings ["project_name" ] = "kinto PROD"
34
35
return settings
35
36
36
37
@@ -59,15 +60,15 @@ def test_timer_can_be_used_as_context_manager(self):
59
60
self .assertEqual (my_func (1 , 1 ), 2 )
60
61
61
62
resp = self .app .get ("/__metrics__" )
62
- self .assertIn ("TYPE func_latency_context summary" , resp .text )
63
+ self .assertIn ("TYPE kintoprod_func_latency_context summary" , resp .text )
63
64
64
65
def test_timer_can_be_used_as_decorator (self ):
65
66
decorated = self .app .app .registry .metrics .timer ("func.latency.decorator" )(my_func )
66
67
67
68
self .assertEqual (decorated (1 , 1 ), 2 )
68
69
69
70
resp = self .app .get ("/__metrics__" )
70
- self .assertIn ("TYPE func_latency_decorator summary" , resp .text )
71
+ self .assertIn ("TYPE kintoprod_func_latency_decorator summary" , resp .text )
71
72
72
73
def test_timer_can_be_used_as_decorator_on_partial_function (self ):
73
74
partial = functools .partial (my_func , 3 )
@@ -76,39 +77,39 @@ def test_timer_can_be_used_as_decorator_on_partial_function(self):
76
77
self .assertEqual (decorated (3 ), 6 )
77
78
78
79
resp = self .app .get ("/__metrics__" )
79
- self .assertIn ("TYPE func_latency_partial summary" , resp .text )
80
+ self .assertIn ("TYPE kintoprod_func_latency_partial summary" , resp .text )
80
81
81
82
def test_observe_a_single_value (self ):
82
83
self .app .app .registry .metrics .observe ("price" , 111 )
83
84
84
85
resp = self .app .get ("/__metrics__" )
85
- self .assertIn ("price_sum 111" , resp .text )
86
+ self .assertIn ("kintoprod_price_sum 111" , resp .text )
86
87
87
88
def test_observe_a_single_value_with_labels (self ):
88
89
self .app .app .registry .metrics .observe ("size" , 3.14 , labels = [("endpoint" , "/buckets" )])
89
90
90
91
resp = self .app .get ("/__metrics__" )
91
- self .assertIn ('size_sum {endpoint="/buckets"} 3.14' , resp .text )
92
+ self .assertIn ('kintoprod_size_sum {endpoint="/buckets"} 3.14' , resp .text )
92
93
93
94
def test_count_by_key (self ):
94
95
self .app .app .registry .metrics .count ("key" )
95
96
96
97
resp = self .app .get ("/__metrics__" )
97
- self .assertIn ("key_total 1.0" , resp .text )
98
+ self .assertIn ("kintoprod_key_total 1.0" , resp .text )
98
99
99
100
def test_count_by_key_value (self ):
100
101
self .app .app .registry .metrics .count ("bigstep" , count = 2 )
101
102
102
103
resp = self .app .get ("/__metrics__" )
103
- self .assertIn ("bigstep_total 2.0" , resp .text )
104
+ self .assertIn ("kintoprod_bigstep_total 2.0" , resp .text )
104
105
105
106
def test_count_by_key_grouped (self ):
106
107
self .app .app .registry .metrics .count ("http" , unique = [("status" , "500" )])
107
108
self .app .app .registry .metrics .count ("http" , unique = [("status" , "200" )])
108
109
109
110
resp = self .app .get ("/__metrics__" )
110
- self .assertIn ('http_total {status="500"} 1.0' , resp .text )
111
- self .assertIn ('http_total {status="200"} 1.0' , resp .text )
111
+ self .assertIn ('kintoprod_http_total {status="500"} 1.0' , resp .text )
112
+ self .assertIn ('kintoprod_http_total {status="200"} 1.0' , resp .text )
112
113
113
114
def test_metrics_cant_be_mixed (self ):
114
115
self .app .app .registry .metrics .count ("counter" )
@@ -127,16 +128,32 @@ def test_metrics_names_and_labels_are_transformed(self):
127
128
self .app .app .registry .metrics .count ("http.home.status" , unique = [("code.get" , "200" )])
128
129
129
130
resp = self .app .get ("/__metrics__" )
130
- self .assertIn ('http_home_status_total {code_get="200"} 1.0' , resp .text )
131
+ self .assertIn ('kintoprod_http_home_status_total {code_get="200"} 1.0' , resp .text )
131
132
132
133
def test_count_with_legacy_string_generic_group (self ):
133
134
self .app .app .registry .metrics .count ("champignons" , unique = "boletus" )
134
135
135
136
resp = self .app .get ("/__metrics__" )
136
- self .assertIn ('champignons_total {group="boletus"} 1.0' , resp .text )
137
+ self .assertIn ('kintoprod_champignons_total {group="boletus"} 1.0' , resp .text )
137
138
138
139
def test_count_with_legacy_string_basic_group (self ):
139
140
self .app .app .registry .metrics .count ("mushrooms" , unique = "species.boletus" )
140
141
141
142
resp = self .app .get ("/__metrics__" )
142
- self .assertIn ('mushrooms_total{species="boletus"} 1.0' , resp .text )
143
+ self .assertIn ('kintoprod_mushrooms_total{species="boletus"} 1.0' , resp .text )
144
+
145
+
146
+ @skip_if_no_prometheus
147
+ class PrometheusNoPrefixTest (PrometheusWebTest ):
148
+ @classmethod
149
+ def get_app_settings (cls , extras = None ):
150
+ settings = super ().get_app_settings (extras )
151
+ settings ["project_name" ] = "Some Project"
152
+ settings ["prometheus_prefix" ] = ""
153
+ return settings
154
+
155
+ def test_metrics_have_no_prefix (self ):
156
+ self .app .app .registry .metrics .observe ("price" , 111 )
157
+
158
+ resp = self .app .get ("/__metrics__" )
159
+ self .assertIn ("TYPE price summary" , resp .text )
0 commit comments