50 lines
1.1 KiB
Coq
50 lines
1.1 KiB
Coq
|
module metrics
|
||
|
|
||
|
fn test_only_counters() {
|
||
|
mut m := new_default_collector()
|
||
|
m.counter_increment(name: 'test')
|
||
|
|
||
|
mut e := new_prometheus_exporter([])
|
||
|
e.load(m)
|
||
|
|
||
|
assert e.export_to_string()! == 'test 1\n'
|
||
|
|
||
|
metric := Metric{
|
||
|
name: 'test2'
|
||
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
||
|
}
|
||
|
m.counter_increment(metric)
|
||
|
m.counter_increment(metric)
|
||
|
|
||
|
assert e.export_to_string()! == 'test 1\ntest2{hi="label",hi2="label2"} 2\n'
|
||
|
}
|
||
|
|
||
|
fn test_only_gauges() {
|
||
|
mut m := new_default_collector()
|
||
|
m.gauge_set(3.25, name: 'test')
|
||
|
|
||
|
mut e := new_prometheus_exporter([])
|
||
|
e.load(m)
|
||
|
|
||
|
assert e.export_to_string()! == 'test 3.25\n'
|
||
|
|
||
|
metric := Metric{
|
||
|
name: 'test2'
|
||
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
||
|
}
|
||
|
m.gauge_add(2.5, metric)
|
||
|
|
||
|
assert e.export_to_string()! == 'test 3.25\ntest2{hi="label",hi2="label2"} 2.5\n'
|
||
|
}
|
||
|
|
||
|
fn test_single_histogram() {
|
||
|
mut m := new_default_collector()
|
||
|
|
||
|
m.histogram_record(5.0, name: 'test')
|
||
|
|
||
|
mut e := new_prometheus_exporter([0.5, 5.0])
|
||
|
e.load(m)
|
||
|
|
||
|
assert e.export_to_string()! == 'test_count 1\ntest_sum 5.0\ntest_bucket{le="0.5"} 0\ntest_bucket{le="5.0"} 1\n'
|
||
|
}
|