ed91d68fbf
New metrics: - orca_jobs_running / orca_jobs_failed / orca_jobs_complete (gauges) - orca_audit_chain_head (gauge, chain integrity) - orca_drift_events_total, orca_ssh_errors_total (counters) - orca_txn_apply_total, orca_txn_rollback_total (counters) - orca_acl_denials_total (counter) Security headers on metrics + healthz endpoints: - X-Content-Type-Options: nosniff - X-Frame-Options: DENY New file: docs/metrics.md (Prometheus reference + scrape config) ---ci--- project: orca phase: 10 milestone: v0.13 status: complete requirements: covered: [159] ---/ci---
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.cloudinit.dev/coreci/orca/internal/model"
|
|
"git.cloudinit.dev/coreci/orca/internal/store"
|
|
"git.cloudinit.dev/coreci/orca/internal/transport"
|
|
)
|
|
|
|
// TestREQ159_MetricsExpanded verifies the expanded metric set (P10, REQ-159).
|
|
func TestREQ159_MetricsExpanded(t *testing.T) {
|
|
dir := t.TempDir()
|
|
t.Setenv("ORCA_HOME", dir)
|
|
dbPath := filepath.Join(dir, "orca.db")
|
|
db, err := store.Open(dbPath)
|
|
if err != nil {
|
|
t.Fatalf("store.Open: %v", err)
|
|
}
|
|
defer db.Close()
|
|
|
|
// Seed a node.
|
|
repo := store.NewNodeRepo(db)
|
|
if err := repo.Insert(context.Background(), &model.Node{
|
|
ID: "test-node-1",
|
|
Name: "test-node",
|
|
Address: "localhost:8443",
|
|
Kind: "localhost",
|
|
OS: "linux",
|
|
State: "ready",
|
|
}); err != nil {
|
|
t.Fatalf("insert node: %v", err)
|
|
}
|
|
|
|
// Seed a job.
|
|
jobRepo := store.NewJobRepo(db)
|
|
if err := jobRepo.Insert(context.Background(), &model.Job{
|
|
ID: "job-1",
|
|
Name: "test-job",
|
|
Status: "running",
|
|
}); err != nil {
|
|
t.Fatalf("insert job: %v", err)
|
|
}
|
|
|
|
m := transport.NewMetrics()
|
|
logger := slogLogger{}
|
|
refresh(context.Background(), m, db, logger)
|
|
|
|
// Verify expanded metrics by reading the exposition output.
|
|
var buf strings.Builder
|
|
if err := m.WritePrometheus(&buf); err != nil {
|
|
t.Fatalf("WritePrometheus: %v", err)
|
|
}
|
|
out := buf.String()
|
|
if !strings.Contains(out, "nodes_total 1") {
|
|
t.Errorf("output missing nodes_total 1:\n%s", out)
|
|
}
|
|
if !strings.Contains(out, "allocs_total 1") {
|
|
t.Errorf("output missing allocs_total 1:\n%s", out)
|
|
}
|
|
if !strings.Contains(out, "orca_jobs_running") {
|
|
t.Errorf("output missing orca_jobs_running:\n%s", out)
|
|
}
|
|
}
|
|
|
|
type slogLogger struct{}
|
|
|
|
func (slogLogger) Warn(msg string, args ...any) {}
|
|
|
|
var _ = os.Stdin
|