Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(metrics): add error type to nack metric #10013

Merged
merged 3 commits into from
Apr 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions pkg/util/xds/stats_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xds

import (
"context"
"strings"
"sync"
"time"

Expand All @@ -14,7 +15,13 @@ import (

var statsLogger = core.Log.WithName("stats-callbacks")

const ConfigInFlightThreshold = 100_000
const (
ConfigInFlightThreshold = 100_000
failedCallingWebhook = "failed calling webhook"
userErrorType = "user"
otherErrorType = "other"
noErrorType = "no_error"
)

type VersionExtractor = func(metadata *structpb.Struct) string

Expand Down Expand Up @@ -89,7 +96,7 @@ func NewStatsCallbacks(metrics prometheus.Registerer, dsType string, versionExtr
stats.requestsReceivedMetric = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: dsType + "_requests_received",
Help: "Number of confirmations requests from a client",
}, []string{"type_url", "confirmation"})
}, []string{"type_url", "confirmation", "error_type"})
if err := metrics.Register(stats.requestsReceivedMetric); err != nil {
return nil, err
}
Expand Down Expand Up @@ -159,9 +166,9 @@ func (s *statsCallbacks) OnStreamRequest(streamID int64, request DiscoveryReques
}

if request.HasErrors() {
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "NACK").Inc()
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "NACK", classifyError(request.ErrorMsg())).Inc()
} else {
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "ACK").Inc()
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "ACK", noErrorType).Inc()
}

if configTime, exists := s.takeConfigTimeFromQueue(request.VersionInfo()); exists {
Expand Down Expand Up @@ -214,9 +221,9 @@ func (s *statsCallbacks) OnStreamDeltaRequest(streamID int64, request DeltaDisco
}

if request.HasErrors() {
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "NACK").Inc()
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "NACK", classifyError(request.ErrorMsg())).Inc()
} else {
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "ACK").Inc()
s.requestsReceivedMetric.WithLabelValues(request.GetTypeUrl(), "ACK", noErrorType).Inc()
}

// Delta only has an initial version, therefore we need to change the key to nodeID and typeURL.
Expand All @@ -229,3 +236,11 @@ func (s *statsCallbacks) OnStreamDeltaRequest(streamID int64, request DeltaDisco
func (s *statsCallbacks) OnStreamDeltaResponse(_ int64, _ DeltaDiscoveryRequest, response DeltaDiscoveryResponse) {
s.responsesSentMetric.WithLabelValues(response.GetTypeUrl()).Inc()
}

func classifyError(error string) string {
if strings.Contains(error, failedCallingWebhook) {
return userErrorType
} else {
return otherErrorType
}
}
Loading