~bigbes/lethe

ref: e108b3e06984223f9489e5dcf1f22ed60ae8adb7 lethe/internal/platform/observability/metrics_test.go -rw-r--r-- 1.1 KiB
e108b3e0 — Eugene Blikh feat(session): list and detail JSON API with filters a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package observability

import (
	"context"
	"testing"
)

// TestMetricsInit confirms Init returns nil and every counter/vec is wired.
// We deliberately do not assert on Prometheus exposition format — that's an
// integration concern handled when the /metrics endpoint lands in Phase 5.
func TestMetricsInit(t *testing.T) {
	m := &Metrics{}
	if err := m.Init(context.Background()); err != nil {
		t.Fatalf("Init: %v", err)
	}
	if m.Registry == nil {
		t.Fatal("Registry is nil")
	}
	if m.HTTPRequests == nil {
		t.Fatal("HTTPRequests is nil")
	}
	if m.HTTPDuration == nil {
		t.Fatal("HTTPDuration is nil")
	}
	if m.IngestLinesAccepted == nil {
		t.Fatal("IngestLinesAccepted is nil")
	}
	if m.IngestLinesErrored == nil {
		t.Fatal("IngestLinesErrored is nil")
	}
	if m.IngestChunksCommitted == nil {
		t.Fatal("IngestChunksCommitted is nil")
	}

	// Sanity: increments/observations don't panic.
	m.HTTPRequests.WithLabelValues("GET", "/healthz", "200").Inc()
	m.HTTPDuration.WithLabelValues("GET", "/healthz").Observe(0.001)
	m.IngestLinesAccepted.Inc()
	m.IngestLinesErrored.Inc()
	m.IngestChunksCommitted.Inc()
}