@@ -99,12 +99,12 @@ format_group() ->
99
99
seshat :new (Group , widget1 , Counters , #{component => widget1 }),
100
100
seshat :new (Group , widget2 , Counters , #{component => widget2 }),
101
101
seshat :new (Group , screw , Counters ), % no labels, will be omitted
102
- PrometheusFormat = seshat :format (Group ),
103
- ExpectedPrometheusFormat = #{reads => #{type => counter ,
104
- help => " Total reads" ,
105
- values => #{#{component => widget1 } => 0 ,
106
- #{component => widget2 } => 0 }}},
107
- ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
102
+ Result = seshat :format (Group ),
103
+ ExpectedMap = #{reads => #{type => counter ,
104
+ help => " Total reads" ,
105
+ values => #{#{component => widget1 } => 0 ,
106
+ #{component => widget2 } => 0 }}},
107
+ ? assertEqual (ExpectedMap , Result ),
108
108
ok .
109
109
110
110
format_one () ->
@@ -113,11 +113,11 @@ format_one() ->
113
113
seshat :new_group (Group ),
114
114
seshat :new (Group , widget1 , Counters , #{component => widget1 }),
115
115
seshat :new (Group , widget2 , Counters , #{component => widget2 }),
116
- PrometheusFormat = seshat :format_one (Group , widget2 ),
117
- ExpectedPrometheusFormat = #{reads => #{type => counter ,
118
- help => " Total reads" ,
119
- values => #{#{component => widget2 } => 0 }}},
120
- ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
116
+ Result = seshat :format_one (Group , widget2 ),
117
+ ExpectedMap = #{reads => #{type => counter ,
118
+ help => " Total reads" ,
119
+ values => #{#{component => widget2 } => 0 }}},
120
+ ? assertEqual (ExpectedMap , Result ),
121
121
ok .
122
122
123
123
format_with_many_labels () ->
@@ -128,12 +128,12 @@ format_with_many_labels() ->
128
128
seshat :new (Group , widget2 , Counters , #{component => " widget2" , status => down }),
129
129
set_value (Group , widget1 , reads , 1 ),
130
130
set_value (Group , widget2 , reads , 2 ),
131
- PrometheusFormat = seshat :format (Group ),
132
- ExpectedPrometheusFormat = #{reads => #{type => counter ,
133
- help => " Total reads" ,
134
- values => #{#{component => " widget1" , status => up } => 1 ,
135
- #{component => " widget2" , status => down } => 2 }}},
136
- ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
131
+ Result = seshat :format (Group ),
132
+ ExpectedMap = #{reads => #{type => counter ,
133
+ help => " Total reads" ,
134
+ values => #{#{component => " widget1" , status => up } => 1 ,
135
+ #{component => " widget2" , status => down } => 2 }}},
136
+ ? assertEqual (ExpectedMap , Result ),
137
137
ok .
138
138
139
139
format_selected_metrics () ->
@@ -146,16 +146,16 @@ format_selected_metrics() ->
146
146
seshat :new_group (Group ),
147
147
seshat :new (Group , thing1 , Counters , #{component => " thing1" }),
148
148
seshat :new (Group , thing2 , Counters , #{component => " thing2" }),
149
- PrometheusFormat = seshat :format (Group , [reads , writes ]),
150
- ExpectedPrometheusFormat = #{reads => #{type => counter ,
151
- help => " Total reads" ,
152
- values => #{#{component => " thing1" } => 0 ,
153
- #{component => " thing2" } => 0 }},
154
- writes => #{type => counter ,
155
- help => " Total writes" ,
156
- values => #{#{component => " thing1" } => 0 ,
157
- #{component => " thing2" } => 0 }}},
158
- ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
149
+ Result = seshat :format (Group , [reads , writes ]),
150
+ ExpectedMap = #{reads => #{type => counter ,
151
+ help => " Total reads" ,
152
+ values => #{#{component => " thing1" } => 0 ,
153
+ #{component => " thing2" } => 0 }},
154
+ writes => #{type => counter ,
155
+ help => " Total writes" ,
156
+ values => #{#{component => " thing1" } => 0 ,
157
+ #{component => " thing2" } => 0 }}},
158
+ ? assertEqual (ExpectedMap , Result ),
159
159
ok .
160
160
161
161
invalid_fields () ->
@@ -181,21 +181,20 @@ format_ratio() ->
181
181
set_value (Group , test_component , pangs , 33 ),
182
182
set_value (Group , test_component , rings , 100 ),
183
183
184
- PrometheusFormat = seshat :format (Group ),
185
- ExpectedPrometheusFormat = #{pings => #{type => gauge ,
186
- help => " Some ratio that happens to be 0%" ,
187
- values => #{#{component => test } => 0.0 }},
188
- pongs => #{type => gauge ,
189
- help => " Some ratio that happens to be 17%" ,
190
- values => #{#{component => test } => 0.17 }},
191
- pangs => #{type => gauge ,
192
- help => " Some ratio that happens to be 33%" ,
193
- values => #{#{component => test } => 0.33 }},
194
- rings => #{type => gauge ,
195
- help => " Some ratio that happens to be 100%" ,
196
- values => #{#{component => test } => 1.0 }}},
197
-
198
- ? assertEqual (ExpectedPrometheusFormat , PrometheusFormat ),
184
+ Result = seshat :format (Group ),
185
+ ExpectedMap = #{pings => #{type => gauge ,
186
+ help => " Some ratio that happens to be 0%" ,
187
+ values => #{#{component => test } => 0.0 }},
188
+ pongs => #{type => gauge ,
189
+ help => " Some ratio that happens to be 17%" ,
190
+ values => #{#{component => test } => 0.17 }},
191
+ pangs => #{type => gauge ,
192
+ help => " Some ratio that happens to be 33%" ,
193
+ values => #{#{component => test } => 0.33 }},
194
+ rings => #{type => gauge ,
195
+ help => " Some ratio that happens to be 100%" ,
196
+ values => #{#{component => test } => 1.0 }}},
197
+ ? assertEqual (ExpectedMap , Result ),
199
198
ok .
200
199
201
200
format_time_metrics () ->
@@ -214,25 +213,24 @@ format_ratio() ->
214
213
set_value (Group , test_component , short_latency , 5 ),
215
214
set_value (Group , test_component , long_latency , 1500 ),
216
215
217
- MapFormat = seshat :format (Group ),
218
- ExpectedMapFormat = #{
216
+ MapResult = seshat :format (Group ),
217
+ ExpectedMap = #{
219
218
job_duration => #{type => gauge ,
220
- help => " Job duration" ,
221
- values => #{Labels => 30.0 }},
219
+ help => " Job duration" ,
220
+ values => #{Labels => 30.0 }},
222
221
short_latency => #{type => gauge ,
223
- help => " Short latency" ,
224
- values => #{Labels => 0.005 }},
222
+ help => " Short latency" ,
223
+ values => #{Labels => 0.005 }},
225
224
long_latency => #{type => gauge ,
226
- help => " Request latency" ,
227
- values => #{Labels => 1.5 }}
225
+ help => " Request latency" ,
226
+ values => #{Labels => 1.5 }}
228
227
},
229
- ? assertEqual (ExpectedMapFormat , MapFormat ),
228
+ ? assertEqual (ExpectedMap , MapResult ),
230
229
231
230
Prefix = " myapp" ,
232
231
MetricNames = [job_duration , short_latency , long_latency ], % Added new metric name
233
- ResultAsList = binary_to_list ( seshat :text_format (Group , Prefix , MetricNames ) ),
232
+ TextResult = seshat :text_format (Group , Prefix , MetricNames ),
234
233
235
- % Expected format needs sorting because order isn't guaranteed
236
234
ExpectedLines = [
237
235
" # HELP myapp_job_duration_seconds Job duration" ,
238
236
" # TYPE myapp_job_duration_seconds gauge" ,
@@ -244,15 +242,9 @@ format_ratio() ->
244
242
" # TYPE myapp_long_latency_seconds gauge" ,
245
243
" myapp_long_latency_seconds{component=\" test\" } 1.5"
246
244
],
247
- ExpectedSortedText = lists :sort (ExpectedLines ),
248
-
249
- % Split and sort the actual result for comparison
250
- ResultLines = string :split (ResultAsList , " \n " , all ),
251
- FilteredResultLines = [Line || Line <- ResultLines , Line /= " " ],
252
- SortedResultText = lists :sort (FilteredResultLines ),
253
-
254
- ? assertEqual (ExpectedSortedText , SortedResultText ),
245
+ ExpectedResult = list_to_binary (string :join (ExpectedLines , " \n " ) ++ " \n " ),
255
246
247
+ ? assertEqual (ExpectedResult , TextResult ),
256
248
ok .
257
249
258
250
text_format_selected_metrics () ->
@@ -288,34 +280,37 @@ text_format_selected_metrics() ->
288
280
set_value (Group , thing3 , duration , 345 ),
289
281
set_value (Group , thing3 , npc , 1 ), % to be ignored
290
282
291
- ResultAsList = binary_to_list (seshat :text_format (Group , " acme" , [reads , writes , cached , latency , duration ])),
292
- ExpectedPrometheusFormat = " # HELP acme_reads Total reads\n "
293
- " # TYPE acme_reads counter\n "
294
- " acme_reads{version=\" 1.2.3\" ,component=\" thing1\" } 1\n "
295
- " acme_reads{component=\" thing2\" ,some_atom=\" atom_value\" } 3\n "
296
- " acme_reads{component=\" thing3\" ,some_binary=\" binary_value\" } 1234\n "
297
- " # HELP acme_writes Total writes\n "
298
- " # TYPE acme_writes counter\n "
299
- " acme_writes{version=\" 1.2.3\" ,component=\" thing1\" } 2\n "
300
- " acme_writes{component=\" thing2\" ,some_atom=\" atom_value\" } 4\n "
301
- " acme_writes{component=\" thing3\" ,some_binary=\" binary_value\" } 4321\n "
302
- " # HELP acme_cached_ratio Ratio of things served from cache\n "
303
- " # TYPE acme_cached_ratio gauge\n "
304
- " acme_cached_ratio{version=\" 1.2.3\" ,component=\" thing1\" } 0.1\n "
305
- " acme_cached_ratio{component=\" thing2\" ,some_atom=\" atom_value\" } 1.0\n "
306
- " acme_cached_ratio{component=\" thing3\" ,some_binary=\" binary_value\" } 0.17\n "
307
- " # HELP acme_latency_seconds Latency\n "
308
- " # TYPE acme_latency_seconds gauge\n "
309
- " acme_latency_seconds{version=\" 1.2.3\" ,component=\" thing1\" } 0.005\n "
310
- " acme_latency_seconds{component=\" thing2\" ,some_atom=\" atom_value\" } 0.006\n "
311
- " acme_latency_seconds{component=\" thing3\" ,some_binary=\" binary_value\" } 0.007\n "
312
- " # HELP acme_duration_seconds Duration\n "
313
- " # TYPE acme_duration_seconds gauge\n "
314
- " acme_duration_seconds{version=\" 1.2.3\" ,component=\" thing1\" } 123.0\n "
315
- " acme_duration_seconds{component=\" thing2\" ,some_atom=\" atom_value\" } 234.0\n "
316
- " acme_duration_seconds{component=\" thing3\" ,some_binary=\" binary_value\" } 345.0\n " ,
317
-
318
- ? assertEqual (ExpectedPrometheusFormat , ResultAsList ),
283
+ Result = seshat :text_format (Group , " acme" , [reads , writes , cached , latency , duration ]),
284
+ ExpectedLines = [
285
+ " # HELP acme_reads Total reads" ,
286
+ " # TYPE acme_reads counter" ,
287
+ " acme_reads{version=\" 1.2.3\" ,component=\" thing1\" } 1" ,
288
+ " acme_reads{component=\" thing2\" ,some_atom=\" atom_value\" } 3" ,
289
+ " acme_reads{component=\" thing3\" ,some_binary=\" binary_value\" } 1234" ,
290
+ " # HELP acme_writes Total writes" ,
291
+ " # TYPE acme_writes counter" ,
292
+ " acme_writes{version=\" 1.2.3\" ,component=\" thing1\" } 2" ,
293
+ " acme_writes{component=\" thing2\" ,some_atom=\" atom_value\" } 4" ,
294
+ " acme_writes{component=\" thing3\" ,some_binary=\" binary_value\" } 4321" ,
295
+ " # HELP acme_cached_ratio Ratio of things served from cache" ,
296
+ " # TYPE acme_cached_ratio gauge" ,
297
+ " acme_cached_ratio{version=\" 1.2.3\" ,component=\" thing1\" } 0.1" ,
298
+ " acme_cached_ratio{component=\" thing2\" ,some_atom=\" atom_value\" } 1.0" ,
299
+ " acme_cached_ratio{component=\" thing3\" ,some_binary=\" binary_value\" } 0.17" ,
300
+ " # HELP acme_latency_seconds Latency" ,
301
+ " # TYPE acme_latency_seconds gauge" ,
302
+ " acme_latency_seconds{version=\" 1.2.3\" ,component=\" thing1\" } 0.005" ,
303
+ " acme_latency_seconds{component=\" thing2\" ,some_atom=\" atom_value\" } 0.006" ,
304
+ " acme_latency_seconds{component=\" thing3\" ,some_binary=\" binary_value\" } 0.007" ,
305
+ " # HELP acme_duration_seconds Duration" ,
306
+ " # TYPE acme_duration_seconds gauge" ,
307
+ " acme_duration_seconds{version=\" 1.2.3\" ,component=\" thing1\" } 123.0" ,
308
+ " acme_duration_seconds{component=\" thing2\" ,some_atom=\" atom_value\" } 234.0" ,
309
+ " acme_duration_seconds{component=\" thing3\" ,some_binary=\" binary_value\" } 345.0"
310
+ ],
311
+ ExpectedResult = list_to_binary (string :join (ExpectedLines , " \n " ) ++ " \n " ),
312
+
313
+ ? assertEqual (ExpectedResult , Result ),
319
314
ok .
320
315
321
316
% % test helpers
0 commit comments