-
Notifications
You must be signed in to change notification settings - Fork 4
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/typed-runtime-cfg #93
Conversation
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
… into refactor/typed-runtime-cfg
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
…m/sparrow into feat/simplify-helm-chart-config
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
@puffitos Can you create an issue to the validation part you've mentioned in your PR? |
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.
Regarding the Runtime
interface name, no better idea for now. Seems ok for me for now!
// enrichTargets updates the targets of the sparrow's checks with the | ||
// global targets. Per default, the two target lists are merged. | ||
func (s *Sparrow) enrichTargets(cfg runtime.Config) runtime.Config { | ||
if cfg.Empty() || s.tarMan == nil { |
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.
cfg.Empty
validation here seems a bit smelly since we are starting all checks if none is configured. (In the second reconciliation run though, targets will be enriched since the config is not empty anymore).
We might want to have a look at the reconciliation logic in a dedicated PR anyway, so this is not that important.
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.
Since there currently is no validation (outside the YAML syntax one) when grabbing a new runtime.Config
, the following config may also be pushed to the channel:
incoming := runtime.Config{}
// Parsed from an empty YAML file, which is a legit option
We should either stop something from this ever happening at loader-time, or just write a simple guard here, which makes more sense to me.
The point about reworking the function is valid.
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Added a dedicated error type to handle mismatched configs, if they can even happen. I've removed the nil cfg test for the health config, as the health can ATM never be nil when passed via a regular way.
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
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.
LGTM but can you open the validation issue I mentioned before and maybe an issue to your final remark regarding the mapping of check names to interfaces.
…fig format Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Signed-off-by: Bruno Bressi <bruno.bressi@telekom.de>
Motivation
Closes #72
Since we currently have no binding reasons of using
any
typed configurations if a strongly typed language, we should avoid doing that :) Please read through the text of the PR and come back to it. I've tried to explain everything done.It's only like 1000 lines of code changed 👍 Although I encourage organizing a call to go over the PR, please go through the changes yourselves; most of the changes are just renamings of imports... The important parts are the interface changes and mostly the ReconcileChecks function of the Sparrow. The rest was just doing due diligence and updating everything so that the code may compile.
Needless to say, to be merged after #91. Also includes most changes from that PR.
Changes
Any type removal
The
any
Configuration was removed in the following fashion:Config
, that represents the YAML file with the check’s runtime configuration was introduced.Config
struct was used everywhere, where themap[any]any
appeared.any
map can’t be expressed directly by a typedConfig
- this created the need for an interface for those CheckConfigs coming in each time to be able to differentiate between them, without doing type checking each time.Name
andGetConfig
).Config
structs must thus implement a new interface, currently namedRuntime
(used aschecks.Runtime
- I’m open to better names. The name occurred “organically” fromRuntimeConfig
, which is the current type being used in theconfig
package). This handles the checks and their configuration during the sparrow’s runtime and reconciliation methods.The rest was:
SetConfig
and implement theName
andGetConfig
run.go
- this was the most difficult part, as the ReconcileChecks function is heavy. We should see how we can simplify the logic, if that’s possible.Structural
Some moving around of packages had to be done, because of cyclic imports. We should generally avoid creating dedicated packages up until the point we realize, that a package is too big and handles too many responsibilities.
Changes:
types
package is gone, contents were moved tochecks
into abase.go
file, which contains the basic types for the checks and their results.errors
package was unneeded, can be part of thechecks
package. Also, naming packages after the stdlib is something we should avoid.register.go
file was replaced by an sister-to-checks
package namedfactory
, to give more meaning to the existence of this “registry” for checks. A factory to create the checks, given a runtime configuration. The management of which checks are available and their creation shouldn’t be part of thechecks
package, but a package which uses thechecks
package.runtime
package inchecks
was introduced, to handle the Runtime Configuration of the checks. It currently cannot be part of thechecks
package, as the checks themselves need this package to run. Maybe it’s place is in a different package altogether, or maybe we shouldn’t package the checks 🤷You may stop reading here and just start the review. If you need more information though, keep reading on the specific changes.
Checks runtime configuration
This struct handles the runtime configuration file for all checks. This struct replaces the
any
maps with the checks configuration in the whole codebase.Notable features:
Config
struct as well to handle the extra configuration for the check, or else the check won’t be configurable.The runtime configuration of the checks was removed from the startup configuration check struct (in the
config
package), as this was the wrong place for it. Finally, the unused and currently unneededapiVersion
andkind
fields of the configuration were removed from the configuration file. RIP (not).Still open (for the future):
Validate
method to validate the configuration per check. Left it out, as this would only enlarge this already large enough PR.runtime.Config
struct, which should have a validate Method to validate all configurations.Check Interface & Check handling
The Check interface was modified, as it was the most sensible thing that came in mind to be able to handle the update of the checks themselves during the
ReconcileChecks
routine. The interface was thus expanded:Name
of the Check, which allows the identification of the checkTo create new checks, a proper Factory was created to just call the constructors and also create multiple checks from the incoming
runtime.Config
from the configuration channel of the Sparrow.Tests done
Final remarks
Most fragile changes of this refactoring were made because of how the
ReconcileChecks
works, like expanding the Checks interface with aGetConfig
, which seems unnecessary to just update the config of a check. We should focus some time on finding a simpler logic on how to CRUD the checks managed by the sparrow, instead of managing them in amap[string]checks.Check
(a map of names to interfaces).