49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package metrics
|
|
|
|
import (
|
|
"bytes"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestPromCounters(t *testing.T) {
|
|
p := NewProm()
|
|
p.Prediction("standard_profile", 100*time.Millisecond, nil)
|
|
p.Prediction("standard_profile", 200*time.Millisecond, nil)
|
|
p.Prediction("float_profile", 50*time.Millisecond, nil)
|
|
|
|
var buf bytes.Buffer
|
|
p.Write(&buf)
|
|
out := buf.String()
|
|
|
|
if !strings.Contains(out, `predictor_predictions_total{profile="standard_profile",status="ok"} 2`) {
|
|
t.Errorf("expected count=2 for standard_profile, got: %s", out)
|
|
}
|
|
if !strings.Contains(out, `predictor_predictions_total{profile="float_profile",status="ok"} 1`) {
|
|
t.Errorf("expected count=1 for float_profile, got: %s", out)
|
|
}
|
|
// Sum of durations: 0.1 + 0.2 = 0.3 seconds.
|
|
if !strings.Contains(out, "predictor_prediction_duration_seconds_sum") {
|
|
t.Errorf("expected sum present, got: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestPromGauge(t *testing.T) {
|
|
p := NewProm()
|
|
p.ActiveEpoch(time.Unix(1700000000, 0))
|
|
|
|
var buf bytes.Buffer
|
|
p.Write(&buf)
|
|
out := buf.String()
|
|
if !strings.Contains(out, "predictor_active_dataset_epoch_seconds 1.7e+09") {
|
|
t.Errorf("expected gauge with epoch 1700000000, got: %s", out)
|
|
}
|
|
}
|
|
|
|
func TestNoop(t *testing.T) {
|
|
sink := Noop()
|
|
sink.Prediction("any", time.Second, nil)
|
|
sink.Download("any", time.Second, "complete", 0)
|
|
sink.ActiveEpoch(time.Now())
|
|
}
|