Skip to content

Commit 52f540e

Browse files
feat(classifier): deadline exceeded in peer create as connectivity (#3005)
1 parent 1019ea8 commit 52f540e

4 files changed

Lines changed: 42 additions & 1 deletion

File tree

flow/alerting/classifier.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,17 @@ func GetErrorClass(ctx context.Context, err error) (ErrorClass, ErrorInfo) {
478478
}
479479
}
480480

481+
var peerCreateError *exceptions.PeerCreateError
482+
if errors.As(err, &peerCreateError) {
483+
// Check for context deadline exceeded error
484+
if errors.Is(peerCreateError, context.DeadlineExceeded) {
485+
return ErrorNotifyConnectivity, ErrorInfo{
486+
Source: ErrorSourceOther,
487+
Code: "CONTEXT_DEADLINE_EXCEEDED",
488+
}
489+
}
490+
}
491+
481492
return ErrorOther, ErrorInfo{
482493
Source: ErrorSourceOther,
483494
Code: "UNKNOWN",

flow/alerting/classifier_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package alerting
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"net"
@@ -301,3 +302,14 @@ func TestRandomErrorShouldBeOther(t *testing.T) {
301302
Code: "UNKNOWN",
302303
}, errInfo, "Unexpected error info")
303304
}
305+
306+
func TestPeerCreateTimeoutErrorShouldBeConnectivity(t *testing.T) {
307+
// Simulate a peer create timeout error, this is just a unit test, maybe we should try recreating this error in a more realistic way
308+
err := exceptions.NewPeerCreateError(context.DeadlineExceeded)
309+
errorClass, errInfo := GetErrorClass(t.Context(), fmt.Errorf("error in peer create: %w", err))
310+
assert.Equal(t, ErrorNotifyConnectivity, errorClass, "Unexpected error class")
311+
assert.Equal(t, ErrorInfo{
312+
Source: ErrorSourceOther,
313+
Code: "CONTEXT_DEADLINE_EXCEEDED",
314+
}, errInfo, "Unexpected error info")
315+
}

flow/connectors/core.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/PeerDB-io/peerdb/flow/model"
2525
"github.com/PeerDB-io/peerdb/flow/otel_metrics"
2626
"github.com/PeerDB-io/peerdb/flow/shared"
27+
"github.com/PeerDB-io/peerdb/flow/shared/exceptions"
2728
)
2829

2930
type Connector interface {
@@ -467,7 +468,7 @@ func GetAs[T Connector](ctx context.Context, env map[string]string, config *prot
467468
var none T
468469
conn, err := GetConnector(ctx, env, config)
469470
if err != nil {
470-
return none, err
471+
return none, exceptions.NewPeerCreateError(err)
471472
}
472473

473474
if tconn, ok := conn.(T); ok {

flow/shared/exceptions/peer.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package exceptions
2+
3+
type PeerCreateError struct {
4+
error
5+
}
6+
7+
func NewPeerCreateError(err error) *PeerCreateError {
8+
return &PeerCreateError{err}
9+
}
10+
11+
func (e *PeerCreateError) Error() string {
12+
return "PeerCreate Error: " + e.error.Error()
13+
}
14+
15+
func (e *PeerCreateError) Unwrap() error {
16+
return e.error
17+
}

0 commit comments

Comments
 (0)