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

feat: make it possible to filter message by origin #223

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

octonato
Copy link
Member

@octonato octonato force-pushed the octonato/origin-region-consumer branch 3 times, most recently from d80a8b4 to 16457cb Compare February 17, 2025 17:23
@octonato octonato force-pushed the octonato/origin-region-consumer branch from 16457cb to f64be05 Compare February 18, 2025 16:47
Copy link
Member Author

@octonato octonato left a comment

Choose a reason for hiding this comment

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

Some updates on this PR.

  • consumer and views receive originRegion in context
  • all components can have access to selfRegion via Context

Some other ideas that we can include here or in follow-up. We might want to add API to set the originRegion in the Eventing Testkit.

/**
* Returns the region where this instance is running.
*/
String selfRegion();
Copy link
Member Author

Choose a reason for hiding this comment

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

Context is ubiquitous. All contexts inherit from it. By adding the selfRegion here we make it possible to always check 'where' we are.

This includes component creation contexts, command contexts, http request context and consumer messages (both consumers and views).


import java.util.Optional;

public interface OriginAwareContext extends Context {
Copy link
Member Author

Choose a reason for hiding this comment

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

MessageContext (Consumer) and UpdateContext (Views) now extends OriginAwareContext which gives access to the originRegion and method hasLocalOrigin.

*
* @return the region where a message was first created. When not applicable, it returns an empty Optional.
*/
Optional<String> originRegion();
Copy link
Contributor

@aludwiko aludwiko Feb 18, 2025

Choose a reason for hiding this comment

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

I mentioned this on the runtime side, but maybe I should do it here. In my opinion, it feels more natural to get the originRegion information from the metadata. We can add a helper method extract it, similar to subject, time, etc., I guess there was a reason to make it this way, what was that?

Copy link
Contributor

Choose a reason for hiding this comment

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

hasLocalOrigin is nice, but if that is the only reason, I think users can create such a method themselves if they need it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the implementation with meta will also be much simpler because we are passing this information through all the layers from the runtime to the sdk.

Copy link
Member Author

@octonato octonato Feb 18, 2025

Choose a reason for hiding this comment

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

The reason why I didn't add it to the metadata is because we used to also have JWT and ACL there and we stepped away from it. JWT and ACL is now only present on the endpoints request, which makes more sense.

Also, metadata is available in places where it doesn't make sense to have the originRegion, for example in commands. We should have it only when consuming messages.

Copy link
Member Author

Choose a reason for hiding this comment

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

About hasLocalOrigin, the method impl is quite simple and indeed anyone can implement this logic, but there is some hidden knowledge in there that otherwise we will need to document.

  1. empty means we are consuming from a broker or service-to-service, so not local
    (we will have to document this)
  2. for non-empty origins, it needs to match selfRegion, so it depends
    (this is easy and kind of obvious)
  3. in dev-mode, both will be "" and therefore local by definition
    (this is also hidden logic that this method is encapsulating)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, metadata is available in places where it doesn't make sense to have the originRegion, for example in commands. We should have it only when consuming messages.

Good point, but that implies that we have a leaking abstraction because I can run metadata.asCloudEvent in my command handler, which doesn't make any sense. Maybe we should have a separate CommandMetadata, Message/EventMetadata ?

@octonato octonato force-pushed the octonato/origin-region-consumer branch from f64be05 to 7158c73 Compare February 18, 2025 19:45
@patriknw
Copy link
Member

in docs we have a todo, related to this:

ifdef::todo[TODO: describe conditional processing https://github.com/lightbend/kalix-runtime/issues/3098 ]

@octonato
Copy link
Member Author

in docs we have a todo, related to this:

ifdef::todo[TODO: describe conditional processing https://github.com/lightbend/kalix-runtime/issues/3098 ]

Sure, we will need to document this.

@octonato octonato force-pushed the octonato/origin-region-consumer branch from 7158c73 to c6bd4a8 Compare February 20, 2025 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants