-
Notifications
You must be signed in to change notification settings - Fork 820
Add admin page for HA tracker information. #1546
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
11 commits
Select commit
Hold shift + click to select a range
615a547
Add admin page for HA tracker information.
cstyan 640c5b0
Turn on HA tracker by default, remove EnableHATracker config. Accepting
cstyan 7845c2c
Add Update and Failover times to the HA tracker HTTP page.
cstyan 3b61a30
Prefix HA tracker flags, check HA enable only in HA code, and only
cstyan 6a66e47
Prefix HA tracker flags, check HA enable only in HA code, and only
cstyan 1702bb9
Move creation of HA tracker to before creation of distributor struct in
cstyan 468bb3f
Sort results for HA tracker admin page.
cstyan 1855a1f
Nits.
tomwilkie 3b280e1
Add changelog entry.
tomwilkie f55e509
Unlock immediately after use.
tomwilkie c87a062
Fix rebase.
tomwilkie 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
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
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,99 @@ | ||
package distributor | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
"sort" | ||
"strings" | ||
"time" | ||
|
||
"github.com/prometheus/prometheus/pkg/timestamp" | ||
) | ||
|
||
const trackerTpl = ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Cortex HA Tracker Status</title> | ||
</head> | ||
<body> | ||
<h1>Cortex HA Tracker Status</h1> | ||
<p>Current time: {{ .Now }}</p> | ||
<table width="100%" border="1"> | ||
<thead> | ||
<tr> | ||
<th>User ID</th> | ||
<th>Cluster</th> | ||
<th>Replica</th> | ||
<th>Elected Time</th> | ||
<th>Time Until Update</th> | ||
<th>Time Until Failover</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{{ range .Elected }} | ||
<tr> | ||
<td>{{ .UserID }}</td> | ||
<td>{{ .Cluster }}</td> | ||
<td>{{ .Replica }}</td> | ||
<td>{{ .ElectedAt }}</td> | ||
<td>{{ .UpdateTime }}</td> | ||
<td>{{ .FailoverTime }}</td> | ||
</tr> | ||
{{ end }} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html>` | ||
|
||
var trackerTmpl *template.Template | ||
|
||
func init() { | ||
trackerTmpl = template.Must(template.New("ha-tracker").Parse(trackerTpl)) | ||
} | ||
|
||
func (h *haTracker) ServeHTTP(w http.ResponseWriter, req *http.Request) { | ||
h.electedLock.RLock() | ||
type replica struct { | ||
UserID, Cluster, Replica string | ||
ElectedAt time.Time | ||
UpdateTime, FailoverTime time.Duration | ||
} | ||
|
||
electedReplicas := []replica{} | ||
for key, desc := range h.elected { | ||
chunks := strings.SplitN(key, "/", 2) | ||
|
||
electedReplicas = append(electedReplicas, replica{ | ||
UserID: chunks[0], | ||
Cluster: chunks[1], | ||
Replica: desc.Replica, | ||
ElectedAt: timestamp.Time(desc.ReceivedAt), | ||
UpdateTime: time.Until(timestamp.Time(desc.ReceivedAt).Add(h.cfg.UpdateTimeout)), | ||
FailoverTime: time.Until(timestamp.Time(desc.ReceivedAt).Add(h.cfg.FailoverTimeout)), | ||
}) | ||
} | ||
h.electedLock.RUnlock() | ||
|
||
sort.Slice(electedReplicas, func(i, j int) bool { | ||
first := electedReplicas[i] | ||
second := electedReplicas[j] | ||
|
||
if first.UserID != second.UserID { | ||
return first.UserID < second.UserID | ||
} | ||
return first.Cluster < second.Cluster | ||
}) | ||
|
||
if err := trackerTmpl.Execute(w, struct { | ||
Elected []replica | ||
Now time.Time | ||
}{ | ||
Elected: electedReplicas, | ||
Now: time.Now(), | ||
}); err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.