-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[43644] feat(exporter/loadbalancing/dnsresolver): add quarantine mechanism for unhealthy endpoints #43961
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
base: main
Are you sure you want to change the base?
[43644] feat(exporter/loadbalancing/dnsresolver): add quarantine mechanism for unhealthy endpoints #43961
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog) | ||
| component: exporter/loadbalancing | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Quarantine mechanism for unhealthy endpoints in the DNS resolver. | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [43644] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | | ||
| - Added a quarantine feature for unhealthy endpoints, delaying retries to those endpoints after a configurable period (default: 30s). | ||
| - Quarantine settings are configurable via the DNS resolver's `quarantine` section. | ||
| - The load balancer will avoid sending data to endpoints marked as unhealthy until their quarantine period expires, using healthy endpoints in the hash ring without triggering unnecessary ring updates. | ||
| - This increases resilience by reducing the risk of exporters being stuck in degraded states with repeated failed attempts. | ||
| - This feature currently applies only to the DNS resolver. | ||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
| "slices" | ||
| "strings" | ||
| "sync" | ||
| "time" | ||
|
|
||
| "go.opentelemetry.io/collector/component" | ||
| "go.uber.org/zap" | ||
|
|
@@ -38,6 +39,10 @@ type loadBalancer struct { | |
| componentFactory componentFactory | ||
| exporters map[string]*wrappedExporter | ||
|
|
||
| // Track unhealthy endpoints across all signal types | ||
| unhealthyEndpoints map[string]time.Time | ||
| healthLock sync.RWMutex | ||
|
|
||
| stopped bool | ||
| updateLock sync.RWMutex | ||
| } | ||
|
|
@@ -79,12 +84,14 @@ func newLoadBalancer(logger *zap.Logger, cfg component.Config, factory component | |
|
|
||
| var err error | ||
| dnsResolver := oCfg.Resolver.DNS.Get() | ||
|
|
||
| res, err = newDNSResolver( | ||
| dnsLogger, | ||
| dnsResolver.Hostname, | ||
| dnsResolver.Port, | ||
| dnsResolver.Interval, | ||
| dnsResolver.Timeout, | ||
| &dnsResolver.Quarantine, | ||
| telemetry, | ||
| ) | ||
| if err != nil { | ||
|
|
@@ -137,10 +144,11 @@ func newLoadBalancer(logger *zap.Logger, cfg component.Config, factory component | |
| } | ||
|
|
||
| return &loadBalancer{ | ||
| logger: logger, | ||
| res: res, | ||
| componentFactory: factory, | ||
| exporters: map[string]*wrappedExporter{}, | ||
| logger: logger, | ||
| res: res, | ||
| componentFactory: factory, | ||
| exporters: map[string]*wrappedExporter{}, | ||
| unhealthyEndpoints: make(map[string]time.Time), | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -212,6 +220,48 @@ func (lb *loadBalancer) removeExtraExporters(ctx context.Context, endpoints []st | |
| } | ||
| } | ||
|
|
||
| // markUnhealthy marks an endpoint as unhealthy | ||
| func (lb *loadBalancer) markUnhealthy(endpoint string) { | ||
| lb.healthLock.Lock() | ||
| defer lb.healthLock.Unlock() | ||
|
|
||
| if _, exists := lb.unhealthyEndpoints[endpoint]; !exists { | ||
| lb.unhealthyEndpoints[endpoint] = time.Now() | ||
| } | ||
| } | ||
|
|
||
| // isHealthy checks if an endpoint is healthy or if it has been quarantined long enough to retry | ||
| func (lb *loadBalancer) isHealthy(endpoint string) bool { | ||
| lb.healthLock.RLock() | ||
| timestamp, exists := lb.unhealthyEndpoints[endpoint] | ||
| lb.healthLock.RUnlock() | ||
|
|
||
| if !exists { | ||
| return true | ||
| } | ||
|
|
||
| // If quarantine period has passed, remove from unhealthy list and allow retry | ||
| if dnsRes, ok := lb.res.(*dnsResolver); ok && dnsRes.quarantine != nil { | ||
| lb.logger.Debug("isHealthy", zap.String("endpoint", endpoint), zap.Time("timestamp", timestamp), zap.Duration("quarantineDuration", dnsRes.quarantine.Duration)) | ||
| if time.Since(timestamp) > dnsRes.quarantine.Duration { | ||
| lb.healthLock.Lock() | ||
| delete(lb.unhealthyEndpoints, endpoint) | ||
| lb.healthLock.Unlock() | ||
| lb.logger.Debug("isHealthy - quarantine period passed", zap.String("endpoint", endpoint)) | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| // isQuarantineEnabled checks if the resolver supports quarantine logic and if it's enabled. | ||
| // Quarantine logic is supported for DNS resolvers only. | ||
| func (lb *loadBalancer) isQuarantineEnabled() bool { | ||
| dnsRes, ok := lb.res.(*dnsResolver) | ||
| return ok && dnsRes.quarantine.Enabled | ||
| } | ||
|
|
||
| func (lb *loadBalancer) Shutdown(ctx context.Context) error { | ||
| err := lb.res.shutdown(ctx) | ||
| lb.stopped = true | ||
|
|
@@ -238,3 +288,79 @@ func (lb *loadBalancer) exporterAndEndpoint(identifier []byte) (*wrappedExporter | |
|
|
||
| return exp, endpoint, nil | ||
| } | ||
|
|
||
| // nextExporterAndEndpoint returns the next exporter and endpoint in the ring after the given position. | ||
| func (lb *loadBalancer) nextExporterAndEndpoint(pos position) (*wrappedExporter, string, error) { | ||
| lb.updateLock.RLock() | ||
| defer lb.updateLock.RUnlock() | ||
|
|
||
| endpoint := lb.ring.findEndpoint(pos) | ||
| exp, found := lb.exporters[endpointWithPort(endpoint)] | ||
| if !found { | ||
| return nil, "", fmt.Errorf("couldn't find the exporter for the endpoint %q", endpoint) | ||
| } | ||
|
|
||
| return exp, endpoint, nil | ||
| } | ||
|
|
||
| // consumeWithRetryAndQuarantine executes the consume operation with the initial assignment of the exporter and endpoint. | ||
| // If the consume operation fails, it will retry with the next endpoint in its associated ring. | ||
| // It will try subsequent endpoints until either one succeeds or all available endpoints have been tried. | ||
| // Once an unhealthy endpoint is found, it will be marked as unhealthy and not tried again until the quarantine period has passed. | ||
| func (lb *loadBalancer) consumeWithRetryAndQuarantine(identifier []byte, exp *wrappedExporter, endpoint string, consume func(*wrappedExporter, string) error) error { | ||
| var err error | ||
|
|
||
| // Try the first endpoint if it's healthy or quarantine period has passed | ||
| if lb.isHealthy(endpoint) { | ||
| if err = consume(exp, endpoint); err == nil { | ||
| return nil | ||
| } | ||
| // Mark as unhealthy if the consume failed | ||
| lb.markUnhealthy(endpoint) | ||
| } | ||
|
|
||
| // If consume failed, try with subsequent endpoints | ||
| // Keep track of tried endpoints to avoid infinite loop | ||
| tried := map[string]bool{endpoint: true} | ||
| currentPos := getPosition(identifier) | ||
|
|
||
| // Try until we've used all available endpoints | ||
| for len(tried) < len(lb.exporters) { | ||
|
||
| // retryExp, retryEndpoint, retryErr := lb.exporterAndEndpoint(identifier) | ||
| retryExp, retryEndpoint, retryErr := lb.nextExporterAndEndpoint(currentPos) | ||
| if retryErr != nil { | ||
| // Return original error if we can't get a new endpoint | ||
| return err | ||
| } | ||
|
|
||
| // If we've already tried this endpoint in this cycle, move to next position | ||
| if tried[retryEndpoint] { | ||
| currentPos = (currentPos + 1) % position(maxPositions) | ||
| continue | ||
| } | ||
|
|
||
| // Skip unhealthy endpoints that are still in quarantine | ||
| if !lb.isHealthy(retryEndpoint) { | ||
| tried[retryEndpoint] = true | ||
| // If we've exhausted all endpoints and they're all unhealthy, stop | ||
| if len(tried) == len(lb.exporters) { | ||
| break | ||
| } | ||
| currentPos = (currentPos + 1) % position(maxPositions) | ||
| continue | ||
| } | ||
|
|
||
| tried[retryEndpoint] = true | ||
|
|
||
| if retryErr = consume(retryExp, retryEndpoint); retryErr == nil { | ||
| return nil | ||
| } | ||
| // Mark as unhealthy if the consume failed | ||
| lb.markUnhealthy(retryEndpoint) | ||
|
|
||
| // Move to next position for next iteration | ||
| currentPos = (currentPos + 1) % position(maxPositions) | ||
| } | ||
|
|
||
| return fmt.Errorf("all endpoints were tried and failed: %v", tried) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.