Skip to content

Commit 27db977

Browse files
jakobhtins-tril
authored andcommitted
Added shard not found error (cadence-workflow#7186)
What changed? Added a shard not found error to the proto def, and mappers. We now return this specific error when we get a lookup for a shard we do not know. Why? This error is an expected user error so we should treat it as such. How did you test it? Unit tests and local runs Potential risks Release notes Documentation Changes
1 parent 7bd7c00 commit 27db977

File tree

12 files changed

+329
-34
lines changed

12 files changed

+329
-34
lines changed

.gen/proto/sharddistributor/v1/service.pb.go

Lines changed: 241 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.gen/proto/sharddistributor/v1/service.pb.yarpc.go

Lines changed: 18 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/metrics/defs.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,6 +2882,7 @@ const (
28822882
ShardDistributorLatency
28832883
ShardDistributorErrContextTimeoutCounter
28842884
ShardDistributorErrNamespaceNotFound
2885+
ShardDistributorErrShardNotFound
28852886

28862887
ShardDistributorAssignLoopNumRebalancedShards
28872888
ShardDistributorAssignLoopShardRebalanceLatency
@@ -3644,6 +3645,7 @@ var MetricDefs = map[ServiceIdx]map[int]metricDefinition{
36443645
ShardDistributorFailures: {metricName: "shard_distributor_failures", metricType: Counter},
36453646
ShardDistributorLatency: {metricName: "shard_distributor_latency", metricType: Timer},
36463647
ShardDistributorErrNamespaceNotFound: {metricName: "shard_distributor_err_namespace_not_found", metricType: Counter},
3648+
ShardDistributorErrShardNotFound: {metricName: "shard_distributor_err_shard_not_found", metricType: Counter},
36473649
ShardDistributorAssignLoopShardRebalanceLatency: {metricName: "shard_distrubutor_shard_assign_latency", metricType: Histogram},
36483650
ShardDistributorAssignLoopNumRebalancedShards: {metricName: "shard_distributor_shard_assign_reassigned_shards", metricType: Gauge},
36493651
ShardDistributorAssignLoopAttempts: {metricName: "shard_distrubutor_shard_assign_attempt", metricType: Counter},

common/types/mapper/proto/errors.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ func FromError(err error) error {
8787
return typedErr
8888
} else if ok, typedErr = errorutils.ConvertError(err, fromNamespaceNotFoundErr); ok {
8989
return typedErr
90+
} else if ok, typedErr = errorutils.ConvertError(err, fromShardNotFoundErr); ok {
91+
return typedErr
9092
}
9193

9294
return protobuf.NewError(yarpcerrors.CodeUnknown, err.Error())
@@ -124,6 +126,11 @@ func ToError(err error) error {
124126
return &types.NamespaceNotFoundError{
125127
Namespace: details.Namespace,
126128
}
129+
case *sharddistributorv1.ShardNotFoundError:
130+
return &types.ShardNotFoundError{
131+
Namespace: details.Namespace,
132+
ShardKey: details.ShardKey,
133+
}
127134
}
128135
case yarpcerrors.CodeInvalidArgument:
129136
switch getErrorDetails(err).(type) {
@@ -376,3 +383,10 @@ func fromNamespaceNotFoundErr(e *types.NamespaceNotFoundError) error {
376383
Namespace: e.Namespace,
377384
}))
378385
}
386+
387+
func fromShardNotFoundErr(e *types.ShardNotFoundError) error {
388+
return protobuf.NewError(yarpcerrors.CodeNotFound, e.Error(), protobuf.WithErrorDetails(&sharddistributorv1.ShardNotFoundError{
389+
Namespace: e.Namespace,
390+
ShardKey: e.ShardKey,
391+
}))
392+
}

0 commit comments

Comments
 (0)