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

events: Add filters to keep track of local and other subscriptions #24201

Merged
merged 5 commits into from
Nov 30, 2023

Conversation

swenson
Copy link
Contributor

@swenson swenson commented Nov 20, 2023

This adds a very basic implementation of a list of namespace+eventType combinations that each node is interested in by just running the glob operations in for-loops. Some parallelization is possible, but not enabled by default.

It only wires up keeping track of what the local event bus is interested in for now (but doesn't use it yet to filter messages).

@swenson swenson requested a review from a team November 20, 2023 19:05
@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label Nov 20, 2023
@swenson swenson added this to the 1.16.0-rc1 milestone Nov 20, 2023
This adds a very basic implementation of a list of namespace+eventType
combinations that each node is interested in by just running the
glob operations in for-loops. Some parallelization is possible, but
not enabled by default.

It only wires up keeping track of what the local event bus is interested
in for now (but doesn't use it yet to filter messages).
Copy link

Build Results:
All builds succeeded! ✅

Copy link

github-actions bot commented Nov 20, 2023

CI Results:
All Go tests succeeded! ✅

…ions; local node is probably better anyway
Copy link
Contributor

@tomhjp tomhjp left a comment

Choose a reason for hiding this comment

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

LGTM - just a few suggestions

patterns []pattern
}

func (nf *NodeFilter) match(nsPath string, eventType logical.EventType) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to accept *namespace.Namespace instead of string for all the nsPath parameters in this file - that way callers don't have to worry about the exact format of the path (should it have a trailing slash, should it be absolute or relative, etc) and can just pass something they know is safe by its type.

vault/eventbus/bus.go Outdated Show resolved Hide resolved
@@ -192,11 +181,25 @@ func NewEventBus(logger hclog.Logger) (*EventBus, error) {
logger = hclog.Default().Named("events")
}

sourceUrl, err := url.Parse("vault://" + localNodeID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably worth a changelog note?

func (f *Filters) anyMatch(nsPath string, eventType logical.EventType) bool {
f.lock.RLock()
defer f.lock.RUnlock()
if f.parallel {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the number of parallel goroutines is equal to the number of nodes (always going to be small), and all the data is local, are we sure it's worth adding this parallel path? I'd err on the side of simplicity until we have data to back up the need for parallelism here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I went back and forth on this one. There are a lot of potential optimizations that could be done (combining/simplifying globs into regexes, parallelization, using a more sophisticated tree matching data structure, etc.), but it all seems a bit premature. I'll remove this for now.

}
filters.patterns = slices.DeleteFunc(filters.patterns, func(m pattern) bool {
return m.eventTypePattern == check.eventTypePattern &&
slices.Equal(m.namespacePatterns, check.namespacePatterns)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given we're checking for slice equality to remove patterns, perhaps we should sort this slice on the way in to make the equality check a little more reliable?

Christopher Swenson and others added 2 commits November 27, 2023 14:54
Co-authored-by: Tom Proctor <tomhjp@users.noreply.github.com>
@swenson
Copy link
Contributor Author

swenson commented Nov 30, 2023

Thanks!

@swenson swenson merged commit 9d39b6f into main Nov 30, 2023
111 checks passed
@swenson swenson deleted the vault-21592/event-filters branch November 30, 2023 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants