@@ -20,11 +20,12 @@ test_suite_test_() ->
20
20
fun cleanup /1 ,
21
21
[ fun overview /0 ,
22
22
fun counters_with_persistent_term_field_spec /0 ,
23
- fun prometheus_format_group /0 ,
24
- fun prometheus_format_one /0 ,
25
- fun prometheus_format_with_many_labels /0 ,
26
- fun prometheus_format_ratio /0 ,
27
- fun prometheus_format_selected_metrics /0 ,
23
+ fun format_group /0 ,
24
+ fun format_one /0 ,
25
+ fun format_with_many_labels /0 ,
26
+ fun format_ratio /0 ,
27
+ fun format_selected_metrics /0 ,
28
+ fun text_format_selected_metrics /0 ,
28
29
fun invalid_fields /0 ]}.
29
30
30
31
overview () ->
@@ -90,7 +91,7 @@ counters_with_persistent_term_field_spec() ->
90
91
91
92
ok .
92
93
93
- prometheus_format_group () ->
94
+ format_group () ->
94
95
Group = widgets ,
95
96
Counters = [{reads , 1 , counter , " Total reads" }],
96
97
seshat :new_group (Group ),
@@ -105,7 +106,7 @@ prometheus_format_group() ->
105
106
? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
106
107
ok .
107
108
108
- prometheus_format_one () ->
109
+ format_one () ->
109
110
Group = widgets ,
110
111
Counters = [{reads , 1 , counter , " Total reads" }],
111
112
seshat :new_group (Group ),
@@ -118,7 +119,7 @@ prometheus_format_one() ->
118
119
? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
119
120
ok .
120
121
121
- prometheus_format_with_many_labels () ->
122
+ format_with_many_labels () ->
122
123
Group = widgets ,
123
124
Counters = [{reads , 1 , counter , " Total reads" }],
124
125
seshat :new_group (Group ),
@@ -134,7 +135,7 @@ prometheus_format_with_many_labels() ->
134
135
? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
135
136
ok .
136
137
137
- prometheus_format_selected_metrics () ->
138
+ format_selected_metrics () ->
138
139
Group = widgets ,
139
140
Counters = [
140
141
{reads , 1 , counter , " Total reads" },
@@ -166,7 +167,7 @@ invalid_fields() ->
166
167
167
168
ok .
168
169
169
- prometheus_format_ratio () ->
170
+ format_ratio () ->
170
171
Group = widgets ,
171
172
Counters = [{pings , 1 , ratio , " Some ratio that happens to be 0%" },
172
173
{pongs , 2 , ratio , " Some ratio that happens to be 17%" },
@@ -196,6 +197,46 @@ prometheus_format_ratio() ->
196
197
? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
197
198
ok .
198
199
200
+ text_format_selected_metrics () ->
201
+ Group = widgets ,
202
+ Counters = [
203
+ {reads , 1 , counter , " Total reads" },
204
+ {writes , 2 , counter , " Total writes" },
205
+ {cached , 3 , ratio , " Ratio of things served from cache" }
206
+ ],
207
+ seshat :new_group (Group ),
208
+ seshat :new (Group , thing1 , Counters , #{component => " thing1" , version => " 1.2.3" }),
209
+ seshat :new (Group , thing2 , Counters , #{component => " thing2" }),
210
+ seshat :new (Group , thing3 , Counters , #{component => " thing3" }),
211
+ set_value (Group , thing1 , reads , 1 ),
212
+ set_value (Group , thing1 , writes , 2 ),
213
+ set_value (Group , thing1 , cached , 10 ),
214
+ set_value (Group , thing2 , reads , 3 ),
215
+ set_value (Group , thing2 , writes , 4 ),
216
+ set_value (Group , thing2 , cached , 100 ),
217
+ set_value (Group , thing3 , reads , 1234 ),
218
+ set_value (Group , thing3 , writes , 4321 ),
219
+ set_value (Group , thing3 , cached , 17 ),
220
+ PrometheusFormat = binary_to_list (seshat :text_format (Group , " acme" , [reads , writes , cached ])),
221
+ ExpectedPrometheusFormat = " # HELP acme_reads Total reads\n "
222
+ " # TYPE acme_reads counter\n "
223
+ " acme_reads{version=\" 1.2.3\" ,component=\" thing1\" } 1\n "
224
+ " acme_reads{component=\" thing2\" } 3\n "
225
+ " acme_reads{component=\" thing3\" } 1234\n "
226
+ " # HELP acme_writes Total writes\n "
227
+ " # TYPE acme_writes counter\n "
228
+ " acme_writes{version=\" 1.2.3\" ,component=\" thing1\" } 2\n "
229
+ " acme_writes{component=\" thing2\" } 4\n "
230
+ " acme_writes{component=\" thing3\" } 4321\n "
231
+ " # HELP acme_cached_ratio Ratio of things served from cache\n "
232
+ " # TYPE acme_cached_ratio gauge\n "
233
+ " acme_cached_ratio{version=\" 1.2.3\" ,component=\" thing1\" } 0.1\n "
234
+ " acme_cached_ratio{component=\" thing2\" } 1.0\n "
235
+ " acme_cached_ratio{component=\" thing3\" } 0.17\n " ,
236
+
237
+ ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
238
+ ok .
239
+
199
240
% % test helpers
200
241
201
242
set_value (Group , Id , Name , Value ) ->
0 commit comments