Add EventReplayAttack

This commit is contained in:
9seconds
2021-03-29 12:07:18 +03:00
parent bef14bd009
commit daa8b9c798
14 changed files with 114 additions and 3 deletions
+5 -1
View File
@@ -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)
+13
View File
@@ -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
View File
@@ -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))
+10
View File
@@ -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{})