68 lines
2.6 KiB
Go
68 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNetworkDropsDoNotAlert(t *testing.T) {
|
|
for _, name := range []string{"enp6s0", "vmbr0", "fwbr100i0", "tap100i0"} {
|
|
v := NetworkInterface{Name: name, Carrier: true, State: "up", NewDrops: 15, NewReceiveDrops: 15}
|
|
metrics := dashboardMetrics{Network: NetworkMetrics{Interfaces: []NetworkInterface{v}}}
|
|
for _, a := range evaluateAlerts(metrics, AlertThresholds{}) {
|
|
if a.ID == "network-errors" {
|
|
t.Fatalf("%s: drops triggered alert", name)
|
|
}
|
|
}
|
|
v.NewErrors = 1
|
|
metrics.Network.Interfaces[0] = v
|
|
found := false
|
|
for _, a := range evaluateAlerts(metrics, AlertThresholds{}) {
|
|
if a.ID == "network-errors" {
|
|
found = a.Severity == "critical"
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("%s: errors did not trigger critical alert", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNetworkHardwareFaultAndLinkAlerts(t *testing.T) {
|
|
for _, v := range []NetworkInterface{{Name: "eth0", NewFaults: 1}, {Name: "eth0", LinkDown: true}} {
|
|
found := false
|
|
for _, a := range evaluateAlerts(dashboardMetrics{Network: NetworkMetrics{Interfaces: []NetworkInterface{v}}}, AlertThresholds{}) {
|
|
if strings.HasPrefix(a.ID, "network-") && a.Severity == "critical" {
|
|
found = true
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("no critical alert for %+v", v)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNetworkCounterResetsAndFaultBaselines(t *testing.T) {
|
|
old := NetworkInterface{ReceiveBytes: 100, ReceiveErrors: 20, TransmitErrors: 4, ReceiveDrops: 8, FaultCounters: map[string]uint64{"rx_missed_errors": 10, "atlantic:InErrors": 9}, Carrier: true}
|
|
next := NetworkInterface{ReceiveBytes: 1, ReceiveErrors: 1, TransmitErrors: 6, ReceiveDrops: 10, FaultCounters: map[string]uint64{"rx_missed_errors": 12, "atlantic:InErrors": 1, "new": 100}, Carrier: false}
|
|
updateInterfaceDeltas(&next, old, 2)
|
|
if next.NewErrors != 2 || next.NewFaults != 2 || next.NewReceiveDrops != 2 || next.ReceivePerSec != 0 || !next.LinkDown {
|
|
t.Fatalf("bad deltas: %+v", next)
|
|
}
|
|
}
|
|
|
|
func TestAtlanticFaults(t *testing.T) {
|
|
got := parseAtlanticFaults("NIC statistics:\n InErrors: 2\n InDroppedDma: 3\n Queue[0] AllocFails: 4\n Queue[1] SkbAllocFails: 5\n Queue[0] Restarts: 6\n Queue[0] InErrors: 7\n InPackets: 100\n Queue[0] XdpDrop: 50\n InErrorsBad: nope")
|
|
if len(got) != 6 || got["InDroppedDma"] != 3 || got["Queue[0] Restarts"] != 6 {
|
|
t.Fatalf("bad counters: %v", got)
|
|
}
|
|
}
|
|
|
|
func TestFirewallNotAttributedToGuest(t *testing.T) {
|
|
n := NetworkMetrics{Interfaces: []NetworkInterface{{Name: "fwbr100i0", ReceiveDrops: 100}, {Name: "tap100i0"}}}
|
|
decorateNetworkInterfaces(&n, GuestsMetrics{})
|
|
if n.Interfaces[0].VMID != 0 || n.Interfaces[1].VMID != 100 {
|
|
t.Fatalf("bad VM attribution: %+v", n)
|
|
}
|
|
}
|