@@ -19,6 +19,9 @@ prometheus_format_test_() ->
19
19
fun test_deregister /1 ,
20
20
fun test_remove /1 ,
21
21
fun test_default_value /1 ,
22
+ fun test_values_when_empty /1 ,
23
+ fun test_values_when_multiple_in_parallel /1 ,
24
+ fun test_values_when_non_existing /1 ,
22
25
fun test_values /1 ,
23
26
fun test_collector1 /1 ,
24
27
fun test_collector2 /1 ,
@@ -31,15 +34,7 @@ test_merge_logic_when_fetching_value(_) ->
31
34
prometheus_quantile_summary :declare (
32
35
[{name , Name }, {labels , []}, {help , " " }, {error , 0.01 }, {bound , 2184 }]
33
36
),
34
- % Observe many values
35
- Fun = fun () ->
36
- [
37
- prometheus_quantile_summary :observe (Name , N )
38
- || N <- lists :seq (1 , 100 )
39
- ]
40
- end ,
41
- Monitors = [spawn_monitor (Fun ) || _ <- lists :seq (1 , 1000 )],
42
- collect_monitors (Monitors ),
37
+ parallel_observe_sequence_of_values (Name ),
43
38
Value = prometheus_quantile_summary :value (Name ),
44
39
[
45
40
? _assertMatch (
@@ -85,6 +80,23 @@ test_errors(_) ->
85
80
{invalid_metric_help , 12 , " metric help is not a string" },
86
81
prometheus_quantile_summary :new ([{name , " qwe" }, {help , 12 }])
87
82
),
83
+ ? _assertError (
84
+ {invalid_bound , 3.141592 , " Bound should be a positive integer" },
85
+ prometheus_quantile_summary :new ([
86
+ {name , " qwe" },
87
+ {bound , 3.141592 },
88
+ {help , " " }
89
+ ])
90
+ ),
91
+ ? _assertError (
92
+ {invalid_error , 101 , " Error should be a percentage point in (0,100)" },
93
+ prometheus_quantile_summary :new ([
94
+ {name , " qwe" },
95
+ {error , 101 },
96
+ {labels , [" qua" , " quantile" ]},
97
+ {help , " " }
98
+ ])
99
+ ),
88
100
% % mf/arity errors
89
101
? _assertError (
90
102
{unknown_metric , default , unknown_metric },
@@ -400,6 +412,46 @@ test_default_value(_) ->
400
412
? _assertMatch ({0 , 0 , []}, SomethingValue )
401
413
].
402
414
415
+ test_values_when_empty (_ ) ->
416
+ prometheus_quantile_summary :new ([
417
+ {name , orders_summary },
418
+ {labels , [department ]},
419
+ {help , " Track orders count/total sum" }
420
+ ]),
421
+ [
422
+ ? _assertMatch (
423
+ [],
424
+ lists :sort (prometheus_quantile_summary :values (default , orders_summary ))
425
+ )
426
+ ].
427
+
428
+ test_values_when_multiple_in_parallel (_ ) ->
429
+ prometheus_quantile_summary :new ([
430
+ {name , orders_summary },
431
+ {labels , []},
432
+ {help , " Track orders count/total sum" }
433
+ ]),
434
+ parallel_observe_sequence_of_values (orders_summary ),
435
+ [
436
+ ? _assertMatch (
437
+ [
438
+ {[],100000 ,5050000 ,
439
+ [{0.5 ,49.90296094906653 },
440
+ {0.9 ,89.13032933635913 },
441
+ {0.95 ,94.64203039019942 }]}
442
+ ],
443
+ lists :sort (prometheus_quantile_summary :values (default , orders_summary ))
444
+ )
445
+ ].
446
+
447
+ test_values_when_non_existing (_ ) ->
448
+ [
449
+ ? _assertMatch (
450
+ [],
451
+ lists :sort (prometheus_quantile_summary :values (default , orders_summary ))
452
+ )
453
+ ].
454
+
403
455
test_values (_ ) ->
404
456
prometheus_quantile_summary :new ([
405
457
{name , orders_summary },
@@ -408,7 +460,6 @@ test_values(_) ->
408
460
]),
409
461
prometheus_quantile_summary :observe (orders_summary , [electronics ], 765.5 ),
410
462
prometheus_quantile_summary :observe (orders_summary , [groceries ], 112.3 ),
411
-
412
463
[
413
464
? _assertMatch (
414
465
[
@@ -533,6 +584,17 @@ test_collector3(_) ->
533
584
)
534
585
].
535
586
587
+ parallel_observe_sequence_of_values (Name ) ->
588
+ % Observe many values
589
+ Fun = fun () ->
590
+ [
591
+ prometheus_quantile_summary :observe (Name , N )
592
+ || N <- lists :seq (1 , 100 )
593
+ ]
594
+ end ,
595
+ Monitors = [spawn_monitor (Fun ) || _ <- lists :seq (1 , 1000 )],
596
+ collect_monitors (Monitors ).
597
+
536
598
collect_monitors ([]) ->
537
599
ok ;
538
600
collect_monitors ([{Pid , Ref } | Monitors ]) ->
0 commit comments