Skip to content

Subscriptions: bi-di index on per subscription#7770

Merged
yaron2 merged 8 commits into
dapr:masterfrom
JoshVanL:bi-di-subscriptions-index-sub
Jun 20, 2024
Merged

Subscriptions: bi-di index on per subscription#7770
yaron2 merged 8 commits into
dapr:masterfrom
JoshVanL:bi-di-subscriptions-index-sub

Conversation

@JoshVanL

Copy link
Copy Markdown
Contributor

Index on per subscription so that streams or Subscription hot reloading events will only reload that specific subscription, rather than reloading every subscription for that PubSub component. This dramatically reduces disruption to topic subscriptions for a given PubSub component.

Branched from #7757

dapr/proposals#52

@cicoyle cicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Few comments from me, but generally looks good 👍🏻

Comment thread pkg/api/grpc/grpc_test.go
Resiliency: resiliency.New(nil),
}),
pubsubAdapter: &daprt.MockPubSubAdapter{},
outbox: outboxfake.New(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a nit, but upon looking at our naming convention in dapr, I see fake<x>. Can this be renamed to fakeoutbox? or mockoutbox?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is more correct the name follows the package hierarchy outboxfake "github.com/dapr/dapr/pkg/outbox/fake"

Comment thread pkg/api/grpc/subscribe.go Outdated
Comment thread pkg/api/grpc/subscribe.go
Comment thread pkg/runtime/compstore/subscriptions.go Outdated
Comment thread pkg/runtime/compstore/subscriptions.go Outdated
}

