Add configurable ackDeadline to GCP Pub/Sub component #3422
+46
−1
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.
Description
(
ackDeadline
) for the GCP Pub/Sub component within Dapr's components-contrib repository. Previously, the acknowledgment deadline was hardcoded to 20 seconds. This change allows users to specify a custom acknowledgment deadline through the component's metadata, thus providing greater flexibility to tailor behavior to specific workload requirements.Motivation
In many scenarios, the hardcoded 20-second deadline may not be optimal. Applications with varying processing times may require longer deadlines to prevent premature message redelivery, which can lead to increased costs and workload on services. Making this value configurable allows users to optimize their systems based on actual performance and needs.
Changes
Metadata Structure: Added an AckDeadline field to the metadata struct to hold the user-defined acknowledgment deadline.
Default Value: Set a default acknowledgment deadline (defaultAckDeadline) to 20 seconds to maintain backward compatibility.
Metadata Parsing: Updated the createMetadata function to parse the ackDeadline from the component's metadata, with validation to ensure it is a positive integer.
Subscription Configuration: Modified the subscription configuration logic in the ensureSubscription method to utilize the user-configured ackDeadline.
Testing: Enhanced the test suite to include tests for validating the behavior with a specified ackDeadline, handling of invalid values, and default behavior when not specified.
Testing
Comprehensive tests were added to validate:
The correct parsing and application of a valid ackDeadline.
Proper error handling when an invalid ackDeadline is provided.
The use of the default ackDeadline when none is specified.
These tests ensure that the new functionality behaves as expected and that existing functionalities remain unaffected.
Impact
This change is backward compatible. Existing configurations without a specified ackDeadline will use the default value, ensuring that current implementations will operate without modifications. New users can specify an ackDeadline to suit their specific needs.
Issue reference
We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.
Please reference the issue this PR will close: #[issue number]
#3421
Checklist
Please make sure you've completed the relevant tasks for this PR, out of the following list: