fix(alerts): исключить переходы между неоднозначными BGP peers

This commit is contained in:
Denozordec committed 2026-10-12 10:27:41 +07:00
1 parent 22b0e8ae8e
commit c557a8c8cb
11 files changed
+1142 -15

No files matched your search

@@ -8,14 +8,23 @@ export function isKnownBgpState(state: string): boolean {
/** Runs arrive newest first. Keep current unknown, but use the last known previous state. */
export function collectBgpSignalsFromRuns(runs: GreBgpSnapshotRunSnapshot[]): BgpPeerSignal[] {
const byKey = new Map<string, BgpPeerSignal>()
const ambiguousHistory = new Set<string>()
for (const run of runs) {
const batch = new Map<string, string>()
const duplicates = new Set<string>()
for (const row of run.bgpPeers ?? []) {
const key = String(row.key ?? "").trim()
if (!key) continue
const state = String(row.state ?? "").trim()
if (batch.has(key)) duplicates.add(key)
batch.set(key, state)
}
for (const [key, state] of batch) {
const duplicate = duplicates.has(key)
const current = byKey.get(key)
if (!current) byKey.set(key, { key, state, prevState: null })
else if (current.prevState === null && isKnownBgpState(state)) current.prevState = state
if (!current) byKey.set(key, { key, state: duplicate ? "Unknown" : state, prevState: null })
else if (!duplicate && !ambiguousHistory.has(key) && current.prevState === null && isKnownBgpState(state)) current.prevState = state
if (duplicate) ambiguousHistory.add(key)
}
}
return [...byKey.values()]
@@ -135,6 +135,19 @@ for (const [history, expectedPrevious, recoveryExpected] of [
assert.equal(evaluateRule(recovery, emptySnap({ bgpSessions: signals })) !== null, recoveryExpected)
}
for (const pair of [["Established", "Idle"], ["Established", "Established"], ["Unknown", "Idle"]]) {
const runs = [{ bgpPeers: pair.map(state => ({ key: "srv: peer1", state })) }] as GreBgpSnapshotRunSnapshot[]
assert.deepEqual(collectBgpSignalsFromRuns(runs), [{ key: "srv: peer1", state: "Unknown", prevState: null }])
}
{
const runs = [
{ bgpPeers: [{ key: "srv: peer1", state: "Established" }] },
{ bgpPeers: [{ key: "srv: peer1", state: "Established" }, { key: "srv: peer1", state: "Idle" }] },
{ bgpPeers: [{ key: "srv: peer1", state: "Idle" }] },
] as GreBgpSnapshotRunSnapshot[]
assert.deepEqual(collectBgpSignalsFromRuns(runs), [{ key: "srv: peer1", state: "Established", prevState: null }])
}
{
const r = rule({
id: "srv-rec",