func (c *ComponentStore) ListDeclarativeSubscriptions() []subapi.Subscription {
func (c *ComponentStore) ListSubscriptionsAppByPubSub(name string) []*NamedSubscription {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (c *ComponentStore) ListSubscriptionsAppByPubSub(name string) []*NamedSubscription {
func (c *ComponentStore) ListPubSubSubscriptions(name string) []*NamedSubscription {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I like this name as it is more explicit- We are listing subscriptions, which are either programmatic or declarative (i.e. app callback based), which are subscribed to the given pubsub name.

}

func (c *ComponentStore) GetDeclarativeSubscription(name string) (subapi.Subscription, bool) {
func (c *ComponentStore) ListSubscriptionsStreamByPubSub(name string) []*NamedSubscription {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (c *ComponentStore) ListSubscriptionsStreamByPubSub(name string) []*NamedSubscription {
func (c *ComponentStore) ListPubSubSubscriptionsStreams(name string) []*NamedSubscription {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same here

Comment thread pkg/runtime/pubsub/publisher/fake/fake.go Outdated
Comment thread pkg/runtime/pubsub/publisher/fake/fake_test.go Outdated
Comment thread tests/integration/suite/daprd/hotreload/selfhosted/subscriptions/subscriptions.go Outdated
JoshVanL added 7 commits June 20, 2024 14:54
Adds SubscribeTopicEvents proto API which dynamically subscribes to
pubsub topics based on dapr/proposals#52.

This is a basic gRPC implementation of the API whereby, like
Subscription hot-reloading today, subscribing to a topic will reload
_every_ active subscription for the current daprd. In a future PR,
reloading of Subscriptions will be granular to the specific pubsub
topic.

Stream subscriptions are also only active once daprd declares the
application as both present and ready. Dynamic stream subscriptions
should be active both whether a app is running or not, as well as
whether it is ready or not. This will be addressed in a future PR.

Signed-off-by: joshvanl <[email protected]>
healthz.

Refactors pubsub machinery to allow for gRPC bi-directional subcription
streaming when there is no application, or the application in unhealhty.

dapr/proposals#52

Signed-off-by: joshvanl <[email protected]>
Signed-off-by: joshvanl <[email protected]>
Index on per subscription so that streams or Subscription hot reloading
events will only reload that specific subscription, rather than
reloading _every_ subscription for that PubSub component. This
dramatically reduces disruption to topic subscriptions for a given
PubSub component.

Signed-off-by: joshvanl <[email protected]>
@JoshVanL
JoshVanL force-pushed the bi-di-subscriptions-index-sub branch from 3679fff to 99bafe8 Compare June 20, 2024 15:43
@JoshVanL
JoshVanL marked this pull request as ready for review June 20, 2024 15:44
@JoshVanL
JoshVanL requested review from a team as code owners June 20, 2024 15:44
Comment thread pkg/api/grpc/subscribe.go
}

if err := a.processor.Subscriber().ReloadPubSub(req.GetPubsubName()); err != nil {
if err := a.processor.Subscriber().StartStreamerSubscription(key); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can key ever be empty or nil and if so should we do a nil check before starting the streamer subscription? I only see key being returned here key := a.pubsubAdapterStreamer.StreamerKey(req.GetPubsubName(), req.GetTopic()) but am uncertain if it could cause issues if returned unset and used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, key is just a string concatenation function of the given strings so it won't be nil or empty

func (s *streamer) StreamerKey(pubsub, topic string) string {

@cicoyle cicoyle left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@yaron2
yaron2 merged commit 807a128 into dapr:master Jun 20, 2024
AnnuCode pushed a commit to AnnuCode/dapr that referenced this pull request Aug 7, 2024
* Subscriptions: bi-directional subscription & publish streaming.

Adds SubscribeTopicEvents proto API which dynamically subscribes to
pubsub topics based on dapr/proposals#52.

This is a basic gRPC implementation of the API whereby, like
Subscription hot-reloading today, subscribing to a topic will reload
_every_ active subscription for the current daprd. In a future PR,
reloading of Subscriptions will be granular to the specific pubsub
topic.

Stream subscriptions are also only active once daprd declares the
application as both present and ready. Dynamic stream subscriptions
should be active both whether a app is running or not, as well as
whether it is ready or not. This will be addressed in a future PR.

Signed-off-by: joshvanl <[email protected]>

* Subscriptions: bi-directional subscription streaming- subscribe on no
healthz.

Refactors pubsub machinery to allow for gRPC bi-directional subcription
streaming when there is no application, or the application in unhealhty.

dapr/proposals#52

Signed-off-by: joshvanl <[email protected]>

* Fix unit tests

Signed-off-by: joshvanl <[email protected]>

* Fix subscription allowed

Signed-off-by: joshvanl <[email protected]>

* Subscriptions: bi-di index on per subscription

Index on per subscription so that streams or Subscription hot reloading
events will only reload that specific subscription, rather than
reloading _every_ subscription for that PubSub component. This
dramatically reduces disruption to topic subscriptions for a given
PubSub component.

Signed-off-by: joshvanl <[email protected]>

* Lock streamer when sending topic mesgae to stream connection

Signed-off-by: joshvanl <[email protected]>

* Log Info when a streaming subscription unsubscribes

Signed-off-by: joshvanl <[email protected]>

---------

Signed-off-by: joshvanl <[email protected]>
Signed-off-by: Annu Singh <[email protected]>
jake-engelberg pushed a commit to jake-engelberg/dapr that referenced this pull request Sep 20, 2024
* Subscriptions: bi-directional subscription & publish streaming.

Adds SubscribeTopicEvents proto API which dynamically subscribes to
pubsub topics based on dapr/proposals#52.

This is a basic gRPC implementation of the API whereby, like
Subscription hot-reloading today, subscribing to a topic will reload
_every_ active subscription for the current daprd. In a future PR,
reloading of Subscriptions will be granular to the specific pubsub
topic.

Stream subscriptions are also only active once daprd declares the
application as both present and ready. Dynamic stream subscriptions
should be active both whether a app is running or not, as well as
whether it is ready or not. This will be addressed in a future PR.

Signed-off-by: joshvanl <[email protected]>

* Subscriptions: bi-directional subscription streaming- subscribe on no
healthz.

Refactors pubsub machinery to allow for gRPC bi-directional subcription
streaming when there is no application, or the application in unhealhty.

dapr/proposals#52

Signed-off-by: joshvanl <[email protected]>

* Fix unit tests

Signed-off-by: joshvanl <[email protected]>

* Fix subscription allowed

Signed-off-by: joshvanl <[email protected]>

* Subscriptions: bi-di index on per subscription

Index on per subscription so that streams or Subscription hot reloading
events will only reload that specific subscription, rather than
reloading _every_ subscription for that PubSub component. This
dramatically reduces disruption to topic subscriptions for a given
PubSub component.

Signed-off-by: joshvanl <[email protected]>

* Lock streamer when sending topic mesgae to stream connection

Signed-off-by: joshvanl <[email protected]>

* Log Info when a streaming subscription unsubscribes

Signed-off-by: joshvanl <[email protected]>

---------

Signed-off-by: joshvanl <[email protected]>
Signed-off-by: Jake Engelberg <[email protected]>
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.

3 participants