mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 13:54:02 +03:00
Add EventReplayAttack
This commit is contained in:
+5
-1
@@ -110,10 +110,14 @@ func (p prometheusProcessor) EventConcurrencyLimited(_ mtglib.EventConcurrencyLi
|
||||
p.factory.metricConcurrencyLimited.Inc()
|
||||
}
|
||||
|
||||
func (p prometheusProcessor) EventIPBlocklisted(evt mtglib.EventIPBlocklisted) {
|
||||
func (p prometheusProcessor) EventIPBlocklisted(_ mtglib.EventIPBlocklisted) {
|
||||
p.factory.metricIPBlocklisted.Inc()
|
||||
}
|
||||
|
||||
func (p prometheusProcessor) EventReplayAttack(_ mtglib.EventReplayAttack) {
|
||||
p.factory.metricReplayAttacks.Inc()
|
||||
}
|
||||
|
||||
func (p prometheusProcessor) Shutdown() {
|
||||
for _, v := range p.streams {
|
||||
releaseStreamInfo(v)
|
||||
|
||||
@@ -198,6 +198,19 @@ func (suite *PrometheusTestSuite) TestEventIPBlocklisted() {
|
||||
suite.Contains(data, `mtg_ip_blocklisted 1`)
|
||||
}
|
||||
|
||||
func (suite *PrometheusTestSuite) TestEventReplayAttack() {
|
||||
suite.prometheus.EventReplayAttack(mtglib.EventReplayAttack{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: "connID",
|
||||
})
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
data, err := suite.Get()
|
||||
suite.NoError(err)
|
||||
suite.Contains(data, `mtg_replay_attacks 1`)
|
||||
}
|
||||
|
||||
func TestPrometheus(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &PrometheusTestSuite{})
|
||||
|
||||
+5
-1
@@ -114,10 +114,14 @@ func (s statsdProcessor) EventConcurrencyLimited(_ mtglib.EventConcurrencyLimite
|
||||
s.client.Incr(MetricConcurrencyLimited, 1)
|
||||
}
|
||||
|
||||
func (s statsdProcessor) EventIPBlocklisted(evt mtglib.EventIPBlocklisted) {
|
||||
func (s statsdProcessor) EventIPBlocklisted(_ mtglib.EventIPBlocklisted) {
|
||||
s.client.Incr(MetricIPBlocklisted, 1)
|
||||
}
|
||||
|
||||
func (s statsdProcessor) EventReplayAttack(_ mtglib.EventReplayAttack) {
|
||||
s.client.Incr(MetricReplayAttacks, 1)
|
||||
}
|
||||
|
||||
func (s statsdProcessor) Shutdown() {
|
||||
now := time.Now()
|
||||
events := make([]mtglib.EventFinish, 0, len(s.streams))
|
||||
|
||||
@@ -228,6 +228,16 @@ func (suite *StatsdTestSuite) TestEventIPBlocklisted() {
|
||||
suite.Equal("mtg.ip_blocklisted:1|c", suite.statsdServer.String())
|
||||
}
|
||||
|
||||
func (suite *StatsdTestSuite) TestEventReplayAttack() {
|
||||
suite.statsd.EventReplayAttack(mtglib.EventReplayAttack{
|
||||
CreatedAt: time.Now(),
|
||||
ConnID: "connID",
|
||||
})
|
||||
|
||||
time.Sleep(statsdSleepTime)
|
||||
suite.Equal("mtg.replay_attacks:1|c", suite.statsdServer.String())
|
||||
}
|
||||
|
||||
func TestStatsd(t *testing.T) {
|
||||
t.Parallel()
|
||||
suite.Run(t, &StatsdTestSuite{})
|
||||
|
||||
Reference in New Issue
Block a user