/
compactor_http.go
46 lines (37 loc) · 1.26 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
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/grafana/mimir/blob/main/pkg/compactor/compactor_http.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Cortex Authors.
package compactor
import (
_ "embed" // Used to embed html template
"html/template"
"net/http"
"github.com/go-kit/log/level"
"github.com/grafana/dskit/services"
util_log "github.com/grafana/pyroscope/pkg/util"
)
var (
//go:embed status.gohtml
statusPageHTML string
statusPageTemplate = template.Must(template.New("main").Parse(statusPageHTML))
)
type statusPageContents struct {
Message string
}
func writeMessage(w http.ResponseWriter, message string) {
w.WriteHeader(http.StatusOK)
err := statusPageTemplate.Execute(w, statusPageContents{Message: message})
if err != nil {
level.Error(util_log.Logger).Log("msg", "unable to serve compactor ring page", "err", err)
}
}
func (c *MultitenantCompactor) RingHandler(w http.ResponseWriter, req *http.Request) {
if c.State() != services.Running {
// we cannot read the ring before MultitenantCompactor is in Running state,
// because that would lead to race condition.
writeMessage(w, "Compactor is not running yet.")
return
}
c.ring.ServeHTTP(w, req)
}