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

Add configurable ackDeadline to GCP Pub/Sub component #3422

Merged
merged 7 commits into from
Jun 26, 2024

Conversation

mahparaashley
Copy link
Contributor

@mahparaashley mahparaashley commented May 21, 2024

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:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#[issue number]

Copy link
Contributor

@ItalyPaleAle ItalyPaleAle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pubsub/gcp/pubsub/pubsub.go Outdated Show resolved Hide resolved
Signed-off-by: mashley@rechargeapps.com <mashley@rechargeapps.com>
@mahparaashley mahparaashley force-pushed the improve-ack-deadline-flexibility branch from 063057d to 3637c71 Compare May 21, 2024 20:32
Updated the AckDeadline field in the metadata struct to use time.Duration instead of int. This change allows Dapr to interpret the acknowledgment deadline as either seconds or Go duration strings, providing greater flexibility and usability for configuring message acknowledgment timeouts.

Signed-off-by: mashley@rechargeapps.com <mashley@rechargeapps.com>
@yaron2
Copy link
Member

yaron2 commented Jun 24, 2024

@mahparaashley please resolve the conflict

@berndverst
Copy link
Member

This PR is in rough shape. Why was the metadata struct type moved into pubsub.go which is now a duplicate from the one declared in the same package in metadata.go ?

I'll try to fix it up. Please be more conscious of compiler / linter errors. You can run make test and make lint locally.

@mahparaashley
Copy link
Contributor Author

This PR is in rough shape. Why was the metadata struct type moved into pubsub.go which is now a duplicate from the one declared in the same package in metadata.go ?

I'll try to fix it up. Please be more conscious of compiler / linter errors. You can run make test and make lint locally.

berndverst Thank you for your feedback. This was my first time working with Go, and I am still learning. I will take a look at it over the weekend.

Signed-off-by: Bernd Verst <github@bernd.dev>
@berndverst
Copy link
Member

This PR is in rough shape. Why was the metadata struct type moved into pubsub.go which is now a duplicate from the one declared in the same package in metadata.go ?
I'll try to fix it up. Please be more conscious of compiler / linter errors. You can run make test and make lint locally.

berndverst Thank you for your feedback. This was my first time working with Go, and I am still learning. I will take a look at it over the weekend.

It's ok I understand. We are now beyond code freeze. I pushed the fixes to your PR so I can merge the PR into the release. Otherwise you would have to wait 3 months for this feature!

Signed-off-by: Bernd Verst <github@bernd.dev>
@berndverst
Copy link
Member

@mahparaashley for the changes I made primarily look at this commit. 8f214c8

Since you used time.Duration for the metadata the value does not need to be converted to metadata explicitly. The way our code works, this allows users to specify durations like "1m30s" or "5s" or "6h" etc. But we also support unit less numbers like "12" to simply refer to seconds. These duration strings are preferred - so you used the correct data type here. When you to value comparison after metadata parsing however you need to also convert to the relevant duration type.

Those were the main changes besides some incorrect instantiation of types or declarations of properties.

I pushed my changes to your PR and will merge it. This way you can get credit for the contribution, but unfortunately I cannot wait for you to fix it up at this point given our code freeze.

@berndverst berndverst merged commit 1375f08 into dapr:main Jun 26, 2024
87 of 88 checks passed
@mahparaashley
Copy link
Contributor Author

@berndverst Thank you so much!

@mahparaashley mahparaashley deleted the improve-ack-deadline-flexibility branch June 26, 2024 20:10
@berndverst berndverst added this to the v1.14 milestone Jul 23, 2024
@marcduiker
Copy link
Contributor

@holopin-bot @mahparaashley Thank you!

Copy link

holopin-bot bot commented Aug 15, 2024

Congratulations @mahparaashley, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/clzv9qhjj22650cl54pn9wle5

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants