test: add ha_status collector test and fixtures
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
d458894b0e
commit
16cfba4587
3 changed files with 62 additions and 0 deletions
1
collector/fixtures/ha_manager_status.json
Normal file
1
collector/fixtures/ha_manager_status.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"data":{"manager_status":{"master_node":"node03","node_status":{"node01":"online","node02":"online","node03":"online"},"service_status":{"vm:106":{"node":"node01","running":1,"state":"started"}}},"lrm_status":{"node01":{"mode":"active","state":"active","timestamp":1774016350},"node02":{"mode":"active","state":"wait_for_agent_lock","timestamp":1774016351},"node03":{"mode":"active","state":"wait_for_agent_lock","timestamp":1774016351}}}}
|
||||
1
collector/fixtures/ha_resources.json
Normal file
1
collector/fixtures/ha_resources.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"data":[{"sid":"vm:106","type":"vm","state":"started","max_restart":2,"max_relocate":2,"failback":1}]}
|
||||
60
collector/ha_status_test.go
Normal file
60
collector/ha_status_test.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package collector
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||
)
|
||||
|
||||
func TestHAStatusCollector(t *testing.T) {
|
||||
client := newTestClient(t, map[string]string{
|
||||
"/cluster/ha/status/manager_status": "ha_manager_status.json",
|
||||
"/cluster/ha/resources": "ha_resources.json",
|
||||
})
|
||||
|
||||
collector := newHAStatusCollector(slog.Default())
|
||||
adapter := &testCollectorAdapter{client: client, collector: collector}
|
||||
|
||||
reg := prometheus.NewRegistry()
|
||||
reg.MustRegister(adapter)
|
||||
|
||||
expected := `
|
||||
# HELP pve_ha_crm_master Whether a node is the CRM master.
|
||||
# TYPE pve_ha_crm_master gauge
|
||||
pve_ha_crm_master{node="node01"} 0
|
||||
pve_ha_crm_master{node="node02"} 0
|
||||
pve_ha_crm_master{node="node03"} 1
|
||||
# HELP pve_ha_lrm_mode LRM mode for a node.
|
||||
# TYPE pve_ha_lrm_mode gauge
|
||||
pve_ha_lrm_mode{mode="active",node="node01"} 1
|
||||
pve_ha_lrm_mode{mode="active",node="node02"} 1
|
||||
pve_ha_lrm_mode{mode="active",node="node03"} 1
|
||||
# HELP pve_ha_lrm_timestamp_seconds Last LRM heartbeat as Unix timestamp.
|
||||
# TYPE pve_ha_lrm_timestamp_seconds gauge
|
||||
pve_ha_lrm_timestamp_seconds{node="node01"} 1.77401635e+09
|
||||
pve_ha_lrm_timestamp_seconds{node="node02"} 1.774016351e+09
|
||||
pve_ha_lrm_timestamp_seconds{node="node03"} 1.774016351e+09
|
||||
# HELP pve_ha_node_status HA node status.
|
||||
# TYPE pve_ha_node_status gauge
|
||||
pve_ha_node_status{node="node01",status="online"} 1
|
||||
pve_ha_node_status{node="node02",status="online"} 1
|
||||
pve_ha_node_status{node="node03",status="online"} 1
|
||||
# HELP pve_ha_service_config HA service configuration.
|
||||
# TYPE pve_ha_service_config gauge
|
||||
pve_ha_service_config{failback="1",max_relocate="2",max_restart="2",sid="vm:106",type="vm"} 1
|
||||
# HELP pve_ha_service_status HA service runtime status.
|
||||
# TYPE pve_ha_service_status gauge
|
||||
pve_ha_service_status{node="node01",sid="vm:106",state="started"} 1
|
||||
`
|
||||
|
||||
if err := testutil.GatherAndCompare(reg, strings.NewReader(expected),
|
||||
"pve_ha_crm_master", "pve_ha_node_status",
|
||||
"pve_ha_lrm_timestamp_seconds", "pve_ha_lrm_mode",
|
||||
"pve_ha_service_config", "pve_ha_service_status",
|
||||
); err != nil {
|
||||
t.Errorf("unexpected metrics: %s", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue