Skip to content

Commit

Permalink
Merge pull request #1885 from patrickbrophy/fix-issue-1774
Browse files Browse the repository at this point in the history
Rejected Advertisement Metric
  • Loading branch information
jhiemstrawisc authored Jan 18, 2025
2 parents 74cfdbf + 15956dd commit fc194ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -1154,13 +1154,15 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType server_s
if err == adminApprovalErr {
log.Warningf("Failed to verify token. %s %q was not approved", sType.String(), adV2.Name)
ctx.JSON(http.StatusForbidden, gin.H{"approval_error": true, "error": fmt.Sprintf("%s %q was not approved by an administrator. %s", sType.String(), ad.Name, approvalErrMsg)})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
} else {
log.Warningln("Failed to verify token:", err)
ctx.JSON(http.StatusForbidden, server_structs.SimpleApiResp{
Status: server_structs.RespFailed,
Msg: fmt.Sprintf("Authorization token verification failed %v", err),
})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
}
}
Expand All @@ -1170,6 +1172,7 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType server_s
Status: server_structs.RespFailed,
Msg: "Authorization token verification failed. Token missing required scope",
})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
}
}
Expand All @@ -1184,13 +1187,15 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType server_s
if err == adminApprovalErr {
log.Warningf("Failed to verify advertise token. Namespace %q requires administrator approval", namespace.Path)
ctx.JSON(http.StatusForbidden, gin.H{"approval_error": true, "error": fmt.Sprintf("The namespace %q was not approved by an administrator. %s", namespace.Path, approvalErrMsg)})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
} else {
log.Warningln("Failed to verify token:", err)
ctx.JSON(http.StatusForbidden, server_structs.SimpleApiResp{
Status: server_structs.RespFailed,
Msg: fmt.Sprintf("Authorization token verification failed: %v", err),
})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
}
}
Expand All @@ -1201,6 +1206,7 @@ func registerServeAd(engineCtx context.Context, ctx *gin.Context, sType server_s
Status: server_structs.RespFailed,
Msg: "Authorization token verification failed. Token missing required scope",
})
metrics.PelicanDirectorRejectedAdvertisements.With(prometheus.Labels{"hostname": adV2.Name}).Inc()
return
}
}
Expand Down
5 changes: 5 additions & 0 deletions metrics/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ var (
Name: "pelican_director_geoip_errors",
Help: "The total number of errors encountered trying to resolve coordinates using the GeoIP MaxMind database",
}, []string{"network", "source", "proj"})

PelicanDirectorRejectedAdvertisements = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "pelican_director_rejected_advertisements",
Help: "The total number of advertisements rejected by the director",
}, []string{"hostname"})
)

0 comments on commit fc194ec

Please sign in to comment.