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

test(MonitoredDeployBaseTask): add tests to verify log message for different types of RetrofitError #4608

Conversation

Pranav-b-7
Copy link
Contributor

@Pranav-b-7 Pranav-b-7 commented Nov 22, 2023

This PR introduces test cases designed to assess the current behaviour of the getRetrofitLogMessage() method when faced with diverse RetrofitErrors, including HTTP Error, Network Error, Unexpected Error, and Conversion Error. These tests provide a comprehensive understanding of the existing functionality before upcoming enhancements.

The primary objective of these test cases is to serve as a reference point for the behaviour of getRetrofitLogMessage() prior to planned modifications. The intention is to eliminate the usage of RetrofitError, and the added tests will help validate and compare the code's behaviour after the proposed changes.

Details:

  • Added specific test cases to simulate HTTP Error, Network Error, Unexpected Error, and Conversion Error scenarios.
  • These tests are crucial in establishing a baseline for the current behavior of getRetrofitLogMessage().
  • The subsequent changes will focus on refactoring the method to enhance its reliability and maintainability by eliminating reliance on RetrofitError.

@Pranav-b-7 Pranav-b-7 changed the title feat(retrofit): set error handler as SpinnakerRetrofitErrorHandler to simplify the exception handling refactor(retrofit): set error handler as SpinnakerRetrofitErrorHandler to simplify the exception handling Nov 22, 2023
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from e342423 to 3375c11 Compare November 22, 2023 12:54
@Pranav-b-7 Pranav-b-7 marked this pull request as ready for review November 22, 2023 13:09
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 3375c11 to fc85e63 Compare November 23, 2023 12:39
@Pranav-b-7 Pranav-b-7 changed the title refactor(retrofit): set error handler as SpinnakerRetrofitErrorHandler to simplify the exception handling refactor(deploymentmonitor): add SpinnakerRetrofitErrorHandler to DeploymentMonitorService Nov 23, 2023
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from fc85e63 to 4c608ef Compare November 23, 2023 13:57
@Pranav-b-7 Pranav-b-7 requested a review from dbyron-sf November 23, 2023 14:09
@Pranav-b-7 Pranav-b-7 requested a review from dbyron-sf November 24, 2023 06:14
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch 4 times, most recently from c17f0c6 to 6dfb59d Compare November 29, 2023 11:01
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch 4 times, most recently from adce656 to d5c37dc Compare November 30, 2023 10:19
@Pranav-b-7 Pranav-b-7 changed the title refactor(deploymentmonitor): add SpinnakerRetrofitErrorHandler to DeploymentMonitorService feat(deploymentmonitor): add SpinnakerRetrofitErrorHandler to DeploymentMonitorService Nov 30, 2023
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from d5c37dc to 88bf108 Compare December 1, 2023 12:42
@dbyron-sf dbyron-sf force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 88bf108 to 46ff1f3 Compare December 1, 2023 16:49
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 46ff1f3 to 1428839 Compare December 4, 2023 04:34
@Pranav-b-7 Pranav-b-7 closed this Dec 5, 2023
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 1428839 to e51c7c9 Compare December 5, 2023 10:30
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 962e7ab to 1a10d02 Compare December 6, 2023 09:44
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 1a10d02 to 6611821 Compare December 7, 2023 06:14
…fferent types of RetrofitError

This commit introduces a set of test cases aimed at showcasing the current behavior of the getRetrofitLogMessage() method when different types of RetrofitErrors, such as HTTP Error, Network Error, Unexpected Error, and Conversion Error, are thrown.

The purpose of these test cases is to establish a baseline understanding of the method's behavior in handling various RetrofitError scenarios before the upcoming modifications. These tests will serve as a reference point to compare and validate the behavior of the code after enhancements are made, specifically focusing on eliminating the usage of RetrofitError.

These test cases provide valuable insight into the existing behavior of the getRetrofitLogMessage() method and will aid in assessing the effectiveness of subsequent modifications.
@Pranav-b-7 Pranav-b-7 force-pushed the deploymentMonitorService-eliminate-RetrofitError branch from 6611821 to 947cf8b Compare December 7, 2023 06:23
@Pranav-b-7 Pranav-b-7 requested a review from dbyron-sf December 7, 2023 07:09
@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Dec 7, 2023
@mergify mergify bot added the auto merged Merged automatically by a bot label Dec 7, 2023
@mergify mergify bot merged commit adc81ac into spinnaker:master Dec 7, 2023
4 checks passed
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Dec 8, 2023
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Dec 8, 2023
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Dec 11, 2023
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Dec 29, 2023
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
dbyron-sf pushed a commit to Pranav-b-7/orca that referenced this pull request Jan 2, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 3, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, a new specific exception handler is introduced to manage JsonProcessing during the serialization of the HTTP error body. The impact of these changes should be compared with another related PR: spinnaker#4617
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 3, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, when the error response body is null, an appropriate error message will be printed in the logger.
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 3, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, when the error response body is null, an appropriate error message will be printed in the logger.
Pranav-b-7 added a commit to Pranav-b-7/orca that referenced this pull request Jan 4, 2024
…for DeploymentMonitorService

