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

Gatherer/Gatherers plugin management #114

Merged
merged 11 commits into from
Sep 27, 2022
Merged

Conversation

CDimonaco
Copy link
Member

@CDimonaco CDimonaco commented Sep 23, 2022

This PR contains an implementation of a "gatherer" manager, a component made in order to extract the responsability of gatherers management into a separate component, contained into gatherer package.

This component will be injected as dependency and initialized when the agents starts with the appropriate configuration.

The plugin management, is moved to the gatherers package in order to segregate responsabilities, infact the plugin system offer the capability of adding new fact gatherers.

Some cleanup and initialization is made to support this refactoring.

Various tests refactoring with auto generated mocks.

@CDimonaco CDimonaco changed the title Gatherer Manager Gatherer/Gatherers plugin management Sep 23, 2022
@CDimonaco CDimonaco force-pushed the available_gatherers_manager branch from b0c08e9 to ccdaba8 Compare September 23, 2022 14:35
@CDimonaco CDimonaco marked this pull request as ready for review September 23, 2022 14:40
@CDimonaco CDimonaco self-assigned this Sep 23, 2022
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Hey @CDimonaco ,
It looks really good.
I just added some comments on things that I think we could discuss about!

internal/factsengine/gatherers/manager.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/manager_test.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/manager_test.go Outdated Show resolved Hide resolved
internal/factsengine/gatherers/manager_test.go Outdated Show resolved Hide resolved
internal/factsengine/gathering_test.go Show resolved Hide resolved
internal/factsengine/policy_test.go Outdated Show resolved Hide resolved
internal/factsengine/factsengine_test.go Show resolved Hide resolved
internal/factsengine/gatherers/manager_test.go Outdated Show resolved Hide resolved
cmd/facts.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rtorrero rtorrero left a comment

Choose a reason for hiding this comment

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

LGTM, some minor comments

internal/factsengine/gathering.go Outdated Show resolved Hide resolved
func (s *ErrorGatherer) Gather(_ []entities.FactRequest) ([]entities.Fact, error) {
return nil, &entities.FactGatheringError{Type: "dummy-type", Message: "some error"}
}

func (suite *GatheringTestSuite) TestGatheringGatherFacts() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this naming for this test, but I think other tests are still using the previous prefix, e.g. TestFactsEngineGatherFacts which is a bit confusing IMO

Am I missing something?

@CDimonaco CDimonaco requested a review from arbulu89 September 27, 2022 09:20
Copy link
Contributor

@arbulu89 arbulu89 left a comment

Choose a reason for hiding this comment

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

Perfect!
(just a comment about renaming a test funtion name)

suite.Equal(expectedGatherers, result)
}

func (suite *TestManager) TestFactsEngineGetGathererNotFound() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test name still need to be changed hehe
FactsEngine to Manager

cmd/facts.go Outdated
@@ -81,17 +81,29 @@ func gather(*cobra.Command, []string) {
var argument = viper.GetString("argument")
var pluginsFolder = viper.GetString("plugins-folder")

engine := factsengine.NewFactsEngine("", "")
gathererManager := gatherers.NewManager(gatherers.StandardGatherers())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could have a gatherers.NewManagerWithPlugins(gatherers.StandardGatherers(), pluginsFolder to remove some duplicated code

Copy link
Member

@nelsonkopliku nelsonkopliku left a comment

Choose a reason for hiding this comment

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

Good job!

Only reasoning point I might raise is the Manager terminology.
I find it sometimes a bit too generic: what aspects is it managing? What does it actually mean manage, it can be really anything, and it can imply a lot of things.

This reminds me of some past not-so-nice experiences, where some sort of Manager in the code became sort of a god class/module 😅

What do you think about a more explicit variant Registry, or similar?
A place where you track all the available gatherers. That is where you can add and retrieve (get) them.

Just an idea, naming is hard 😄

Copy link
Contributor

@dottorblaster dottorblaster left a comment

Choose a reason for hiding this comment

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

@nelsonkopliku

There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton

@CDimonaco
Copy link
Member Author

Good job!

Only reasoning point I might raise is the Manager terminology.

I find it sometimes a bit too generic: what aspects is it managing? What does it actually mean manage, it can be really anything, and it can imply a lot of things.

This reminds me of some past not-so-nice experiences, where some sort of Manager in the code became sort of a god class/module 😅

What do you think about a more explicit variant Registry, or similar?

A place where you track all the available gatherers. That is where you can add and retrieve (get) them.

Just an idea, naming is hard 😄

Absolutely, great idea, manager was really a temp name 🤣

Registry is more appropriate, I will change that

@CDimonaco CDimonaco force-pushed the available_gatherers_manager branch from 91ddfb8 to ad0d852 Compare September 27, 2022 15:48
@CDimonaco
Copy link
Member Author

Renamed to Registry.

Ready to merge! 🚀

@CDimonaco CDimonaco merged commit 91a6663 into main Sep 27, 2022
@stefanotorresi stefanotorresi deleted the available_gatherers_manager branch October 3, 2022 11:06
@nelsonkopliku nelsonkopliku added the enhancement New feature or request label Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

5 participants