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

Ingester: replace grpc/status usages with gogo/status #6416

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

duricanikolic
Copy link
Contributor

What this PR does

This PR replaces the usage of grpc/status with gogo/status in ingester-specific error handling. The reason for that is because the latter allows a more simple handling of custom error details.

Which issue(s) this PR fixes or relates to

Related to #6008

Checklist

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

@duricanikolic duricanikolic self-assigned this Oct 18, 2023
@duricanikolic duricanikolic requested a review from a team as a code owner October 18, 2023 09:56
}

func (e errorWithStatus) Unwrap() error {
return e.err
}

func (e errorWithStatus) GRPCStatus() *status.Status {
return e.status
func (e errorWithStatus) GRPCStatus() *grpcstatus.Status {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewer: this is needed to ensure that gRPC engine will be able to recognizer errorWithStatus by calling grpc.status.FromError().

Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
@@ -430,3 +441,20 @@ func newIngesterErrSamplers(freq int64) ingesterErrSamplers {
log.NewSampler(freq),
}
}

func handlePushError(err error) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: this method has been moved from ingester.go to errors.go.

@@ -292,3 +316,151 @@ func checkIngesterError(t *testing.T, err error, expectedType ingesterErrorType,
require.ErrorAs(t, err, &softErr)
}
}

func TestHandlePushError(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: this test has been moved from ingester.go to errors.go.

@@ -3154,23 +3154,6 @@ func (i *Ingester) Push(ctx context.Context, req *mimirpb.WriteRequest) (*mimirp
return nil, handledErr
}

func handlePushError(err error) error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: this method has been moved from ingester.go to errors.go.

@@ -8992,151 +8991,3 @@ func TestIngester_lastUpdatedTimeIsNotInTheFuture(t *testing.T) {
// Verify that maxTime of TSDB is actually our future sample.
require.Equal(t, futureTS, db.db.Head().MaxTime())
}

func TestIngester_HandlePushError(t *testing.T) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers: this test has been moved from ingester.go to errors.go.

require.Equal(t, codes.Unavailable, st.Code())
require.Errorf(t, err, st.Message())

// Ensure httpgrpc's HTTPResponseFromError does not recognize errWithStatuserrWithStatus.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Ensure httpgrpc's HTTPResponseFromError does not recognize errWithStatuserrWithStatus.
// Ensure httpgrpc's HTTPResponseFromError does not recognize errWithStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed this typo. Thank you.

require.Equal(t, http.StatusBadRequest, int(st.Code()))
require.Errorf(t, err, st.Message())

// Ensure httpgrpc's HTTPResponseFromError recognizes errWithStatuserrWithHTTPStatus.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Ensure httpgrpc's HTTPResponseFromError recognizes errWithStatuserrWithHTTPStatus.
// Ensure httpgrpc's HTTPResponseFromError recognizes errWithStatus.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have fixed this typo. Thank you.

require.Errorf(t, err, st.Message())

// Ensure httpgrpc's HTTPResponseFromError does not recognize errWithStatuserrWithStatus.
resp, ok := httpgrpc.HTTPResponseFromError(errWithStatus)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we want it to not recognize the status? is that just to ensure that no behavior changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

httpgrpc.HttpResponseFromError() ensures that the given error is built by httpgrpc.Errorf(). Since we need to guarantee backwards compatibility, methods that translate errors to the corresponding HTTP or gRPC codes will need to be able to distinguish between errors built by httpgrpc.Errorf() and status.Error().
status.FromError() recognizes both types of errors, but httpgrpc.HttpResponseFromError() recognzies only the former. This test ensures that this property holds.

Copy link
Contributor

@replay replay left a comment

Choose a reason for hiding this comment

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

LGTM, thx

Signed-off-by: Yuri Nikolic <durica.nikolic@grafana.com>
@duricanikolic duricanikolic merged commit 2be6899 into main Oct 18, 2023
28 checks passed
@duricanikolic duricanikolic deleted the yuri/handling-ingester-errors branch October 18, 2023 11:11
@duricanikolic duricanikolic restored the yuri/handling-ingester-errors branch October 18, 2023 13:24
@duricanikolic duricanikolic deleted the yuri/handling-ingester-errors branch October 18, 2023 13:28
@pstibrany
Copy link
Member

gogo/protobuf is deprecated and we should not use it in new code.

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.

3 participants