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

Metric bucket should not return error when error is expected #103

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

yeya24
Copy link
Contributor

@yeya24 yeya24 commented Feb 27, 2024

  • I added CHANGELOG entry for this change.
  • Change is not relevant to the end user.

Changes

Now, when metric bucket got an error which is isOpFailureExpected, it doesn't increment the metric but still returns the error back to the caller.

For example, it is quite common to log the error returned by bucket operations like below. However, even if I already specify IsXXXError as expected, the error still returns and will be logged. To filter it out, I need to add another IsXXXError(err) check to not log the error, which is very redundant to me.

err := userBucket.ReaderWithExpectedErrs(IsXXXError).Iter(...)
level.Log("msg", "got error", "err", err)

We also have another usecase which doesn't support checking the error in the caller. https://github.com/cortexproject/cortex/blob/master/pkg/storage/bucket/s3/bucket_client.go#L135

We implemented our own storage provider which has retries. Since the error is returned, there is no way for the retryer to know if the error is expected or not and it will keep retrying and finally log the error. There is no way to inject the expected error to the bucket client itself in this case.

Verification

Signed-off-by: Ben Ye <benye@amazon.com>
Signed-off-by: Ben Ye <benye@amazon.com>
@yeya24 yeya24 force-pushed the do-not-return-error-when-expected branch from e780e80 to 383edf7 Compare December 11, 2024 00:46
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

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

Just a small comment apart from that lgtm

objstore.go Outdated
b.metrics.opsFailures.WithLabelValues(op).Inc()
}
return err
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can omit this one no?

Suggested change
return err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Good catch!
Addressed in the latest commit

Signed-off-by: Ben Ye <benye@amazon.com>
Copy link
Collaborator

@JoaoBraveCoding JoaoBraveCoding left a comment

Choose a reason for hiding this comment

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

lgtm

Signed-off-by: Ben Ye <benye@amazon.com>
@yeya24 yeya24 merged commit d69df72 into main Dec 12, 2024
7 checks passed
@yeya24 yeya24 deleted the do-not-return-error-when-expected branch December 12, 2024 21:39
@aknuds1
Copy link
Contributor

aknuds1 commented Dec 16, 2024

To filter it out, I need to add another IsXXXError(err) check to not log the error, which is very redundant to me.

Isn't it better to be explicit about this though, than to assume that the caller doesn't want to know that an error occurred?

This change breaks Mimir in many places, and I see the following problems with it:

  1. The doc comment is no longer correct, as it only says that "it will not increment objstore_bucket_operation_failures_total metric". It doesn't mention that expected errors are swallowed.
  2. The caller has to e.g. check whether BucketReader.Get returns a nil io.ReadCloser in case the error is nil, for the case when an expected error is encountered.
  3. InstrumentedBucket.WithExpectedErrs is intended to concern itself with metrics, but whether to return an error or not is completely beyond that scope and violates the principle of least surprise.

In sum, I think this PR should be reverted. It would be better to either add another method, as an alternative to WithExpectedErrs that swallows expected errors, or leave to the caller to ignore expected errors (as is the case now).

aknuds1 added a commit to aknuds1/objstore that referenced this pull request Dec 16, 2024
…-error-when-expected"

This reverts commit d69df72, reversing
changes made to 8d266b9.
aknuds1 added a commit to aknuds1/objstore that referenced this pull request Dec 16, 2024
…-error-when-expected"

This reverts commit d69df72, reversing
changes made to 8d266b9.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
yeya24 added a commit that referenced this pull request Dec 16, 2024
Revert "Merge pull request #103 from thanos-io/do-not-return-error-when-expected"
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.

4 participants