Skip to content

Commit 332ea97

Browse files
committed
fix(metrics): get network operational status from APPL_DB instead of STATE_DB, as APPL_DB is correct regarding the hardware's state.
1 parent cf431e7 commit 332ea97

2 files changed

Lines changed: 28 additions & 28 deletions

File tree

internal/agent/metrics/interfaces.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ func (c *InterfaceCollector) Collect(ch chan<- prometheus.Metric) {
6868
return
6969
}
7070

71-
stateDB, err := c.connector.Connect("STATE_DB")
71+
applDB, err := c.connector.Connect("APPL_DB")
7272
if err != nil {
73-
log.Printf("InterfaceCollector: failed to connect to STATE_DB: %v", err)
73+
log.Printf("InterfaceCollector: failed to connect to APPL_DB: %v", err)
7474
return
7575
}
7676

@@ -94,7 +94,7 @@ func (c *InterfaceCollector) Collect(ch chan<- prometheus.Metric) {
9494
stateKeys = append(stateKeys, "PORT_TABLE:"+name)
9595
}
9696

97-
stateData := batchHGetAll(ctx, stateDB, stateKeys)
97+
stateData := batchHGetAll(ctx, applDB, stateKeys)
9898

9999
upCount := 0
100100
downCount := 0
@@ -103,7 +103,7 @@ func (c *InterfaceCollector) Collect(ch chan<- prometheus.Metric) {
103103
stateKey := stateKeys[i]
104104
fields := stateData[stateKey]
105105

106-
operUp := fields["netdev_oper_status"] == "up"
106+
operUp := fields["oper_status"] == "up"
107107
adminUp := fields["admin_status"] == "up"
108108

109109
operVal := 0.0

internal/agent/metrics/metrics_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,18 @@ func TestDeviceCollectorNotReady(t *testing.T) {
136136
// --- Interface Collector Tests ---
137137

138138
func TestInterfaceCollector(t *testing.T) {
139-
mc := newMockConnector("CONFIG_DB", "STATE_DB")
139+
mc := newMockConnector("CONFIG_DB", "APPL_DB")
140140

141141
mc.mocks["CONFIG_DB"].ExpectKeys("PORT|*").SetVal([]string{
142142
"PORT|Ethernet0", "PORT|Ethernet4",
143143
})
144-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet0").SetVal(map[string]string{
145-
"netdev_oper_status": "up",
146-
"admin_status": "up",
144+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet0").SetVal(map[string]string{
145+
"oper_status": "up",
146+
"admin_status": "up",
147147
})
148-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet4").SetVal(map[string]string{
149-
"netdev_oper_status": "down",
150-
"admin_status": "up",
148+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet4").SetVal(map[string]string{
149+
"oper_status": "down",
150+
"admin_status": "up",
151151
})
152152

153153
collector := NewInterfaceCollector(mc)
@@ -164,22 +164,22 @@ func TestInterfaceCollector(t *testing.T) {
164164
}
165165

166166
func TestInterfaceCollectorInterfaceTotals(t *testing.T) {
167-
mc := newMockConnector("CONFIG_DB", "STATE_DB")
167+
mc := newMockConnector("CONFIG_DB", "APPL_DB")
168168

169169
mc.mocks["CONFIG_DB"].ExpectKeys("PORT|*").SetVal([]string{
170170
"PORT|Ethernet0", "PORT|Ethernet4", "PORT|Ethernet8",
171171
})
172-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet0").SetVal(map[string]string{
173-
"netdev_oper_status": "up",
174-
"admin_status": "up",
172+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet0").SetVal(map[string]string{
173+
"oper_status": "up",
174+
"admin_status": "up",
175175
})
176-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet4").SetVal(map[string]string{
177-
"netdev_oper_status": "up",
178-
"admin_status": "up",
176+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet4").SetVal(map[string]string{
177+
"oper_status": "up",
178+
"admin_status": "up",
179179
})
180-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet8").SetVal(map[string]string{
181-
"netdev_oper_status": "down",
182-
"admin_status": "down",
180+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet8").SetVal(map[string]string{
181+
"oper_status": "down",
182+
"admin_status": "down",
183183
})
184184

185185
collector := NewInterfaceCollector(mc)
@@ -1233,18 +1233,18 @@ func TestConfigValidationRegexInvalidPattern(t *testing.T) {
12331233
// --- Interface Collector Per-Interface State Tests ---
12341234

12351235
func TestInterfaceCollectorPerInterfaceState(t *testing.T) {
1236-
mc := newMockConnector("CONFIG_DB", "STATE_DB")
1236+
mc := newMockConnector("CONFIG_DB", "APPL_DB")
12371237

12381238
mc.mocks["CONFIG_DB"].ExpectKeys("PORT|*").SetVal([]string{
12391239
"PORT|Ethernet0", "PORT|Ethernet4",
12401240
})
1241-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet0").SetVal(map[string]string{
1242-
"netdev_oper_status": "up",
1243-
"admin_status": "up",
1241+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet0").SetVal(map[string]string{
1242+
"oper_status": "up",
1243+
"admin_status": "up",
12441244
})
1245-
mc.mocks["STATE_DB"].ExpectHGetAll("PORT_TABLE|Ethernet4").SetVal(map[string]string{
1246-
"netdev_oper_status": "down",
1247-
"admin_status": "up",
1245+
mc.mocks["APPL_DB"].ExpectHGetAll("PORT_TABLE:Ethernet4").SetVal(map[string]string{
1246+
"oper_status": "down",
1247+
"admin_status": "up",
12481248
})
12491249

12501250
collector := NewInterfaceCollector(mc)

0 commit comments

Comments
 (0)