- Implement GeoIPService for IP-to-country lookups with comprehensive error handling. - Add tests for GeoIPService covering various scenarios including invalid IPs and database loading. - Extend AccessListService to handle GeoIP service integration, including graceful degradation when GeoIP service is unavailable. - Introduce new tests for AccessListService to validate geo ACL behavior and country code parsing. - Update SecurityService to include new fields for WAF configuration and enhance decision logging functionality. - Add extensive tests for SecurityService covering rule set management and decision logging. - Create a detailed Security Coverage QA Plan to ensure 100% code coverage for security-related functionality.
50 lines
1.8 KiB
Go
50 lines
1.8 KiB
Go
// Package metrics provides Prometheus metrics collectors for the application.
|
|
package metrics
|
|
|
|
import (
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
)
|
|
|
|
var (
|
|
wafRequestsTotal = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Name: "charon_waf_requests_total",
|
|
Help: "Total number of requests evaluated by WAF",
|
|
})
|
|
wafBlockedTotal = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Name: "charon_waf_blocked_total",
|
|
Help: "Total number of requests blocked by WAF",
|
|
})
|
|
wafMonitoredTotal = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Name: "charon_waf_monitored_total",
|
|
Help: "Total number of requests monitored (not blocked) by WAF",
|
|
})
|
|
crowdsecRequestsTotal = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Name: "charon_crowdsec_requests_total",
|
|
Help: "Total number of requests evaluated by CrowdSec bouncer",
|
|
})
|
|
crowdsecBlockedTotal = prometheus.NewCounter(prometheus.CounterOpts{
|
|
Name: "charon_crowdsec_blocked_total",
|
|
Help: "Total number of requests blocked by CrowdSec decisions",
|
|
})
|
|
)
|
|
|
|
// Register registers Prometheus collectors. Call once at startup.
|
|
func Register(registry *prometheus.Registry) {
|
|
registry.MustRegister(wafRequestsTotal, wafBlockedTotal, wafMonitoredTotal, crowdsecRequestsTotal, crowdsecBlockedTotal)
|
|
}
|
|
|
|
// IncWAFRequest increments the evaluated requests counter.
|
|
func IncWAFRequest() { wafRequestsTotal.Inc() }
|
|
|
|
// IncWAFBlocked increments the blocked requests counter.
|
|
func IncWAFBlocked() { wafBlockedTotal.Inc() }
|
|
|
|
// IncWAFMonitored increments the monitored requests counter.
|
|
func IncWAFMonitored() { wafMonitoredTotal.Inc() }
|
|
|
|
// IncCrowdSecRequest increments the CrowdSec evaluated requests counter.
|
|
func IncCrowdSecRequest() { crowdsecRequestsTotal.Inc() }
|
|
|
|
// IncCrowdSecBlocked increments the CrowdSec blocked requests counter.
|
|
func IncCrowdSecBlocked() { crowdsecBlockedTotal.Inc() }
|