Update the error handler for the retrofit client, DeploymentMonitorService, to use SpinnakerRetrofitErrorHandler. Additionally, modify catch blocks with RetrofitError to use Spinnaker*Exception.

Purpose : This commit is foundational work for upgrading the Retrofit version to retrofit2.x

Behavioural change : The modification includes updating catch blocks, leading to a change in the format of logger messages. This aligns with the upcoming modifications discussed in the PR: spinnaker#4608

Additionally, when the error response body is null, an appropriate error message will be printed in the logger.
dbyron-sf added a commit to dbyron-sf/orca that referenced this pull request Jan 8, 2024
…e for different types of RetrofitError (spinnaker#4608)"

This reverts commit adc81ac.

With the addition of EvaluateDeploymentHealthTaskTest, we have equivalent coverage that:

- is in java instead of groovy
- doesn't increase the visibility of getRetrofitLogMessage
- more easily shows behavior changes when adopting SpinnakerRetrofitErrorHandler
- is less likely to change when moving from retrofit to retrofit2
mergify bot pushed a commit that referenced this pull request Jan 8, 2024
…eploymentMonitorService (#4628)

* refactor(clouddriver/test): configure logback to log messages

to make it possible to add tests that assert on the contents of log messages.

orca-test has a logback-test.xml file that disables logging, so add one for
orca-clouddriver that takes precedence so log messages actually get generated.

Now that logging is enabled, clock.millis() is called an additional time during a test in
ServerGroupCacheForceRefreshTaskSpec.

* test(clouddriver): demonstrate behavior of EvaluateDeploymentHealthTask

to see what changes when moving to SpinnakerRetrofitErrorHandler.  Specifically, these
tests verify the contents of a log message that's tightly coupled to RetrofitError.

* Revert "test(MonitoredDeployBaseTask): Add tests to verify log message for different types of RetrofitError (#4608)"

This reverts commit adc81ac.

With the addition of EvaluateDeploymentHealthTaskTest, we have equivalent coverage that:

- is in java instead of groovy
- doesn't increase the visibility of getRetrofitLogMessage
- more easily shows behavior changes when adopting SpinnakerRetrofitErrorHandler
- is less likely to change when moving from retrofit to retrofit2

* refactor(deploymentmonitor): use SpinnakerRetrofitErrorHandler with DeploymentMonitorService

Note, there's a behavior change here when http response bodies aren't json objects.
Previously, the log message would, barring an exception processing the response, include
the http response body in the log message.  With SpinnakerHttpException, response bodies
that aren't json objects aren't available, so the body appears to be empty.

For example, before:

2024-01-04 12:31:59.640  WARN   --- [    Test worker] n.s.o.c.t.m.EvaluateDeploymentHealthTask : [] HTTP Error encountered while talking to monitorName(monitorId)->http://localhost:49179/deployment/evaluateHealth, status: 400 (Bad Request)
response body: non-json response}
retrofit.RetrofitError: 400 Bad Request
	at retrofit.RetrofitError.httpError(RetrofitError.java:40)

after:

2024-01-04 14:26:13.270  WARN   --- [    Test worker] n.s.o.c.t.m.EvaluateDeploymentHealthTask : [] HTTP Error encountered while talking to monitorName(monitorId)->http://localhost:58192/deployment/evaluateHealth, status: 400 (Bad Request)
response body: }
com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException: Status: 400, URL: http://localhost:58192/deployment/evaluateHealth, Message: Bad Request
	at com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler.handleError(SpinnakerRetrofitErrorHandler.java:55)

There's also a behavior change for ConversionException.

before:

2024-01-04 16:03:19.363  WARN   --- [    Test worker] n.s.o.c.t.m.EvaluateDeploymentHealthTask : [] HTTP Error encountered while talking to monitorName(monitorId)->http://localhost:60051/deployment/evaluateHealth, status: 200 (OK)
headers:
response body: }
retrofit.RetrofitError: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentStep` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('bogus')
 at [Source: (retrofit.ExceptionCatchingTypedInput$ExceptionCatchingInputStream); line: 1, column: 13] (through reference chain: com.netflix.spinnaker.orca.deploymentmonitor.models.EvaluateHealthResponse["nextStep"])
	at retrofit.RetrofitError.conversionError(RetrofitError.java:33)

after:

2024-01-04 16:14:03.540  WARN   --- [    Test worker] n.s.o.c.t.m.EvaluateDeploymentHealthTask : [] HTTP Error encountered while talking to monitorName(monitorId)->http://localhost:59402/deployment/evaluateHealth, <NO RESPONSE>}
com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerConversionException: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot construct instance of `com.netflix.spinnaker.orca.deploymentmonitor.models.DeploymentStep` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('bogus')
 at [Source: (retrofit.ExceptionCatchingTypedInput$ExceptionCatchingInputStream); line: 1, column: 13] (through reference chain: com.netflix.spinnaker.orca.deploymentmonitor.models.EvaluateHealthResponse["nextStep"])
	at com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerRetrofitErrorHandler.handleError(SpinnakerRetrofitErrorHandler.java:64)
	at retrofit.RestAdapter$RestHandler.invoke(RestAdapter.java:242)

---------

Co-authored-by: Pranav-b-7 <[email protected]>
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.33
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants