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

Replace FSM’s old registry pattern with newly suggested pattern #14266

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Mathew-Estafanous
Copy link
Contributor

@Mathew-Estafanous Mathew-Estafanous commented Aug 18, 2022

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

@Mathew-Estafanous
Copy link
Contributor Author

@kisunji
Sorry for the ping, but do you have any ideas as to what might be the cause for the failed integration tests? I don’t really understand how my changes are causing the failed tests.

@kisunji
Copy link
Contributor

kisunji commented Aug 18, 2022

@kisunji Sorry for the ping, but do you have any ideas as to what might be the cause for the failed integration tests? I don’t really understand how my changes are causing the failed tests.

Hey! If you rebase from main I think the tests should stop failing. It was an authorization issue with forked repos so your logic wouldn't have caused anything to fail.

edit: spoke too soon! #14257 should fix the issue. Until then you can ignore the integration test failures; we can work around it

@Mathew-Estafanous
Copy link
Contributor Author

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 replace-fsm-registry-pattern. 😅 Is it ok to continue with a code review with this PR or should I open anther one with the proper branch name?

@kisunji
Copy link
Contributor

kisunji commented Aug 19, 2022

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 replace-fsm-registry-pattern. 😅 Is it ok to continue with a code review with this PR or should I open anther one with the proper branch name?

That's totally fine. Is this ready for review? It will need some enterprise-side changes on our end but looks simple enough

@Mathew-Estafanous
Copy link
Contributor Author

yup it should be ready for review!

return commands
}

func registerEnterpriseCommands(registry map[structs.MessageType]command, fsm *FSM) {}
Copy link
Contributor

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.

}
return nil
}
func RegisteredRestorer() map[structs.MessageType]restorer {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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.

@@ -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{
Copy link
Contributor

@kisunji kisunji Sep 13, 2022

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.

Copy link
Contributor Author

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.

@kisunji kisunji added pr/no-changelog PR does not need a corresponding .changelog entry pr/no-metrics-test labels Sep 13, 2022
s.persistPeeringTrustBundles,
s.persistPeeringSecrets,
}
registerEnterprisePersisters(registry, s)
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/no-changelog PR does not need a corresponding .changelog entry pr/no-metrics-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants