metrics/prometheus_test.v

52 lines
1.2 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_buckets_set('test', [0.5, 5.0])
2022-12-26 21:49:07 +01:00
m.histogram_record(5.0, name: 'test')
2023-01-04 10:31:48 +01:00
m.histogram_record(7.0, name: 'test')
2022-12-26 21:49:07 +01:00
mut e := new_prometheus_exporter()
e.load('hi_', m)
2022-12-26 21:49:07 +01:00
2023-01-04 10:31:48 +01:00
assert e.export_to_string()! == 'hi_test_count 2\nhi_test_sum 12.0\nhi_test_bucket{le="0.5"} 0\nhi_test_bucket{le="5.0"} 1\nhi_test_bucket{le="+Inf"} 2\n'
2022-12-26 21:49:07 +01:00
}