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

Expand metrics status tags with pubsub validation error types #860

Merged
merged 1 commit into from
Jan 30, 2025
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
16 changes: 16 additions & 0 deletions internal/measurements/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"os"
"strings"

"github.com/ipfs/go-datastore"
pubsub "github.com/libp2p/go-libp2p-pubsub"
Expand All @@ -28,6 +29,21 @@ func Status(ctx context.Context, err error) attribute.KeyValue {
return AttrStatusSuccess
case errors.Is(err, datastore.ErrNotFound):
return AttrStatusNotFound
case errors.As(err, &pubsub.ValidationError{}):
// There are no sentinel errors for pubsub validation errors, unfortunately.
// Hence, the string gymnastics.
switch errMsg := err.Error(); {
case strings.Contains(errMsg, pubsub.RejectValidationIgnored):
return attribute.String("status", "error-pubsub-validation-ignored")
case strings.Contains(errMsg, pubsub.RejectValidationFailed):
return attribute.String("status", "error-pubsub-validation-failed")
case strings.Contains(errMsg, pubsub.RejectValidationThrottled):
return attribute.String("status", "error-pubsub-validation-throttled")
case strings.Contains(errMsg, pubsub.RejectValidationQueueFull):
return attribute.String("status", "error-pubsub-validation-q-full")
default:
return attribute.String("status", "error-pubsub-validation-other")
}
case os.IsTimeout(err),
errors.Is(err, os.ErrDeadlineExceeded),
errors.Is(cErr, context.DeadlineExceeded):
Expand Down
Loading