-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Replace FSM’s old registry pattern with newly suggested pattern #14266
base: main
Are you sure you want to change the base?
Replace FSM’s old registry pattern with newly suggested pattern #14266
Conversation
@kisunji |
Hey! If you rebase from edit: spoke too soon! #14257 should fix the issue. Until then you can ignore the integration test failures; we can work around it |
Ahh ok, that makes a lot more sense. Thanks! I also just realized that I opened this PR with my dev branch instead of the proper branch |
That's totally fine. Is this ready for review? It will need some enterprise-side changes on our end but looks simple enough |
yup it should be ready for review! |
1aa00f4
to
0158a67
Compare
agent/consul/fsm/commands_oss.go
Outdated
return commands | ||
} | ||
|
||
func registerEnterpriseCommands(registry map[structs.MessageType]command, fsm *FSM) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move most of this file to a new file called commands.go
and leave the empty registerEnterpriseCommands
in commands_oss.go
with this directive at the top:
//go:build !consulent
On the enterprise side we have another file called commands_ent.go
which will have the enterprise implementation.
agent/consul/fsm/snapshot_oss.go
Outdated
} | ||
return nil | ||
} | ||
func RegisteredRestorer() map[structs.MessageType]restorer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as commands_oss.go
. Could the common code go to snapshot.go
, leaving only registerEnterpriseRestorers
in the oss-version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need registerEnterprisePersisters
or is it only for Restorers
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also should I add
//go:build !consulent
to the top of snapshot_oss.go
as well or is it just for commands_oss.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah please add it! We would want registerEnterprisePersisters
as well.
dfffe30
to
8c22485
Compare
8c22485
to
58b3eba
Compare
agent/consul/fsm/snapshot.go
Outdated
@@ -104,3 +83,934 @@ func (s *snapshot) Persist(sink raft.SnapshotSink) error { | |||
func (s *snapshot) Release() { | |||
s.state.Close() | |||
} | |||
|
|||
func RegisteredRestorer() map[structs.MessageType]restorer { | |||
registry := map[structs.MessageType]restorer{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last feedback I found while working on the enterprise side:
We actually lost the "this is already registered" check on this registry map.
It's not a big deal on OSS since the compiler natively checks for duplicate keys but in ENT I need to do something like:
func registerEnterpriseRestorers(m map[structs.MessageType]restorer) {
m[structs.EnterpriseType1] = restoreEnterpriseType1
m[structs.EnterpriseType2] = restoreEnterpriseType2
m[structs.EnterpriseType3] = restoreEnterpriseType3
}
which can't check for overwriting keys.
Do you think we could make a registerRestorer
func similar to what you did in commands.go
and add some validation?
I could simply add it to the enterprise side only but it would be nice to have the OSS and ENT versions both call common code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just pushed those changes.
I also thought that it might be better to make a small(ish) change to command.go
by removing the named struct (entry
) and just making it an anonymous struct. I thought that it would prevent misuse or confusion, since the name is pretty vague by itself.
684d34d
to
7a86e6a
Compare
agent/consul/fsm/snapshot.go
Outdated
s.persistPeeringTrustBundles, | ||
s.persistPeeringSecrets, | ||
} | ||
registerEnterprisePersisters(registry, s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found another issue while testing this. Unlike maps, slices are passed as copies so registerEnterprisePersisters
cannot actually add persisters to the registry
.
Can we change the signature so it simply returns a slice of only the enterprise persisters?
Description
As suggested by the linked issue, I transitioned to the new pattern for the FSM operations and snapshot registries. I wasn’t sure if any of the registries needed enterprise mapping as well, so I went ahead and created a noop function for each registry where enterprise mappings can be added.
Links
Working on issue #11740
This PR is a continuation of a previously merged PR, #12729