-
Notifications
You must be signed in to change notification settings - Fork 1
feat: dynamic config system with hot reload #186
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "crypto/sha256" | ||
| "encoding/hex" | ||
| "fmt" | ||
|
|
||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| // ModuleConfigDiff represents what changed between two configs. | ||
| type ModuleConfigDiff struct { | ||
| Added []ModuleConfig // modules in new but not old | ||
| Removed []ModuleConfig // modules in old but not new | ||
| Modified []ModuleConfigChange // modules present in both with different config | ||
| Unchanged []string // module names with no config change | ||
| } | ||
|
|
||
| // ModuleConfigChange represents a change to a single module's config. | ||
| type ModuleConfigChange struct { | ||
| Name string | ||
| OldConfig map[string]any | ||
| NewConfig map[string]any | ||
| } | ||
|
|
||
| // DiffModuleConfigs compares two configs and identifies module-level changes. | ||
| func DiffModuleConfigs(old, new *WorkflowConfig) *ModuleConfigDiff { | ||
| diff := &ModuleConfigDiff{} | ||
|
|
||
| oldMap := make(map[string]ModuleConfig) | ||
| for _, m := range old.Modules { | ||
| oldMap[m.Name] = m | ||
| } | ||
| newMap := make(map[string]ModuleConfig) | ||
| for _, m := range new.Modules { | ||
| newMap[m.Name] = m | ||
| } | ||
|
|
||
| for name, newMod := range newMap { | ||
| oldMod, exists := oldMap[name] | ||
| if !exists { | ||
| diff.Added = append(diff.Added, newMod) | ||
| continue | ||
| } | ||
| if hashModuleConfig(oldMod) != hashModuleConfig(newMod) { | ||
| diff.Modified = append(diff.Modified, ModuleConfigChange{ | ||
| Name: name, | ||
| OldConfig: oldMod.Config, | ||
| NewConfig: newMod.Config, | ||
| }) | ||
| } else { | ||
| diff.Unchanged = append(diff.Unchanged, name) | ||
| } | ||
| } | ||
|
|
||
| for name, oldMod := range oldMap { | ||
| if _, exists := newMap[name]; !exists { | ||
| diff.Removed = append(diff.Removed, oldMod) | ||
| } | ||
| } | ||
|
|
||
| return diff | ||
| } | ||
|
|
||
| // HasNonModuleChanges returns true if workflows, triggers, pipelines, | ||
| // platform config, or requirements changed between old and new | ||
| // (requiring full reload). | ||
| func HasNonModuleChanges(old, new *WorkflowConfig) bool { | ||
| return hashAny(old.Workflows) != hashAny(new.Workflows) || | ||
| hashAny(old.Triggers) != hashAny(new.Triggers) || | ||
| hashAny(old.Pipelines) != hashAny(new.Pipelines) || | ||
| hashAny(old.Platform) != hashAny(new.Platform) || | ||
| hashAny(old.Requires) != hashAny(new.Requires) | ||
| } | ||
|
|
||
| func hashModuleConfig(m ModuleConfig) string { | ||
| data, err := yaml.Marshal(m) | ||
| if err != nil { | ||
| return fmt.Sprintf("error:%v", err) | ||
| } | ||
| sum := sha256.Sum256(data) | ||
| return hex.EncodeToString(sum[:]) | ||
| } | ||
|
|
||
| func hashAny(v any) string { | ||
| if v == nil { | ||
| return "nil" | ||
| } | ||
| data, err := yaml.Marshal(v) | ||
| if err != nil { | ||
| return fmt.Sprintf("error:%v", err) | ||
| } | ||
| sum := sha256.Sum256(data) | ||
| return hex.EncodeToString(sum[:]) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
NewConfigReloader is being constructed with app.engine as the ModuleReconfigurer, but reloadEngine replaces app.engine with a new *StdEngine. The reloader will keep calling ReconfigureModules on the old engine instance after the first full reload. Consider passing a stable adapter (e.g., have *serverApp implement config.ModuleReconfigurer by delegating to app.engine) so the reloader always targets the current engine.