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

Refactor code into separate packages. #752

Merged
merged 4 commits into from
Jan 11, 2023
Merged

Conversation

cristiangreco
Copy link
Contributor

Move existing files into a few separate packages. This should improve testability and make future refactorings easier.

@cristiangreco cristiangreco force-pushed the cristian/refactor-pkg branch 2 times, most recently from fecd54c to 3ea403d Compare January 7, 2023 12:49
Move existing files into a few separate packages. This should improve
testability and make future refactorings easier.
pkg/exporter/update.go Outdated Show resolved Hide resolved
@@ -1,4 +1,4 @@
package exporter
package services
Copy link
Contributor

Choose a reason for hiding this comment

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

This file feels a little out of place here since it's not helping define supported services like services.go. TaggedResource and FilterThroughTags is used by services but I I'm not sure the services pkg owns the definition of a TaggedResource. I think it might fit better with the job pkg, WDYT?

return nil
}

func (c *ScrapeConf) Load(file *string, validSvc func(string) bool) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This refactor stood out, it feels a bit odd to allow a consumer to provide a func which validates the services. I think I would expect a defined way to do that as the default behavior of loading the config. What are your thoughts 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.

Totally agree. I've resorted to this approach to avoid a dependency loop: almost all other pkgs depend on config, including services, so couldn't make config depend on services.

Might move services.go into config pkg... a bit extreme but might make sense on a level. What do you suggest?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yeah I didn't think about the depenency loop 😢 . I think moving services.go to the config pkg sounds like a good plan for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Second thought, related to the comment on aws_tags.go above. Moving services.go to pkg/config make the latter depend on pkg/services (or whatever other package where aws_tags.go is placed). Again a loop.

A possible alternative is a code refactoring where services.go is split in something like: all the const stuff (names, aliases, etc) is moved to a struct of some sort in pkg/config, while the {Filter,Resource}Func and everything else that depends on aws_tags.go definitions is kept in services.go. (plus some additional changes here and there to deal with the fact SupportedServices is being split)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kgeckhart wdyt if this is merged as-is and I give a try to a code refactor just after it? (before cutting a new release anyway)

Copy link
Contributor

@kgeckhart kgeckhart Jan 10, 2023

Choose a reason for hiding this comment

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

👍 makes sense to let this clear and adjust further later. This is already a great step in the right direction.

@cristiangreco cristiangreco merged commit d6cc090 into master Jan 11, 2023
@cristiangreco cristiangreco deleted the cristian/refactor-pkg branch January 11, 2023 10:33
cristiangreco added a commit that referenced this pull request Jan 16, 2023
Extract out supported services list into the config package, and leave
filtering funcs in the services package.

Followup of #752
cristiangreco added a commit that referenced this pull request Jan 17, 2023
Extract out supported services list into the config package, and leave
filtering funcs in the services package.

Followup of #752
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants