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

Extend ring.DoBatch's error class tracking to all errors #427

Merged
merged 6 commits into from
Nov 13, 2023

Conversation

duricanikolic
Copy link
Contributor

@duricanikolic duricanikolic commented Nov 10, 2023

What this PR does:

Error class tracking has been added to ring.DoBatch() in #201. That PR introduced 2 classes of errors:

  • client errors (tracked by itemTracker.failed4xx), and
  • server errors (tracked by itemTracker.failed5xx).

Unfortunately, this change took into account only errors with an HTTP status. In case of a gRPC error, or any other error not implementing GRPCStatus() *Status from google.golang.org/grpc/status, the error was implicitly treated as a server error. For example, if ring instances from a replication set return gRPC errors with gRPC codes FailedPrecondition (due to a client problem), FailedPrecondition (do to a client problem) and Unavailable (do to a server being currently unavailable), the current approach would return the last error that arrived, i.e., the server Unavailable error, although the majority of the instances would have given the client FailedPrecondition error.

Main change

This PR fixes that problem by introducing a new function,

ring.DoBatchWithClientError()

which is a generalization of ring.DoBatch() that has an additional parameter isClientError, a function specified by the caller that differentiates between client and server errors.

Minor changes

itemTracker's attributes failed4xx and failed5xx have been renamed to failedClient and failedServer.

Which issue(s) this PR fixes:

Part of grafana/mimir#6008

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@duricanikolic duricanikolic marked this pull request as draft November 10, 2023 12:24
@duricanikolic duricanikolic changed the title Extend ring.DoBatch's error class tracking to all errors Extend ring.DoBatch's error class tracking to the errors implementing ring.Error Nov 10, 2023
…g.Error

Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. I left a few comments, but the change looks mostly good

ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated
Comment on lines 173 to 175
if itemTracker.done.Load() {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My idea was to set the new done attribute of an itemTracker to true as soon as that itemTracker reaches either its minSuccess or its maxFailure. Once it is achieved, we don't need to consider that itemTracker anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed via slack, this will be done in a separate PR, and maybe in a different form. I have reverted this part of the PR.

ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
@pstibrany
Copy link
Member

I would suggest simpler design: passing a function to DoBatch that categorises errors to server and client-side, or perhaps does the merging of errors. Default function provided in dskit can work with http status codes, while function passed from Mimir can do its own error categorization. WDYT?

Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

the tests look better as table tests 👌

ring/ring_test.go Outdated Show resolved Hide resolved
ring/ring_test.go Outdated Show resolved Hide resolved
ring/ring_test.go Show resolved Hide resolved
@dimitarvdimitrov
Copy link
Contributor

I would suggest simpler design: passing a function to DoBatch that categorises errors to server and client-side, or perhaps does the merging of errors. Default function provided in dskit can work with http status codes, while function passed from Mimir can do its own error categorization. WDYT?

Passing a function will probably create fewer allocations for the client of the library.

But I feel like the interface of DoBatch will become more complex. It already takes one function argument which returns an error. Now it will have another func arg which will receive the same error and return a boolean. I feel like an optional interface on the returned error is less invasive and more straight forward.

@pstibrany
Copy link
Member

But I feel like the interface of DoBatch will become more complex. It already takes one function argument which returns an error. Now it will have another func arg which will receive the same error and return a boolean. I feel like an optional interface on the returned error is less invasive and more straight forward.

DoBatch signature may not be nice, although we could simplify that. Using function would centralize all this logic into single place, with optional interface there will be mix of errors used all over the code base, some implementing the interface and some not.

@duricanikolic
Copy link
Contributor Author

But I feel like the interface of DoBatch will become more complex. It already takes one function argument which returns an error. Now it will have another func arg which will receive the same error and return a boolean. I feel like an optional interface on the returned error is less invasive and more straight forward.

DoBatch signature may not be nice, although we could simplify that. Using function would centralize all this logic into single place, with optional interface there will be mix of errors used all over the code base, some implementing the interface and some not.

I have opted for this solution.

Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
@duricanikolic duricanikolic marked this pull request as ready for review November 10, 2023 15:55
ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a comment

Choose a reason for hiding this comment

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

thanks for addressing my comments

ring/batch.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
@duricanikolic duricanikolic changed the title Extend ring.DoBatch's error class tracking to the errors implementing ring.Error Extend ring.DoBatch's error class tracking to all errors Nov 13, 2023
Copy link
Member

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you. Left some small suggestions for consideration.

ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
ring/batch.go Outdated Show resolved Hide resolved
Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
@duricanikolic duricanikolic merged commit 0ae8e2e into main Nov 13, 2023
3 checks passed
@duricanikolic duricanikolic deleted the yuri/status-code branch November 13, 2023 09:34
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.

None yet

3 participants