Add iplist_size metric

This commit is contained in:
9seconds
2022-03-11 16:20:11 +03:00
parent 4687a7c899
commit 30170b9413
19 changed files with 206 additions and 26 deletions
+20
View File
@@ -92,6 +92,15 @@ type EventReplayAttack struct {
eventBase
}
// EventIPListSize is emitted when mtg updates a contents of the ip lists:
// allowlist or blocklist.
type EventIPListSize struct {
eventBase
Size int
IsBlockList bool
}
// NewEventStart creates a new EventStart event.
func NewEventStart(streamID string, remoteIP net.IP) EventStart {
return EventStart{
@@ -176,3 +185,14 @@ func NewEventReplayAttack(streamID string) EventReplayAttack {
},
}
}
// NewEventIPListSize creates a new EventIPListSize event.
func NewEventIPListSize(size int, isBlockList bool) EventIPListSize {
return EventIPListSize{
eventBase: eventBase{
timestamp: time.Now(),
},
Size: size,
IsBlockList: isBlockList,
}
}
+9
View File
@@ -69,6 +69,15 @@ func (suite *EventsTestSuite) TestEventReplayAttack() {
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
}
func (suite *EventsTestSuite) TestEventIPListSize() {
evt := mtglib.NewEventIPListSize(10, false)
suite.Empty(evt.StreamID())
suite.WithinDuration(time.Now(), evt.Timestamp(), 10*time.Millisecond)
suite.Equal(10, evt.Size)
suite.False(evt.IsBlockList)
}
func TestEvents(t *testing.T) {
t.Parallel()
suite.Run(t, &EventsTestSuite{})