diff --git a/lxd/metrics/api_rates.go b/lxd/metrics/api_rates.go index f21bdfc86318..259c89bc067c 100644 --- a/lxd/metrics/api_rates.go +++ b/lxd/metrics/api_rates.go @@ -6,7 +6,9 @@ import ( "sync/atomic" "github.com/canonical/lxd/lxd/request" + "github.com/canonical/lxd/shared" "github.com/canonical/lxd/shared/entity" + "github.com/canonical/lxd/shared/logger" ) // RequestResult represents a completed request status category. @@ -79,6 +81,11 @@ func GetCompletedRequests(entityType entity.Type, result RequestResult) int64 { func TrackStartedRequest(r *http.Request, endpointType entity.Type) { // Set the callback function to track the request as completed. // Use sync.Once to ensure it can be called at most once. + if !shared.ValueInSlice(endpointType, entity.APIMetricsEntityTypes()) { + logger.Warn("Request will not be counted for the metrics due to inappropriate endpoint type", logger.Ctx{"url": r.URL.Path, "method": r.Method, "remote": r.RemoteAddr, "type": endpointType}) + return + } + var once sync.Once callbackFunc := func(result RequestResult) { once.Do(func() {