Skip to content

Commit

Permalink
Revert "Removed the "network" labels from the metrics"
Browse files Browse the repository at this point in the history
  • Loading branch information
turetske committed Nov 22, 2024
1 parent e677197 commit 8353dd2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,7 @@ func collectDirectorRedirectionMetric(ctx *gin.Context, destination string) {
"destination": destination,
"status_code": strconv.Itoa(ctx.Writer.Status()),
"version": "",
"network": "",
}

version, _, err := extractVersionAndService(ctx)
Expand All @@ -1387,6 +1388,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()
}

Expand Down
14 changes: 12 additions & 2 deletions director/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions metrics/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
)

0 comments on commit 8353dd2

Please sign in to comment.