-
Notifications
You must be signed in to change notification settings - Fork 31
Fix director tests to fetch from TTL cache and respect downtime #2867
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
Changes from 10 commits
14f0b66
7432c8f
f28ecf7
ba09713
a972f19
9e21617
b1690f0
92c3e90
a3b6e58
98a27d1
2c3d8fa
53f297b
17856f7
e073760
8abdcb8
d48eb9b
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "net/url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "time" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/jellydator/ttlcache/v3" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/pkg/errors" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/prometheus/client_golang/prometheus" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log "github.com/sirupsen/logrus" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -132,23 +133,41 @@ func reportStatusToServer(ctx context.Context, serverWebUrl string, status strin | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // isDowntimeActive checks if a downtime is currently active based on the current time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // A downtime is considered active if the current time is between StartTime and EndTime (inclusive), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // or if EndTime is IndefiniteEndTime and current time is after StartTime. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func isDowntimeActive(downtime server_structs.Downtime, currentTime int64) bool { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return downtime.StartTime <= currentTime && (downtime.EndTime >= currentTime || downtime.EndTime == server_structs.IndefiniteEndTime) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Run a periodic test file transfer against an origin to ensure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // it's talking to the director | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func LaunchPeriodicDirectorTest(ctx context.Context, serverAd server_structs.ServerAd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverName := serverAd.Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverUrl := serverAd.URL.String() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverWebUrl := serverAd.WebURL.String() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // it's talking to the director. The test fetches the current server ad | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // from the TTL cache on each cycle and stops when the ad is no longer present. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func LaunchPeriodicDirectorTest(ctx context.Context, serverUrlStr string) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Option to disable touch on hit when fetching from cache to avoid extending TTL | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disableTouchOpt := ttlcache.WithDisableTouchOnHit[string, *server_structs.Advertisement]() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fetch the initial server ad to set up metrics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialAdItem := serverAds.Get(serverUrlStr, disableTouchOpt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if initialAdItem == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Errorf("Failed to start director test suite: server ad not found in cache for URL %s. Test will not be started.", serverUrlStr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialAd := initialAdItem.Value() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverName := initialAd.Name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverWebUrl := initialAd.WebURL.String() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverType := initialAd.Type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug(fmt.Sprintf("Starting a new director test suite for %s server %s at %s", serverAd.Type, serverName, serverUrl)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug(fmt.Sprintf("Starting a new director test suite for %s server %s at %s", serverType, serverName, serverUrlStr)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics.PelicanDirectorFileTransferTestSuite.With( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prometheus.Labels{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": string(serverAd.Type), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": serverType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).Inc() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics.PelicanDirectorActiveFileTransferTestSuite.With( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prometheus.Labels{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": string(serverAd.Type), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": serverType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).Inc() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| customInterval := param.Director_OriginCacheHealthTestInterval.GetDuration() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -162,46 +181,75 @@ func LaunchPeriodicDirectorTest(ctx context.Context, serverAd server_structs.Ser | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ticker := time.NewTicker(customInterval) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer ticker.Stop() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer func() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics.PelicanDirectorActiveFileTransferTestSuite.With( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prometheus.Labels{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": serverType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).Dec() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-ctx.Done(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug(fmt.Sprintf("End director test suite for %s server %s at %s", serverAd.Type, serverName, serverUrl)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| metrics.PelicanDirectorActiveFileTransferTestSuite.With( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prometheus.Labels{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "server_name": serverName, "server_web_url": serverWebUrl, "server_type": string(serverAd.Type), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }).Dec() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug(fmt.Sprintf("Stopped the Director test suite for %s server %s at %s", serverType, serverName, serverUrlStr)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-ticker.C: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug(fmt.Sprintf("Starting a director test cycle for %s server %s at %s", serverAd.Type, serverName, serverUrl)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Fetch the current server ad from the TTL cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| adItem := serverAds.Get(serverUrlStr, disableTouchOpt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if adItem == nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Infof("The Director doesn't have any advertisements for server with URL %s. Stopping director tests.", serverUrlStr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverAd := adItem.Value().ServerAd | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if the server is in an active downtime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| downtimes, err := getCachedDowntimes(serverAd.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Warningf("Failed to get cached downtimes for server %s: %v. Proceeding with director test.", serverAd.Name, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if any downtime is currently active | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| currentTime := time.Now().UTC().UnixMilli() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasActiveDowntime := false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, downtime := range downtimes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isDowntimeActive(downtime, currentTime) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| hasActiveDowntime = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debugf("Skipping director test cycle for %s server %s: server is in active downtime", serverAd.Type, serverAd.Name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if hasActiveDowntime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check if the server is in an active downtime | |
| downtimes, err := getCachedDowntimes(serverAd.Name) | |
| if err != nil { | |
| log.Warningf("Failed to get cached downtimes for server %s: %v. Proceeding with director test.", serverAd.Name, err) | |
| } else { | |
| // Check if any downtime is currently active | |
| currentTime := time.Now().UTC().UnixMilli() | |
| hasActiveDowntime := false | |
| for _, downtime := range downtimes { | |
| if isDowntimeActive(downtime, currentTime) { | |
| hasActiveDowntime = true | |
| log.Debugf("Skipping director test cycle for %s server %s: server is in active downtime", serverAd.Type, serverAd.Name) | |
| break | |
| } | |
| } | |
| if hasActiveDowntime { | |
| continue | |
| } | |
| } | |
| if isServerInDowntime(serverAd.Name) { | |
| log.Debugf("Skipping director test cycle for %s server %s: server is in downtime", serverAd.Type, serverAd.Name) | |
| continue | |
| } | |
| // This helper function should be placed in cache_ads.go | |
| // isServerInDowntime checks if a server is in the filteredServers map with an active filter. | |
| // A server is considered in downtime if it exists in filteredServers with any filter type except tempAllowed. | |
| func isServerInDowntime(serverName string) bool { | |
| filteredServersMutex.RLock() | |
| defer filteredServersMutex.RUnlock() | |
| existingFilterType, isServerFiltered := filteredServers[serverName] | |
| return isServerFiltered && existingFilterType != tempAllowed | |
| } |
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.
Implemented the suggested fix in commit 2c3d8fa. Now using isServerInDowntime() helper function that checks filteredServers map directly, ensuring director tests use the same source of truth as redirect filtering. This avoids maintaining duplicate downtime traversal logic and ensures consistency.
Uh oh!
There was an error while loading. Please reload this page.