mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 15:54:03 +03:00
Add tags for ip blocklisted metric
This commit is contained in:
+14
-9
@@ -110,8 +110,13 @@ func (p prometheusProcessor) EventConcurrencyLimited(_ mtglib.EventConcurrencyLi
|
||||
p.factory.metricConcurrencyLimited.Inc()
|
||||
}
|
||||
|
||||
func (p prometheusProcessor) EventIPBlocklisted(_ mtglib.EventIPBlocklisted) {
|
||||
p.factory.metricIPBlocklisted.Inc()
|
||||
func (p prometheusProcessor) EventIPBlocklisted(evt mtglib.EventIPBlocklisted) {
|
||||
tag := TagIPListBlock
|
||||
if !evt.IsBlockList {
|
||||
tag = TagIPListAllow
|
||||
}
|
||||
|
||||
p.factory.metricIPBlocklisted.WithLabelValues(tag).Inc()
|
||||
}
|
||||
|
||||
func (p prometheusProcessor) EventReplayAttack(_ mtglib.EventReplayAttack) {
|
||||
@@ -150,10 +155,10 @@ type PrometheusFactory struct {
|
||||
|
||||
metricTelegramTraffic *prometheus.CounterVec
|
||||
metricDomainFrontingTraffic *prometheus.CounterVec
|
||||
metricIPBlocklisted *prometheus.CounterVec
|
||||
|
||||
metricDomainFronting prometheus.Counter
|
||||
metricConcurrencyLimited prometheus.Counter
|
||||
metricIPBlocklisted prometheus.Counter
|
||||
metricReplayAttacks prometheus.Counter
|
||||
}
|
||||
|
||||
@@ -223,6 +228,11 @@ func NewPrometheus(metricPrefix, httpPath string) *PrometheusFactory { // nolint
|
||||
Name: MetricDomainFrontingTraffic,
|
||||
Help: "Traffic which is generated talking with front domain.",
|
||||
}, []string{TagDirection}),
|
||||
metricIPBlocklisted: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: metricPrefix,
|
||||
Name: MetricIPBlocklisted,
|
||||
Help: "A number of rejected sessions due to ip blocklisting.",
|
||||
}, []string{TagIPList}),
|
||||
|
||||
metricDomainFronting: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: metricPrefix,
|
||||
@@ -234,11 +244,6 @@ func NewPrometheus(metricPrefix, httpPath string) *PrometheusFactory { // nolint
|
||||
Name: MetricConcurrencyLimited,
|
||||
Help: "A number of sessions that were rejected by concurrency limiter.",
|
||||
}),
|
||||
metricIPBlocklisted: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: metricPrefix,
|
||||
Name: MetricIPBlocklisted,
|
||||
Help: "A number of rejected sessions due to ip blocklisting.",
|
||||
}),
|
||||
metricReplayAttacks: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: metricPrefix,
|
||||
Name: MetricReplayAttacks,
|
||||
@@ -253,10 +258,10 @@ func NewPrometheus(metricPrefix, httpPath string) *PrometheusFactory { // nolint
|
||||
|
||||
registry.MustRegister(factory.metricTelegramTraffic)
|
||||
registry.MustRegister(factory.metricDomainFrontingTraffic)
|
||||
registry.MustRegister(factory.metricIPBlocklisted)
|
||||
|
||||
registry.MustRegister(factory.metricDomainFronting)
|
||||
registry.MustRegister(factory.metricConcurrencyLimited)
|
||||
registry.MustRegister(factory.metricIPBlocklisted)
|
||||
registry.MustRegister(factory.metricReplayAttacks)
|
||||
|
||||
return factory
|
||||
|
||||
@@ -156,7 +156,18 @@ func (suite *PrometheusTestSuite) TestEventIPBlocklisted() {
|
||||
|
||||
data, err := suite.Get()
|
||||
suite.NoError(err)
|
||||
suite.Contains(data, `mtg_ip_blocklisted 1`)
|
||||
suite.Contains(data, `mtg_ip_blocklisted{ip_list="blocklist"} 1`)
|
||||
}
|
||||
|
||||
func (suite *PrometheusTestSuite) TestEventIPAllowlisted() {
|
||||
suite.prometheus.EventIPBlocklisted(
|
||||
mtglib.NewEventIPAllowlisted(net.ParseIP("2001:db8::68")))
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
data, err := suite.Get()
|
||||
suite.NoError(err)
|
||||
suite.Contains(data, `mtg_ip_blocklisted{ip_list="allowlist"} 1`)
|
||||
}
|
||||
|
||||
func (suite *PrometheusTestSuite) TestEventReplayAttack() {
|
||||
|
||||
+7
-2
@@ -113,8 +113,13 @@ func (s statsdProcessor) EventConcurrencyLimited(_ mtglib.EventConcurrencyLimite
|
||||
s.client.Incr(MetricConcurrencyLimited, 1)
|
||||
}
|
||||
|
||||
func (s statsdProcessor) EventIPBlocklisted(_ mtglib.EventIPBlocklisted) {
|
||||
s.client.Incr(MetricIPBlocklisted, 1)
|
||||
func (s statsdProcessor) EventIPBlocklisted(evt mtglib.EventIPBlocklisted) {
|
||||
tag := TagIPListBlock
|
||||
if !evt.IsBlockList {
|
||||
tag = TagIPListAllow
|
||||
}
|
||||
|
||||
s.client.Incr(MetricIPBlocklisted, 1, statsd.StringTag(TagIPList, tag))
|
||||
}
|
||||
|
||||
func (s statsdProcessor) EventReplayAttack(_ mtglib.EventReplayAttack) {
|
||||
|
||||
@@ -186,7 +186,15 @@ func (suite *StatsdTestSuite) TestEventIPBlocklisted() {
|
||||
mtglib.NewEventIPBlocklisted(net.ParseIP("10.0.0.10")))
|
||||
|
||||
time.Sleep(statsdSleepTime)
|
||||
suite.Equal("mtg.ip_blocklisted:1|c", suite.statsdServer.String())
|
||||
suite.Equal("mtg.ip_blocklisted:1|c|#ip_list:blocklist", suite.statsdServer.String())
|
||||
}
|
||||
|
||||
func (suite *StatsdTestSuite) TestEventIPAllowlisted() {
|
||||
suite.statsd.EventIPBlocklisted(
|
||||
mtglib.NewEventIPAllowlisted(net.ParseIP("10.0.0.10")))
|
||||
|
||||
time.Sleep(statsdSleepTime)
|
||||
suite.Equal("mtg.ip_blocklisted:1|c|#ip_list:allowlist", suite.statsdServer.String())
|
||||
}
|
||||
|
||||
func (suite *StatsdTestSuite) TestEventReplayAttack() {
|
||||
|
||||
Reference in New Issue
Block a user