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

Allow setting Expiration Policy on Subscriptions created via Pub Sub Binder #2876

Closed
jmitash opened this issue May 13, 2024 · 5 comments · Fixed by #2894 or #2897
Closed

Allow setting Expiration Policy on Subscriptions created via Pub Sub Binder #2876

jmitash opened this issue May 13, 2024 · 5 comments · Fixed by #2894 or #2897
Labels

Comments

@jmitash
Copy link
Contributor

jmitash commented May 13, 2024

When Pub Sub subscriptions are created, if no expiration policy is specified they expire by default in 31 days. In the setup I am working with, it is common for there to be little activity for long periods of times on some streams. For some of these streams, we spin up consumers reactively once a batch of messages are queued in the subscription (as opposed to having them idle year-round). However, because the subscription is quiet for so long, sometimes it is automatically deleted in between batches. Since there is no way to set the expiration policy on the Binder's auto-created subscriptions, I must create them externally.

I would like to be able to configure the expiration policy for auto-created subscriptions so I don't have to rely on external setup.

If desired, I am happy to contribute this change. I have already prepared it for my own use: main...jmitash:spring-cloud-gcp:feat/pubsub-binder-expiration-config.

@meltsufin meltsufin added pubsub type: enhancement New feature or request labels May 13, 2024
@meltsufin
Copy link
Member

@jmitash Thanks for bringing this up. I didn't realize there was this 31 day expiration default. What's the error message that you get when this happens?

I think this is a very reasonable feature request. @burkedavison WDYT?

@jmitash
Copy link
Contributor Author

jmitash commented May 13, 2024

According to the docs, basically if anything is connecting to the subscription, it counts as activity and resets the deletion timer:

If Pub/Sub detects subscriber activity or if you update any of the subscription properties, the subscription deletion clock restarts. Examples of subscriber activities include open connections, active pulls, or successful pushes.

So I don't think people would see an error because the subscription should not be expired while still in active use. But I'm not 100% certain of that because I'm not sure how exactly they count those things (e.g. what makes a pull "active"? do only new connections count?).

In my case, these streams that are deleted are related to a job initiated by a manual CSV upload. The job is only run a few times a year. So instead of leaving our SCS applications running idle 99% of the time, we set them up so that they start off scaled to zero until there is a backlog of messages. This is done by a different tool which uses the Google Cloud Monitoring API, so it does not count as subscription activity. Because the normal state is not running at all, nothing is pulling when the subscription is deleted, the subscriptions reach the 31 day expiration and get deleted. But because once the application does start up and creates all the subscriptions again, there is no error, but the messages that should have gone to that subscription before then are lost.

@burkedavison
Copy link
Member

SGTM

@meltsufin
Copy link
Member

@jmitash Thanks for the explanation. If you are comfortable opening a pull request for this, we will take a look.

burkedavison added a commit that referenced this issue May 21, 2024
…2876) (@jmitash) (#2897)

* feat: configurable expiration policy on auto-created subscriptions (#2894)

* Add properties for Binder expiration policy

* Set Expiration Policy when creating Subscription

* Treat non-positive durations as "never expire"

* Use Google Java formatting

* docs: add expiration policy section to pubsub

* chore: access autocreate value from properties

* chore: fix test

* docs: correct never expire logic

* chore: add example of setting expirationPolicy.ttl to pubsub-stream functional sample

* docs: update stream binder docs with configuration options

* Update docs/src/main/asciidoc/pubsub.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

* Update docs/src/main/asciidoc/pubsub.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

* Update docs/src/main/asciidoc/pubsub.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

* Update docs/src/main/asciidoc/spring-stream.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

* Update docs/src/main/asciidoc/spring-stream.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

* Update docs/src/main/asciidoc/spring-stream.adoc

Co-authored-by: Mike Eltsufin <meltsufin@google.com>

---------

Co-authored-by: Jacob Mitash <jacob@mitash.org>
Co-authored-by: Mike Eltsufin <meltsufin@google.com>
@burkedavison
Copy link
Member

Fixed in #2897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment