-
Notifications
You must be signed in to change notification settings - Fork 460
/
status.go
49 lines (41 loc) · 1.24 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/cortexproject/cortex/blob/master/pkg/cortex/status.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.
package mimir
import (
_ "embed" // Used to embed html template
"html/template"
"net/http"
"sort"
"time"
"github.com/grafana/mimir/pkg/util"
)
//go:embed status.gohtml
var statusPageHTML string
var statusPageTemplate = template.Must(template.New("webpage").Parse(statusPageHTML))
type statusPageContents struct {
Now time.Time `json:"now"`
Services []renderService `json:"services"`
}
type renderService struct {
Name string `json:"name"`
Status string `json:"status"`
}
func (t *Mimir) servicesHandler(w http.ResponseWriter, r *http.Request) {
svcs := make([]renderService, 0)
for mod, s := range t.ServiceMap {
svcs = append(svcs, renderService{
Name: mod,
Status: s.State().String(),
})
}
sort.Slice(svcs, func(i, j int) bool {
return svcs[i].Name < svcs[j].Name
})
// TODO: this could be extended to also print sub-services, if given service has any
util.RenderHTTPResponse(w, statusPageContents{
Now: time.Now(),
Services: svcs,
}, statusPageTemplate, r)
}