Skip to content

Commit

Permalink
add loki connection check
Browse files Browse the repository at this point in the history
  • Loading branch information
maddsua committed Jan 25, 2025
1 parent b4f2bf3 commit 989f411
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
22 changes: 22 additions & 0 deletions service/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ func ParseLokiUrl(params string) (*LokiConnection, error) {
}, nil
}

func (this *LokiConnection) Ready() error {

req, err := http.NewRequest("GET", this.url+"/ready", nil)
if err != nil {
return err
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}

defer resp.Body.Close()

switch resp.StatusCode {
case http.StatusOK, http.StatusAccepted, http.StatusNoContent:
return nil
}

return fmt.Errorf("http status code %d", resp.StatusCode)
}

type Level string

func (lvl Level) String() string {
Expand Down
9 changes: 8 additions & 1 deletion service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
var migrationsFs embed.FS

// todo: add management API
// todo: pull txid out of timescale metadata

func main() {

Expand Down Expand Up @@ -70,7 +69,15 @@ func main() {
}

if lokiConn != nil {

if err := lokiConn.Ready(); err != nil {
slog.Error("STARTUP: Loki is not ready",
slog.String("err", err.Error()))
os.Exit(1)
}

slog.Info("STARTUP: Loki connection OK")

} else {
slog.Info("STARTUP: Loki not configured. Using Timescale/Postgres")
}
Expand Down

0 comments on commit 989f411

Please sign in to comment.