diff --git a/director/director.go b/director/director.go index 1aeb8e0dc..f8f8f6344 100644 --- a/director/director.go +++ b/director/director.go @@ -1361,6 +1361,7 @@ func collectDirectorRedirectionMetric(ctx *gin.Context, destination string) { "destination": destination, "status_code": strconv.Itoa(ctx.Writer.Status()), "version": "", + "network": "", } version, _, err := extractVersionAndService(ctx) @@ -1374,6 +1375,12 @@ func collectDirectorRedirectionMetric(ctx *gin.Context, destination string) { labels["version"] = "unknown" } + maskedIp, ok := utils.ApplyIPMask(ctx.ClientIP()) + if ok { + labels["network"] = maskedIp + } else { + labels["network"] = "unknown" + } metrics.PelicanDirectorRedirectionsTotal.With(labels).Inc() } diff --git a/director/sort.go b/director/sort.go index b261f6d08..6a11e3361 100644 --- a/director/sort.go +++ b/director/sort.go @@ -37,6 +37,7 @@ import ( "github.com/pelicanplatform/pelican/metrics" "github.com/pelicanplatform/pelican/param" "github.com/pelicanplatform/pelican/server_structs" + "github.com/pelicanplatform/pelican/utils" ) type ( @@ -156,8 +157,17 @@ func getLatLong(ctx context.Context, addr netip.Addr) (lat float64, long float64 } labels := prometheus.Labels{ - "source": "", - "proj": "", + "network": "", + "source": "", + "proj": "", + } + + network, ok := utils.ApplyIPMask(addr.String()) + if !ok { + log.Warningf("Failed to apply IP mask to address %s", ip.String()) + labels["network"] = "unknown" + } else { + labels["network"] = network } project, ok := ctx.Value(ProjectContextKey{}).(string) diff --git a/metrics/director.go b/metrics/director.go index e9ee1a699..7be3927a8 100644 --- a/metrics/director.go +++ b/metrics/director.go @@ -95,10 +95,10 @@ var ( PelicanDirectorRedirectionsTotal = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "pelican_director_redirections_total", Help: "The total number of redirections the director issued.", - }, []string{"destination", "status_code", "version"}) + }, []string{"destination", "status_code", "version", "network"}) PelicanDirectorGeoIPErrors = promauto.NewCounterVec(prometheus.CounterOpts{ Name: "pelican_director_geoip_errors", Help: "The total number of errors encountered trying to resolve coordinates using the GeoIP MaxMind database", - }, []string{"source", "proj"}) + }, []string{"network", "source", "proj"}) )