-
Notifications
You must be signed in to change notification settings - Fork 5
Load balance support #42
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
4 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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -43,23 +43,25 @@ type AzureAppConfiguration struct { | |||||||||||||||||||||||||||||||||
| featureFlags map[string]any | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Settings configured from Options | ||||||||||||||||||||||||||||||||||
| kvSelectors []Selector | ||||||||||||||||||||||||||||||||||
| ffEnabled bool | ||||||||||||||||||||||||||||||||||
| ffSelectors []Selector | ||||||||||||||||||||||||||||||||||
| trimPrefixes []string | ||||||||||||||||||||||||||||||||||
| watchedSettings []WatchedSetting | ||||||||||||||||||||||||||||||||||
| kvSelectors []Selector | ||||||||||||||||||||||||||||||||||
| ffEnabled bool | ||||||||||||||||||||||||||||||||||
| ffSelectors []Selector | ||||||||||||||||||||||||||||||||||
| trimPrefixes []string | ||||||||||||||||||||||||||||||||||
| watchedSettings []WatchedSetting | ||||||||||||||||||||||||||||||||||
| loadBalancingEnabled bool | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Settings used for refresh scenarios | ||||||||||||||||||||||||||||||||||
| sentinelETags map[WatchedSetting]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| watchAll bool | ||||||||||||||||||||||||||||||||||
| kvETags map[Selector][]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| ffETags map[Selector][]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| keyVaultRefs map[string]string // unversioned Key Vault references | ||||||||||||||||||||||||||||||||||
| kvRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| secretRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| ffRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| onRefreshSuccess []func() | ||||||||||||||||||||||||||||||||||
| tracingOptions tracing.Options | ||||||||||||||||||||||||||||||||||
| sentinelETags map[WatchedSetting]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| watchAll bool | ||||||||||||||||||||||||||||||||||
| kvETags map[Selector][]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| ffETags map[Selector][]*azcore.ETag | ||||||||||||||||||||||||||||||||||
| keyVaultRefs map[string]string // unversioned Key Vault references | ||||||||||||||||||||||||||||||||||
| kvRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| secretRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| ffRefreshTimer refresh.Condition | ||||||||||||||||||||||||||||||||||
| onRefreshSuccess []func() | ||||||||||||||||||||||||||||||||||
| tracingOptions tracing.Options | ||||||||||||||||||||||||||||||||||
| lastSuccessfulEndpoint string | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Clients talking to Azure App Configuration/Azure Key Vault service | ||||||||||||||||||||||||||||||||||
| clientManager clientManager | ||||||||||||||||||||||||||||||||||
|
|
@@ -103,6 +105,7 @@ func Load(ctx context.Context, authentication AuthenticationOptions, options *Op | |||||||||||||||||||||||||||||||||
| azappcfg.featureFlags = make(map[string]any) | ||||||||||||||||||||||||||||||||||
| azappcfg.kvSelectors = deduplicateSelectors(options.Selectors) | ||||||||||||||||||||||||||||||||||
| azappcfg.ffEnabled = options.FeatureFlagOptions.Enabled | ||||||||||||||||||||||||||||||||||
| azappcfg.loadBalancingEnabled = options.LoadBalancingEnabled | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| azappcfg.trimPrefixes = options.TrimKeyPrefixes | ||||||||||||||||||||||||||||||||||
| azappcfg.clientManager = clientManager | ||||||||||||||||||||||||||||||||||
|
|
@@ -631,6 +634,10 @@ func (azappcfg *AzureAppConfiguration) executeFailoverPolicy(ctx context.Context | |||||||||||||||||||||||||||||||||
| azappcfg.clientManager.refreshClients(ctx) | ||||||||||||||||||||||||||||||||||
| return fmt.Errorf("no client is available to connect to the target App Configuration store") | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| // If load balancing is enabled, rotate the clients so that the next client to be used is not the last successful one | ||||||||||||||||||||||||||||||||||
| if azappcfg.loadBalancingEnabled && azappcfg.lastSuccessfulEndpoint != "" && len(clients) > 1 { | ||||||||||||||||||||||||||||||||||
| rotateClientsToNextEndpoint(clients, azappcfg.lastSuccessfulEndpoint) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if manager, ok := azappcfg.clientManager.(*configurationClientManager); ok { | ||||||||||||||||||||||||||||||||||
| azappcfg.tracingOptions.ReplicaCount = len(manager.dynamicClients) | ||||||||||||||||||||||||||||||||||
|
|
@@ -651,6 +658,10 @@ func (azappcfg *AzureAppConfiguration) executeFailoverPolicy(ctx context.Context | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| clientWrapper.updateBackoffStatus(true) | ||||||||||||||||||||||||||||||||||
| // Update the last successful endpoint for load balancing | ||||||||||||||||||||||||||||||||||
| if azappcfg.loadBalancingEnabled { | ||||||||||||||||||||||||||||||||||
| azappcfg.lastSuccessfulEndpoint = clientWrapper.endpoint | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -748,6 +759,10 @@ func configureTracingOptions(options *Options) tracing.Options { | |||||||||||||||||||||||||||||||||
| tracingOption.KeyVaultConfigured = true | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if options.LoadBalancingEnabled { | ||||||||||||||||||||||||||||||||||
| tracingOption.IsLoadBalancingEnabled = true | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if options.FeatureFlagOptions.Enabled { | ||||||||||||||||||||||||||||||||||
| tracingOption.FeatureFlagTracing = &tracing.FeatureFlagTracing{} | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -854,6 +869,56 @@ func (azappcfg *AzureAppConfiguration) updateFeatureFlagTracing(featureFlag map[ | |||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| func rotateClientsToNextEndpoint(clients []*configurationClientWrapper, lastSuccessfulEndpoint string) { | ||||||||||||||||||||||||||||||||||
| if len(clients) <= 1 { | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Find the index of the last successful endpoint | ||||||||||||||||||||||||||||||||||
| lastSuccessfulIndex := -1 | ||||||||||||||||||||||||||||||||||
| for i, clientWrapper := range clients { | ||||||||||||||||||||||||||||||||||
| if clientWrapper.endpoint == lastSuccessfulEndpoint { | ||||||||||||||||||||||||||||||||||
| lastSuccessfulIndex = i | ||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // If we found the last successful endpoint, rotate to the next one | ||||||||||||||||||||||||||||||||||
| if lastSuccessfulIndex >= 0 { | ||||||||||||||||||||||||||||||||||
| nextClientIndex := (lastSuccessfulIndex + 1) % len(clients) | ||||||||||||||||||||||||||||||||||
| if nextClientIndex > 0 { | ||||||||||||||||||||||||||||||||||
| rotateSliceInPlace(clients, nextClientIndex) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // rotateSliceInPlace rotates a slice left by k positions using the reverse-reverse algorithm. | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| // rotateSliceInPlace rotates a slice left by k positions using the reverse-reverse algorithm. | |
| // rotateSliceInPlace rotates a slice left by k positions in place using the reverse-reverse algorithm. | |
| // | |
| // Parameters: | |
| // slice: The slice to be rotated. The rotation is performed in place. | |
| // k: The number of positions to rotate the slice to the left. If k >= len(slice), k is reduced modulo len(slice). | |
| // | |
| // Algorithm: | |
| // The function uses the reverse-reverse algorithm: | |
| // 1. Reverse the entire slice. | |
| // 2. Reverse the first len(slice)-k elements. | |
| // 3. Reverse the remaining k elements. | |
| // This results in the slice being rotated left by k positions. | |
| // | |
| // Time Complexity: O(n), where n is the length of the slice. | |
| // Space Complexity: O(1), as the rotation is performed in place. |
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
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.
The rotateClientsToNextEndpoint function lacks documentation. It should include a docstring explaining its purpose, parameters, and how it modifies the clients slice in-place for load balancing.