-
Notifications
You must be signed in to change notification settings - Fork 790
/
compactor_http.go
53 lines (44 loc) · 1.2 KB
/
compactor_http.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
50
51
52
53
package compactor
import (
"html/template"
"net/http"
"github.com/go-kit/log/level"
util_log "github.com/cortexproject/cortex/pkg/util/log"
"github.com/cortexproject/cortex/pkg/util/services"
)
var (
compactorStatusPageTemplate = template.Must(template.New("main").Parse(`
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cortex Compactor Ring</title>
</head>
<body>
<h1>Cortex Compactor Ring</h1>
<p>{{ .Message }}</p>
</body>
</html>`))
)
func writeMessage(w http.ResponseWriter, message string) {
w.WriteHeader(http.StatusOK)
err := compactorStatusPageTemplate.Execute(w, struct {
Message string
}{Message: message})
if err != nil {
level.Error(util_log.Logger).Log("msg", "unable to serve compactor ring page", "err", err)
}
}
func (c *Compactor) RingHandler(w http.ResponseWriter, req *http.Request) {
if !c.compactorCfg.ShardingEnabled {
writeMessage(w, "Compactor has no ring because sharding is disabled.")
return
}
if c.State() != services.Running {
// we cannot read the ring before Compactor is in Running state,
// because that would lead to race condition.
writeMessage(w, "Compactor is not running yet.")
return
}
c.ring.ServeHTTP(w, req)
}