-
Notifications
You must be signed in to change notification settings - Fork 1
Add default timeout support to opal api proxy #368
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
49b56c4
Add default timeout support to opal api proxy
TimDanielsCQI 267cbd7
Merge branch 'main' into PO-3939
TimDanielsCQI 4d78db3
Merge remote-tracking branch 'origin/main' into PO-3939
TimDanielsCQI 6282783
Add proxy timeout error mapping
TimDanielsCQI d40201c
Merge remote-tracking branch 'origin/PO-3939' into PO-3939
TimDanielsCQI c5bcf64
Document proxy timeout and retry contract
TimDanielsCQI 35bd1f5
Merge branch 'main' into PO-3939
TimDanielsCQI a8e738b
Merge branch 'main' into PO-3939
TimDanielsCQI 1d7b492
Require proxy timeout configuration
TimDanielsCQI 092a368
Merge remote-tracking branch 'origin/PO-3939' into PO-3939
TimDanielsCQI d2d9574
Update src/constants/default-proxy-config.ts
TimDanielsCQI 608953c
Clarify proxy timeout ownership
TimDanielsCQI ffaff6a
Move proxy timeout docs to proxy README
TimDanielsCQI 1f25617
Log proxy target on failures
TimDanielsCQI 790aac5
Clarify backend proxy wording
TimDanielsCQI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| # Opal API Proxy Timeout and Retry Contract | ||
|
|
||
| `OpalApiProxy` forwards requests from an opal-frontend node server to an upstream API service. | ||
| It applies a timeout to the upstream connection, but it never retries a request. | ||
| Only the consuming opal-frontend can decide whether replaying its original request is | ||
| safe. | ||
|
|
||
| ## Timeout configuration | ||
|
|
||
| `DEFAULT_PROXY_CONFIG.timeoutInMilliseconds` is intentionally `null`. The common node library does not own an | ||
| environment-specific proxy timeout value. | ||
|
|
||
| Pass the timeout, in milliseconds, as the third argument when creating the | ||
| proxy. The consuming application owns this value so it can be configured per | ||
| environment. | ||
|
|
||
| ```ts | ||
| const proxyConfiguration: ProxyConfiguration = { | ||
| ...DEFAULT_PROXY_CONFIG, | ||
| opalFinesServiceUrl: config.get('opal-api.opal-fines-service'), | ||
| opalUserServiceUrl: config.get('opal-api.opal-user-service'), | ||
| timeoutInMilliseconds: config.get('opal-api.timeoutInMilliseconds'), | ||
| }; | ||
|
|
||
| if (proxyConfiguration.timeoutInMilliseconds === null) { | ||
| throw new Error('Missing opal-api.timeoutInMilliseconds configuration.'); | ||
| } | ||
|
|
||
| if (proxyConfiguration.opalFinesServiceUrl) { | ||
| app.use( | ||
| '/opal-fines-service', | ||
| OpalApiProxy(proxyConfiguration.opalFinesServiceUrl, ipLoggingEnabled, proxyConfiguration.timeoutInMilliseconds), | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ## Error responses | ||
|
|
||
| When the upstream service times out or the proxy encounters a recognised | ||
| transport failure, the proxy returns the following response: | ||
|
|
||
| ```json | ||
| { | ||
| "title": "Gateway Timeout", | ||
| "status": 504, | ||
| "detail": "The upstream service did not respond in time.", | ||
| "retriable": true | ||
| } | ||
| ``` | ||
|
|
||
| Other unexpected proxy failures return `502 Bad Gateway` with | ||
| `"retriable": false`. | ||
|
|
||
| `retriable` is information for the frontend's error and retry handling. It is | ||
| not an instruction to replay every request, and the proxy does not replay any | ||
| request automatically. | ||
|
|
||
| ## Frontend retry example | ||
|
|
||
| The optional retry support in `opal-frontend-common-ui-lib` must be registered | ||
| by the consuming application. A request then opts in individually. This is | ||
| appropriate only after the application has decided that replaying the request | ||
| is safe, for example a read-only `GET` request. | ||
|
|
||
| ```ts | ||
| import { provideHttpClient, withInterceptors } from '@angular/common/http'; | ||
| import { httpRetryInterceptor } from '@hmcts/opal-frontend-common/interceptors/http-retry'; | ||
|
|
||
| provideHttpClient(withInterceptors([httpRetryInterceptor])); | ||
| ``` | ||
|
|
||
| ```ts | ||
| import { withHttpRetry } from '@hmcts/opal-frontend-common/interceptors/http-retry'; | ||
|
|
||
| this.http.get('/api/accounts/123', { | ||
| context: withHttpRetry({ | ||
| retryCount: 2, | ||
| retryableStatusCodes: [504], | ||
| }), | ||
| }); | ||
| ``` | ||
|
|
||
| Do not opt mutation requests, such as `POST`, `PUT`, `PATCH`, or `DELETE`, into | ||
| automatic retries unless the consuming application has explicitly established | ||
| that replaying them is safe. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.