Skip to content

Commit bca03db

Browse files
authored
Add proper categorization for client connection closing error (#6844)
1 parent 90cbed3 commit bca03db

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

common/constants/constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,6 @@ func GetTaskPriority(
316316
) int {
317317
return class | subClass
318318
}
319+
320+
// GRPCConnectionClosingError is the error message returned when a gRPC client connection is closing
321+
const GRPCConnectionClosingError = "grpc: the client connection is closing"

common/metrics/defs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,6 +2085,7 @@ const (
20852085
CadenceErrQueryFailedCounter
20862086
CadenceErrLimitExceededCounter
20872087
CadenceErrContextTimeoutCounter
2088+
CadenceErrGRPCConnectionClosingCounter
20882089
CadenceErrRetryTaskCounter
20892090
CadenceErrBadBinaryCounter
20902091
CadenceErrClientVersionNotSupportedCounter
@@ -2814,6 +2815,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
28142815
CadenceErrQueryFailedCounter: {metricName: "cadence_errors_query_failed", metricType: Counter},
28152816
CadenceErrLimitExceededCounter: {metricName: "cadence_errors_limit_exceeded", metricType: Counter},
28162817
CadenceErrContextTimeoutCounter: {metricName: "cadence_errors_context_timeout", metricType: Counter},
2818+
CadenceErrGRPCConnectionClosingCounter: {metricName: "cadence_errors_grpc_connection_closing", metricType: Counter},
28172819
CadenceErrRetryTaskCounter: {metricName: "cadence_errors_retry_task", metricType: Counter},
28182820
CadenceErrBadBinaryCounter: {metricName: "cadence_errors_bad_binary", metricType: Counter},
28192821
CadenceErrClientVersionNotSupportedCounter: {metricName: "cadence_errors_client_version_not_supported", metricType: Counter},

service/frontend/wrappers/metered/metered.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929

3030
"go.uber.org/yarpc/yarpcerrors"
3131

32+
"github.com/uber/cadence/common/constants"
3233
"github.com/uber/cadence/common/log"
3334
"github.com/uber/cadence/common/log/tag"
3435
"github.com/uber/cadence/common/metrics"
@@ -80,12 +81,18 @@ func (h *apiHandler) handleErr(err error, scope metrics.Scope, logger log.Logger
8081
scope.IncCounter(metrics.CadenceErrContextTimeoutCounter)
8182
return err
8283
}
84+
if err.Code() == yarpcerrors.CodeCancelled {
85+
scope.IncCounter(metrics.CadenceErrGRPCConnectionClosingCounter)
86+
logger.Warn(constants.GRPCConnectionClosingError, tag.Error(err))
87+
return err
88+
}
8389
}
8490
if errors.Is(err, context.DeadlineExceeded) {
8591
logger.Error("Frontend request timedout", tag.Error(err))
8692
scope.IncCounter(metrics.CadenceErrContextTimeoutCounter)
8793
return err
8894
}
95+
8996
logger.Error("Uncategorized error", tag.Error(err))
9097
scope.IncCounter(metrics.CadenceFailures)
9198
return frontendInternalServiceError("cadence internal uncategorized error, msg: %v", err.Error())

service/frontend/wrappers/metered/metered_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"go.uber.org/yarpc/yarpcerrors"
3434

3535
"github.com/uber/cadence/common/cache"
36+
"github.com/uber/cadence/common/constants"
3637
"github.com/uber/cadence/common/dynamicconfig/dynamicproperties"
3738
"github.com/uber/cadence/common/log/tag"
3839
"github.com/uber/cadence/common/log/testlogger"
@@ -111,6 +112,18 @@ func TestHandleErr_InternalServiceError(t *testing.T) {
111112
assert.Contains(t, err.Error(), "cadence internal error")
112113
}
113114

115+
func TestHandleErr_ClientConnectionClosingError(t *testing.T) {
116+
logger := testlogger.New(t)
117+
testScope := tally.NewTestScope("test", nil)
118+
metricsClient := metrics.NewClient(testScope, metrics.Frontend)
119+
handler := &apiHandler{}
120+
121+
err := handler.handleErr(errors.New(constants.GRPCConnectionClosingError), metricsClient.Scope(0), logger)
122+
123+
assert.NotNil(t, err)
124+
assert.Contains(t, err.Error(), constants.GRPCConnectionClosingError)
125+
}
126+
114127
func TestHandleErr_UncategorizedError(t *testing.T) {
115128
logger := testlogger.New(t)
116129
testScope := tally.NewTestScope("test", nil)

0 commit comments

Comments
 (0)