metrics/prometheus_test.v

50 lines
1.1 KiB
Coq
Raw Normal View History

2022-12-26 21:49:07 +01:00
module metrics
fn test_only_counters() {
mut m := new_default_collector()
m.counter_increment(name: 'test')
mut e := new_prometheus_exporter([])
e.load('hi_', m)
2022-12-26 21:49:07 +01:00
assert e.export_to_string()! == 'hi_test 1\n'
2022-12-26 21:49:07 +01:00
metric := Metric{
name: 'test2'
labels: [['hi', 'label']!, ['hi2', 'label2']!]
}
m.counter_increment(metric)
m.counter_increment(metric)
assert e.export_to_string()! == 'hi_test 1\nhi_test2{hi="label",hi2="label2"} 2\n'
2022-12-26 21:49:07 +01:00
}
fn test_only_gauges() {
mut m := new_default_collector()
m.gauge_set(3.25, name: 'test')
mut e := new_prometheus_exporter([])
e.load('hi_', m)
2022-12-26 21:49:07 +01:00
assert e.export_to_string()! == 'hi_test 3.25\n'
2022-12-26 21:49:07 +01:00
metric := Metric{
name: 'test2'
labels: [['hi', 'label']!, ['hi2', 'label2']!]
}
m.gauge_add(2.5, metric)
assert e.export_to_string()! == 'hi_test 3.25\nhi_test2{hi="label",hi2="label2"} 2.5\n'
2022-12-26 21:49:07 +01:00
}
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('hi_', m)
2022-12-26 21:49:07 +01:00
assert e.export_to_string()! == 'hi_test_count 1\nhi_test_sum 5.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\n'
2022-12-26 21:49:07 +01:00
}