106 lines
2.2 KiB
V
106 lines
2.2 KiB
V
module metrics
|
|
|
|
fn test_implements_interface() {
|
|
_ := MetricsCollector(new_default_collector())
|
|
}
|
|
|
|
fn test_null_implements_interface() {
|
|
_ := MetricsCollector(new_null_collector())
|
|
}
|
|
|
|
fn test_counter_increment() {
|
|
mut m := new_default_collector()
|
|
|
|
m.counter_increment(name: 'test')
|
|
assert m.counter_get(name: 'test')? == u64(1)
|
|
|
|
m.counter_increment(name: 'test')
|
|
assert m.counter_get(name: 'test')? == u64(2)
|
|
|
|
// Test with labels
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
|
|
m.counter_set(15, metric)
|
|
m.counter_increment(metric)
|
|
assert m.counter_get(metric)? == u64(16)
|
|
}
|
|
|
|
fn test_histogram() {
|
|
mut m := new_default_collector()
|
|
|
|
m.histogram_record(5.0, name: 'test')
|
|
assert m.histogram_get(name: 'test')? == [5.0]
|
|
|
|
m.histogram_record(7.0, name: 'test')
|
|
assert m.histogram_get(name: 'test')? == [5.0, 7.0]
|
|
|
|
// Test with labels
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
|
|
m.histogram_record(5.0, metric)
|
|
assert m.histogram_get(metric)? == [5.0]
|
|
|
|
m.histogram_record(7.0, metric)
|
|
assert m.histogram_get(metric)? == [5.0, 7.0]
|
|
}
|
|
|
|
fn test_gauge_add() {
|
|
mut m := new_default_collector()
|
|
|
|
m.gauge_add(5.0, name: 'test')
|
|
assert m.gauge_get(name: 'test')? == 5.0
|
|
|
|
// Test with labels
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
|
|
m.gauge_set(3.0, metric)
|
|
m.gauge_add(5.0, metric)
|
|
assert m.gauge_get(metric)? == 8.0
|
|
}
|
|
|
|
fn test_gauge_sub() {
|
|
mut m := new_default_collector()
|
|
|
|
m.gauge_sub(5.0, name: 'test')
|
|
assert m.gauge_get(name: 'test')? == -5.0
|
|
|
|
// Test with labels
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
|
|
m.gauge_set(3.0, metric)
|
|
m.gauge_sub(5.0, metric)
|
|
assert m.gauge_get(metric)? == -2.0
|
|
}
|
|
|
|
fn test_gauge_set() {
|
|
mut m := new_default_collector()
|
|
|
|
m.gauge_set(3.0, name: 'test')
|
|
assert m.gauge_get(name: 'test')? == 3.0
|
|
m.gauge_set(5.0, name: 'test')
|
|
assert m.gauge_get(name: 'test')? == 5.0
|
|
|
|
// Test with labels
|
|
metric := Metric{
|
|
name: 'test2'
|
|
labels: [['hi', 'label']!, ['hi2', 'label2']!]
|
|
}
|
|
|
|
m.gauge_set(3.0, metric)
|
|
assert m.gauge_get(metric)? == 3.0
|
|
m.gauge_set(5.0, metric)
|
|
assert m.gauge_get(metric)? == 5.0
|
|
}
|