Commit 2545966f authored by Christian Pointner's avatar Christian Pointner
Browse files

store: implemented health check

parent 1d947d22
......@@ -25,6 +25,7 @@
package auth
import (
"context"
"encoding/json"
"io/ioutil"
"log"
......@@ -242,7 +243,7 @@ func Middleware() gin.HandlerFunc {
}
}
func Healthz() error {
func Healthz(ctx context.Context) error {
// TODO: implement this!
return nil
}
......@@ -25,11 +25,13 @@
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"strings"
"sync"
"time"
"github.com/gin-gonic/gin"
......@@ -115,11 +117,17 @@ type Health struct {
}
func healthzHandler(c *gin.Context, st *store.Store, im *importer.Importer) {
h := Health{}
h.Auth.err = auth.Healthz()
h.Store.err = st.Healthz()
h.Importer.err = im.Healthz()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) // TODO: hardcoded value
defer cancel()
var h Health
var wg sync.WaitGroup
wg.Add(3)
go func() { defer wg.Done(); h.Auth.err = auth.Healthz(ctx) }()
go func() { defer wg.Done(); h.Store.err = st.Healthz(ctx) }()
go func() { defer wg.Done(); h.Importer.err = im.Healthz(ctx) }()
wg.Wait()
code := http.StatusOK
if h.Auth.err != nil || h.Store.err != nil || h.Importer.err != nil {
code = http.StatusServiceUnavailable
......
......@@ -84,7 +84,7 @@ func (im *Importer) GetJob(show string, id uint64) (*Job, error) {
return im.jobs.GetJob(show, id)
}
func (im *Importer) Healthz() error {
func (im *Importer) Healthz(ctx context.Context) error {
// TODO: implement this!
return nil
}
......
......@@ -25,6 +25,7 @@
package store
import (
"context"
"errors"
"fmt"
"os"
......@@ -131,9 +132,8 @@ func NewStore(cfg Config) (*Store, error) {
return st, nil
}
func (st *Store) Healthz() error {
// TODO: implement this!
return nil
func (st *Store) Healthz(ctx context.Context) error {
return st.db.DB().PingContext(ctx)
}
func (st *Store) GetRevision() string {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment