nflog: Fix Log() crash when gossip is nil (#1064)
This commit is contained in:
parent
359b614f5f
commit
fc984941ee
|
@ -360,9 +360,11 @@ func (l *nlog) Log(r *pb.Receiver, gkey string, firingAlerts, resolvedAlerts []u
|
||||||
},
|
},
|
||||||
ExpiresAt: now.Add(l.retention),
|
ExpiresAt: now.Add(l.retention),
|
||||||
}
|
}
|
||||||
l.gossip.GossipBroadcast(gossipData{
|
if l.gossip != nil {
|
||||||
key: e,
|
l.gossip.GossipBroadcast(gossipData{
|
||||||
})
|
key: e,
|
||||||
|
})
|
||||||
|
}
|
||||||
l.st[key] = e
|
l.st[key] = e
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -264,3 +264,12 @@ func TestGossipDataCoding(t *testing.T) {
|
||||||
require.Equal(t, in, out, "decoded data doesn't match encoded data")
|
require.Equal(t, in, out, "decoded data doesn't match encoded data")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNilGossipDoesNotCrash(t *testing.T) {
|
||||||
|
nl, err := New()
|
||||||
|
if err != nil {
|
||||||
|
require.NoError(t, err, "constructing nflog failed")
|
||||||
|
}
|
||||||
|
err = nl.Log(&pb.Receiver{}, "key", []uint64{}, []uint64{})
|
||||||
|
require.NoError(t, err, "logging notification failed")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue