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

fix(retrofit): use SpinnakerServerException.getHttpMethod() instead of reflection in SpinnakerServerExceptionHandler #4675

Conversation

alice485
Copy link
Contributor

@alice485 alice485 commented Mar 12, 2024

BaseRetrofitExceptionHandler's retry behavior uses a method called findHttpMethodAnnotation to retrieve an exception's HTTP method. For retrofit2 exceptions, this method no longer works due to things being annotated differently in retrofit2. However, Spinnaker*Exceptions can use getHttpMethod() to retrieve this value, so this PR updates the exception handler to default to using the getter and only use findHttpMethodAnnotation if the getter returns null.

@alice485 alice485 force-pushed the spinnakerserverexceptionhandler-avoid-reflection-when-possible branch from 65fe1a8 to 6cdc8d0 Compare March 13, 2024 15:48
@alice485 alice485 force-pushed the spinnakerserverexceptionhandler-avoid-reflection-when-possible branch from 56a594a to 5a58ab9 Compare March 14, 2024 19:12
@dbyron-sf
Copy link
Contributor

I'm seeing a number of failures with only the commit that adds the tests, but not the code changes. Ideally there wouldn't be any failures, and the code change commit would adjust the tests so the behavior change is clear. I realize this is a lot to ask. I am quite curious what we're actually fixing in this PR though.
image

@alice485
Copy link
Contributor Author

I'm seeing a number of failures with only the commit that adds the tests, but not the code changes. Ideally there wouldn't be any failures, and the code change commit would adjust the tests so the behavior change is clear. I realize this is a lot to ask. I am quite curious what we're actually fixing in this PR though.

Basically, the point of this PR was to avoid using reflection unless the exception was created from a RetrofitError, since otherwise we can simply use SpinnakerServerException.getHttpMethod().

During that process, I found that the exception handler's shouldRetry method always returns false (except in the case of a 503 response) for retrofit2 exceptions since it won't be able to find the http method annotation in the stack trace. I mentioned why this is the case here.

So adding retrofit2 exceptions to the parameters being passed into the tests would necessarily make them fail, which is why I originally added both the test exceptions and the code changes in the same commit.

@dbyron-sf
Copy link
Contributor

It would be nice to see the behavior changes in detail, but I'll get over it. Would you mind changing the PR title / commit message to be fix instead of refactor though, and say that what we're fixing is retry behavior for retrofit2?

@alice485 alice485 changed the title refactor(retrofit): use SpinnakerServerException.getHttpMethod() instead of reflection in SpinnakerServerExceptionHandler fix(retrofit): use SpinnakerServerException.getHttpMethod() instead of reflection in SpinnakerServerExceptionHandler Mar 15, 2024
@alice485 alice485 force-pushed the spinnakerserverexceptionhandler-avoid-reflection-when-possible branch 2 times, most recently from fc7ca50 to 2253f09 Compare March 15, 2024 18:44
abe garcia added 2 commits March 15, 2024 15:13
…andler to default to using SpinnakerServerException.getHttpMethod() since findHttpMethodAnnotation returns null for retrofit2 exceptions
@alice485 alice485 force-pushed the spinnakerserverexceptionhandler-avoid-reflection-when-possible branch from 2253f09 to 93c61e4 Compare March 15, 2024 19:13
@alice485 alice485 marked this pull request as ready for review March 15, 2024 19:48
@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Mar 15, 2024
@mergify mergify bot added the auto merged Merged automatically by a bot label Mar 15, 2024
@mergify mergify bot merged commit da1f0bb into spinnaker:master Mar 15, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for merge target-release/1.34
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants