Skip to content

Commit

Permalink
Fix log messages for unready services (#2414)
Browse files Browse the repository at this point in the history
* Fix log messages for unready services

Log lines now looks like

```
11:28:52 compactor: level=debug ts=2022-07-14T09:28:52.169964509Z caller=mimir.go:643 msg="some services are not Running: compactor: Starting"
```

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Remove buffers

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Add a space

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Update pkg/mimir/mimir.go

Co-authored-by: Peter Štibraný <pstibrany@gmail.com>

Co-authored-by: Peter Štibraný <pstibrany@gmail.com>
  • Loading branch information
dimitarvdimitrov and pstibrany committed Jul 14, 2022
1 parent d04fa37 commit 0e9a085
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions pkg/mimir/mimir.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
package mimir

import (
"bytes"
"context"
"flag"
"fmt"
"net/http"
"os"
"reflect"
"strconv"
"strings"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -629,18 +629,17 @@ func (t *Mimir) Run() error {
func (t *Mimir) readyHandler(sm *services.Manager) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if !sm.IsHealthy() {
msg := bytes.Buffer{}
msg.WriteString("Some services are not Running:\n")

var serviceNamesStates []string
for name, s := range t.ServiceMap {
if s.State() != services.Running {
msg.WriteString(fmt.Sprintf("%s: %s\n", name, s.State()))
serviceNamesStates = append(serviceNamesStates, fmt.Sprintf("%s: %s", name, s.State()))
}
}

strMsg := msg.String()
level.Debug(util_log.Logger).Log(strMsg)
http.Error(w, strMsg, http.StatusServiceUnavailable)
level.Debug(util_log.Logger).Log("msg", "some services are not Running", "services", serviceNamesStates)

httpResponse := "Some services are not Running:\n" + strings.Join(serviceNamesStates, "\n")
http.Error(w, httpResponse, http.StatusServiceUnavailable)
return
}

Expand Down

0 comments on commit 0e9a085

Please sign in to comment.