- Added a new field `badConnBaseline` in the `Handler` struct to store the baseline for bad connections. - Updated the `BuildIncidents` function to utilize the effective bad connections count for incident generation. - Introduced a new API endpoint `/api/agg/bad-connections/reset` to reset the bad connections baseline. - Enhanced the frontend with a button to trigger the reset action, providing user feedback through toast notifications. - Updated Svelte components to handle the reset functionality and display appropriate messages based on the operation's success or failure.
25 lines
670 B
Go
25 lines
670 B
Go
package aggregate
|
|
|
|
import "testing"
|
|
|
|
func TestEffectiveConnectionsBad(t *testing.T) {
|
|
h := &Handler{}
|
|
|
|
if got := h.effectiveConnectionsBad("a", 500); got != 500 {
|
|
t.Fatalf("without baseline want 500, got %d", got)
|
|
}
|
|
|
|
h.setBadConnectionBaseline("a", 400)
|
|
if got := h.effectiveConnectionsBad("a", 900); got != 500 {
|
|
t.Fatalf("with baseline 400 want delta 500, got %d", got)
|
|
}
|
|
|
|
h.setBadConnectionBaseline("b", 1000)
|
|
if got := h.effectiveConnectionsBad("b", 500); got != 500 {
|
|
t.Fatalf("after counter drop want raw value 500, got %d", got)
|
|
}
|
|
if _, ok := h.badConnBaseline["b"]; ok {
|
|
t.Fatal("baseline for b should be cleared when current < baseline")
|
|
}
|
|
}
|