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