Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
52 lines
2.1 KiB
Go
52 lines
2.1 KiB
Go
package collector
|
|
|
|
import (
|
|
"log/slog"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
|
)
|
|
|
|
func TestReplicationCollector(t *testing.T) {
|
|
client := newTestClient(t, map[string]string{
|
|
"/nodes/node01/replication": "node_replication.json",
|
|
})
|
|
|
|
collector := newReplicationCollector(slog.Default())
|
|
collector.SetNodes([]string{"node01"})
|
|
adapter := &testCollectorAdapter{client: client, collector: collector}
|
|
|
|
reg := prometheus.NewRegistry()
|
|
reg.MustRegister(adapter)
|
|
|
|
expected := `
|
|
# HELP pve_replication_duration_seconds Duration of the last replication in seconds.
|
|
# TYPE pve_replication_duration_seconds gauge
|
|
pve_replication_duration_seconds{id="100-0"} 5.2
|
|
# HELP pve_replication_failed_syncs Number of failed replication syncs.
|
|
# TYPE pve_replication_failed_syncs gauge
|
|
pve_replication_failed_syncs{id="100-0"} 0
|
|
# HELP pve_replication_info Replication job information.
|
|
# TYPE pve_replication_info gauge
|
|
pve_replication_info{guest="100",id="100-0",source="node01",target="node02",type="local"} 1
|
|
# HELP pve_replication_last_sync_timestamp_seconds Timestamp of the last successful replication sync.
|
|
# TYPE pve_replication_last_sync_timestamp_seconds gauge
|
|
pve_replication_last_sync_timestamp_seconds{id="100-0"} 1.71e+09
|
|
# HELP pve_replication_last_try_timestamp_seconds Timestamp of the last replication attempt.
|
|
# TYPE pve_replication_last_try_timestamp_seconds gauge
|
|
pve_replication_last_try_timestamp_seconds{id="100-0"} 1.71000006e+09
|
|
# HELP pve_replication_next_sync_timestamp_seconds Timestamp of the next scheduled replication sync.
|
|
# TYPE pve_replication_next_sync_timestamp_seconds gauge
|
|
pve_replication_next_sync_timestamp_seconds{id="100-0"} 1.7100036e+09
|
|
`
|
|
|
|
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
|
"pve_replication_info", "pve_replication_duration_seconds",
|
|
"pve_replication_last_sync_timestamp_seconds", "pve_replication_last_try_timestamp_seconds",
|
|
"pve_replication_next_sync_timestamp_seconds", "pve_replication_failed_syncs",
|
|
); err != nil {
|
|
t.Errorf("unexpected metrics: %s", err)
|
|
}
|
|
}
|