Compare commits
No commits in common. "wt/t_f1593f8c" and "main" have entirely different histories.
wt/t_f1593
...
main
@ -162,7 +162,11 @@ func (t *telemetry) RecordInventory(inv api.InventoryResponse) {
|
|||||||
}
|
}
|
||||||
reasonLabels["reason"] = reason
|
reasonLabels["reason"] = reason
|
||||||
setMetric(t.pvcBackupHealthReason, reasonLabels, 1)
|
setMetric(t.pvcBackupHealthReason, reasonLabels, 1)
|
||||||
setMetric(t.pvcBackupHealth, labels, boolGauge(pvc.Healthy))
|
if pvc.Healthy {
|
||||||
|
setMetric(t.pvcBackupHealth, labels, 1)
|
||||||
|
} else {
|
||||||
|
setMetric(t.pvcBackupHealth, labels, 0)
|
||||||
|
}
|
||||||
if pvc.LastBackupAt == "" {
|
if pvc.LastBackupAt == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -321,15 +325,6 @@ func incMetric(target map[string]metricSample, labels map[string]string) {
|
|||||||
target[key] = sample
|
target[key] = sample
|
||||||
}
|
}
|
||||||
|
|
||||||
// boolGauge converts a boolean state into the Prometheus gauge convention of
|
|
||||||
// 1 for true and 0 for false.
|
|
||||||
func boolGauge(value bool) float64 {
|
|
||||||
if value {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func setMetric(target map[string]metricSample, labels map[string]string, value float64) {
|
func setMetric(target map[string]metricSample, labels map[string]string, value float64) {
|
||||||
key := metricKey(labels)
|
key := metricKey(labels)
|
||||||
target[key] = metricSample{labels: cloneLabels(labels), value: value}
|
target[key] = metricSample{labels: cloneLabels(labels), value: value}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -161,55 +160,6 @@ func TestTelemetryRecordInventoryPopulatesAndResetsMetrics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBoolGaugeMapsHealthToPrometheusValues(t *testing.T) {
|
|
||||||
if got := boolGauge(true); got != 1 {
|
|
||||||
t.Fatalf("expected boolGauge(true) to be 1, got %v", got)
|
|
||||||
}
|
|
||||||
if got := boolGauge(false); got != 0 {
|
|
||||||
t.Fatalf("expected boolGauge(false) to be 0, got %v", got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTelemetryRecordInventoryHealthGaugeIdentity(t *testing.T) {
|
|
||||||
telemetry := newTelemetry()
|
|
||||||
|
|
||||||
telemetry.RecordInventory(api.InventoryResponse{
|
|
||||||
Namespaces: []api.NamespaceInventory{
|
|
||||||
{
|
|
||||||
Name: "apps",
|
|
||||||
PVCs: []api.PVCInventory{
|
|
||||||
{
|
|
||||||
Namespace: "apps",
|
|
||||||
PVC: "data",
|
|
||||||
Volume: "pv-apps-data",
|
|
||||||
Driver: "restic",
|
|
||||||
Healthy: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Namespace: "apps",
|
|
||||||
PVC: "cache",
|
|
||||||
Volume: "pv-apps-cache",
|
|
||||||
Driver: "longhorn",
|
|
||||||
Healthy: false,
|
|
||||||
HealthReason: "stale",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
rendered := telemetry.render()
|
|
||||||
for _, line := range []string{
|
|
||||||
"# TYPE pvc_backup_health gauge",
|
|
||||||
`pvc_backup_health{driver="restic",namespace="apps",pvc="data",volume="pv-apps-data"} 1`,
|
|
||||||
`pvc_backup_health{driver="longhorn",namespace="apps",pvc="cache",volume="pv-apps-cache"} 0`,
|
|
||||||
} {
|
|
||||||
if !strings.Contains(rendered, line+"\n") {
|
|
||||||
t.Fatalf("expected rendered metrics to contain %q, got:\n%s", line, rendered)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTelemetryRecordB2UsageTracksBucketsAndFallbackTimestamp(t *testing.T) {
|
func TestTelemetryRecordB2UsageTracksBucketsAndFallbackTimestamp(t *testing.T) {
|
||||||
telemetry := newTelemetry()
|
telemetry := newTelemetry()
|
||||||
scannedAt := time.Date(2026, 4, 20, 16, 30, 0, 0, time.UTC)
|
scannedAt := time.Date(2026, 4, 20, 16, 30, 0, 0, time.UTC)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user