Skip to content

Commit

Permalink
Use extra short timeout for health check.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Apr 7, 2022
1 parent 517a002 commit 4885c78
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/metal-api/internal/datastore/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package datastore

import (
"context"
"time"

"github.com/metal-stack/metal-lib/rest"
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
Expand All @@ -13,13 +14,16 @@ func (rs *RethinkStore) ServiceName() string {

// Check implements the health interface and tests if the database is healthy.
func (rs *RethinkStore) Check(ctx context.Context) (rest.HealthStatus, error) {
healthCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()

t := r.Branch(
rs.db().TableList().SetIntersection(r.Expr(tables)).Count().Eq(len(tables)),
r.Expr(true),
r.Error("required tables are missing"),
)

err := t.Exec(rs.session, r.ExecOpts{Context: ctx})
err := t.Exec(rs.session, r.ExecOpts{Context: healthCtx})
if err != nil {
return rest.HealthStatusUnhealthy, err
}
Expand Down

0 comments on commit 4885c78

Please sign in to comment.