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

[dbnode] Introduce a field for RPC error code and Resource Exhausted error type #3005

Closed
wants to merge 8 commits into from

Conversation

vpranckaitis
Copy link
Collaborator

@vpranckaitis vpranckaitis commented Dec 11, 2020

What this PR does / why we need it:

Introduces Resource Exhausted error type and uses it for query limit exceeded errors. This includes adding code field to rpc.Error and introducing new xerrors.NewResourceExhaustedError().

Special notes for your reviewer:

There are quite a few changes, it might be a bit more convenient to review the them commit-by-commit.

Does this PR introduce a user-facing and/or backwards incompatible change?:

NONE

Does this PR require updating code package or user-facing documentation?:

NONE

Copy link
Collaborator Author

@vpranckaitis vpranckaitis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things regarding this PR that I'm unsure about

} else if xerrors.IsInvalidParams(err) {
} else if xerrors.IsInvalidParams(err) || xerrors.IsResourceExhausted(err) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are quite a few cases in this PR grouping invalid param with resource exhausted errors does make sense, e.g.:

  • returning same status code (404 in this case);
  • incrementing the same metric.

In such cases I wanted to limit the amount of changes in a single PR and I erred on maintaining externally observable behavior (status codes, published metrics) as it was up until now. This would be fixed in upcoming commits.

// NB: To maintain better backwards compatibility, using BAD_REQUEST error type coupled with
// RESOURCE_EXHAUSTED error code. After a reasonable amount of time this should be switched to
// RESOURCE_EXHAUSTED error code (added after M3 release v1.0.0)
return newError(rpc.ErrorType_BAD_REQUEST, rpc.ErrorCode_RESOURCE_EXHAUSTED, err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should introduce the protocol changes in a backwards compatible way. Older clients, which are not aware about Resource Exhausted error type, will fallback to current Bad Request behavior. On the other hand, newer client would know about Resource Exhausted errors, but the server would keep sending Bad Request until it's upgraded.

@@ -192,7 +192,7 @@ func (q *lookbackLimit) exceeded() error {
func (q *lookbackLimit) checkLimit(recent int64) error {
if q.options.Limit > 0 && recent > q.options.Limit {
q.metrics.exceeded.Inc(1)
return xerrors.NewInvalidParamsError(fmt.Errorf(
return xerrors.NewResourceExhaustedError(fmt.Errorf(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Resource Exhausted for query limits

src/dbnode/generated/thrift/rpc.thrift Outdated Show resolved Hide resolved
Comment on lines +151 to +153
func IsResourceExhausted(err error) bool {
return GetInnerResourceExhaustedError(err) != nil
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: these methods might behave in a confusing way. E.g. NewResourceExhaustedError(NewInvalidParamError(err)) could be treated as both depending on which of IsResourceExhausted() or IsInvalidParam() was called first.

@vpranckaitis vpranckaitis changed the title Vilius/richer rpc errors Introduce a field for RPC error code and Resource Exhausted error type Dec 11, 2020
return tterrors.NewBadRequestError(err)
}
return tterrors.NewInternalError(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this in the convert package?

In fact this method already exists, we would just need to add it:
https://github.com/m3db/m3/blob/master/src/dbnode/network/server/tchannelthrift/convert/convert.go#L187:L197

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov
Copy link

codecov bot commented Dec 14, 2020

Codecov Report

Merging #3005 (3f67cf8) into master (b7ea2e7) will increase coverage by 1.7%.
The diff coverage is 53.8%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #3005     +/-   ##
========================================
+ Coverage    70.5%   72.3%   +1.7%     
========================================
  Files        1078    1078             
  Lines       99840   99459    -381     
========================================
+ Hits        70430   71916   +1486     
+ Misses      24287   22537   -1750     
+ Partials     5123    5006    -117     
Flag Coverage Δ
aggregator 75.8% <0.0%> (-0.1%) ⬇️
cluster 85.1% <100.0%> (-0.1%) ⬇️
collector 84.3% <ø> (ø)
dbnode 78.7% <62.0%> (+4.3%) ⬆️
m3em 74.4% <ø> (ø)
m3ninx 73.1% <ø> (-0.1%) ⬇️
metrics 19.9% <ø> (ø)
msg 74.0% <ø> (-0.2%) ⬇️
query 67.4% <20.0%> (ø)
x 80.0% <40.0%> (-0.4%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b7ea2e7...3f67cf8. Read the comment docs.

@vpranckaitis vpranckaitis changed the title Introduce a field for RPC error code and Resource Exhausted error type [dbnode] Introduce a field for RPC error code and Resource Exhausted error type Dec 14, 2020
@@ -54,6 +54,35 @@ func IsBadRequestError(err error) bool {
return false
}

// IsResourceExhaustedError determines if the error is a resource exhausted error.
func IsResourceExhaustedError(err error) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Call this IsResourceExhaustedErrorCode to match the fact that it's matching on ErrorCode not ErrorType?

@@ -32,9 +32,15 @@ enum ErrorType {
BAD_REQUEST
}

enum ErrorCode {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's use ErrorFlags instead of ErrorCode as we arrived at during our catchup? Will map the naming of the error value to how we would like to use them if flags&RESOURCE_EXHAUSTED { ... }.

@vpranckaitis
Copy link
Collaborator Author

Redone in #3017

@vpranckaitis vpranckaitis deleted the vilius/richer_rpc_errors branch January 8, 2021 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants