-
Notifications
You must be signed in to change notification settings - Fork 3
chore: [JS] RPT: document request compression & resilience features #378
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
base: main
Are you sure you want to change the base?
Changes from 14 commits
1cb365c
432f5f0
4d2cf31
c57e0d4
ee5236c
68dd366
5afe03c
ee65743
fdbe4aa
9417646
e55fe6b
15bab91
e803cb5
84b829d
e2fd81f
ef8edcc
dcbf28f
b5d7c34
9f75897
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,8 @@ Use the `predictWithSchema()` method to make predictions with a schema explicitl | |
| Pass the data schema, and the prediction data including the prediction configuration and input data to the method. | ||
| Prefer providing the data schema if it is known instead of relying on the auto-inference solely based on the input data. | ||
|
|
||
| For information about custom request options such as compression, custom headers, or timeout, refer to the [Advanced Usage](#advanced-usage) section. | ||
|
|
||
| ```typescript | ||
| const prediction = await client.predictWithSchema( | ||
| // Data schema | ||
|
|
@@ -146,6 +148,8 @@ To make predictions without providing a schema, use the `predictWithoutSchema()` | |
| Pass only the prediction data as a parameter. | ||
| The data schema will be inferred from the input data. | ||
|
|
||
| For information about custom request options such as compression, custom headers, or timeout, refer to the [Advanced Usage](#advanced-usage) section. | ||
|
|
||
| ```typescript | ||
| const prediction = await client.predictWithoutSchema( | ||
| // Prediction data | ||
|
|
@@ -180,3 +184,117 @@ const prediction = await client.predictWithoutSchema( | |
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ## Advanced Usage | ||
|
|
||
| The RPT client supports advanced features for specialized use cases. | ||
|
|
||
| ### Request Compression | ||
|
|
||
| The RPT client automatically compresses prediction requests to improve performance for large datasets. | ||
| By default, requests with a body of 1024 bytes or larger are automatically compressed using `gzip`. | ||
|
|
||
| To customize compression settings, pass a `customRequest` parameter with a `requestCompression` configuration to the `predictWithSchema()` or `predictWithoutSchema()` methods: | ||
|
|
||
| <!-- vale off --> | ||
|
|
||
| ```typescript | ||
| import * as zlib from 'zlib'; | ||
|
|
||
| const prediction = await client.predictWithSchema(schema, predictionData, { | ||
| requestCompression: { | ||
| algorithm: 'gzip', // Only 'gzip' is currently supported for RPT | ||
| mode: true, // Force compression regardless of payload size (default 'auto') | ||
| autoCompressMinSize: 2048 // Only compress payloads >= 2048 bytes in 'auto' mode (default 1024) | ||
davidkna-sap marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| compressOptions: { | ||
| level: zlib.constants.Z_BEST_SPEED // Custom compression level | ||
| } | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| <!-- vale on --> | ||
|
|
||
| ### Custom Request Options | ||
|
|
||
| The `customRequest` parameter also supports additional HTTP request configuration options from the SAP Cloud SDK for JavaScript, such as: | ||
|
|
||
| - `headers`: Custom HTTP headers. | ||
| - `timeout`: Request timeout in milliseconds. | ||
| - `middleware`: Custom HTTP middleware functions. | ||
|
|
||
| :::warning | ||
|
|
||
| The compression middleware is automatically prepended to the middleware chain, unless disabled by setting `mode: false`. | ||
|
|
||
| ::: | ||
|
|
||
| Example with custom headers: | ||
davidkna-sap marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ```typescript | ||
| const prediction = await client.predictWithSchema(schema, predictionData, { | ||
| headers: { | ||
| 'x-custom-header': 'value' | ||
| }, | ||
| timeout: 30000, // 30 seconds | ||
| requestCompression: { | ||
| mode: true | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ## Resilience | ||
|
|
||
| The `@sap-cloud-sdk/resilience` package provides built-in resilience features to handle transient failures and improve reliability. | ||
| For advanced resilience patterns, refer to the [SAP Cloud SDK documentation on resilience](https://sap.github.io/cloud-sdk/docs/js/guides/resilience). | ||
|
|
||
| ### Retry | ||
|
|
||
| The HTTP client automatically retries failed requests on transient errors such as network issues or temporary server errors. | ||
| Customize retry behavior using the resilience library. | ||
|
|
||
| Set a custom retry count: | ||
|
|
||
| ```typescript | ||
| import { retry } from '@sap-cloud-sdk/resilience'; | ||
|
|
||
| const prediction = await client.predictWithSchema(schema, predictionData, { | ||
| middleware: [ | ||
| retry({ maxRetries: 3, backoffType: 'exponential', initialDelay: 1000 }) | ||
| ], | ||
| requestCompression: { | ||
| mode: false // Disable automatic compression, compression middleware will not be prepended | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| ### Timeout | ||
|
|
||
| Configure timeout for requests to prevent hanging connections. | ||
| The default timeout is 10 seconds. | ||
|
|
||
| ```typescript | ||
| const prediction = await client.predictWithSchema(schema, predictionData, { | ||
| timeout: 30000 // 30 seconds | ||
| }); | ||
| ``` | ||
|
|
||
| ### Combining Resilience Patterns | ||
|
|
||
| Combine multiple resilience patterns for comprehensive protection: | ||
|
|
||
| <!-- vale off --> | ||
|
|
||
| ```typescript | ||
| import { retry, timeout, circuitBreaker } from '@sap-cloud-sdk/resilience'; | ||
|
|
||
| const prediction = await client.predictWithSchema(schema, predictionData, { | ||
| middleware: [ | ||
davidkna-sap marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| retry({ maxRetries: 3, backoffType: 'exponential', initialDelay: 1000 }), | ||
| circuitBreaker({ failureThreshold: 5, recoveryTimeout: 60000 }), | ||
|
||
| timeout(30000) | ||
|
|
||
| }); | ||
| ``` | ||
|
|
||
| <!-- vale on --> | ||
Uh oh!
There was an error while loading. Please reload this page.