mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Add iplist_size metric
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user