Skip to content

Commit

Permalink
lxd/metrics: Add logging for wrong endpoint type
Browse files Browse the repository at this point in the history
Signed-off-by: hamistao <[email protected]>
  • Loading branch information
hamistao committed Oct 15, 2024
1 parent c9b6697 commit c2fb4de
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lxd/metrics/api_rates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit c2fb4de

Please sign in to comment.