Change healthchecker to return error

This commit is contained in:
Torjus Håkestad 2021-11-06 00:41:27 +01:00
parent 8ba601a2b1
commit db8372f6db
5 changed files with 18 additions and 9 deletions

View File

@ -109,6 +109,6 @@ func (s *CachingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
return attempts, err
}
func (s *CachingStore) IsHealthy() bool {
func (s *CachingStore) IsHealthy() error {
return s.backend.IsHealthy()
}

View File

@ -142,8 +142,8 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error)
return results, nil
}
func (s *MemoryStore) IsHealthy() bool {
return true
func (s *MemoryStore) IsHealthy() error {
return nil
}
func toResults(m map[string]int) []StatsResult {

View File

@ -121,6 +121,6 @@ func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttemp
return s.store.Query(query)
}
func (s *MetricsCollectingStore) IsHealthy() bool {
return s.IsHealthy()
func (s *MetricsCollectingStore) IsHealthy() error {
return s.store.IsHealthy()
}

View File

@ -126,8 +126,11 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er
return results, nil
}
func (s *PostgresStore) IsHealthy() bool {
return s.db.Ping() == nil
func (s *PostgresStore) IsHealthy() error {
if err := s.db.Ping(); err != nil {
return ErrStoreUnhealthy
}
return nil
}
func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) {

View File

@ -1,6 +1,12 @@
package store
import "github.uio.no/torjus/apiary/models"
import (
"errors"
"github.uio.no/torjus/apiary/models"
)
var ErrStoreUnhealthy = errors.New("store is unhealthy")
type LoginStats string
@ -39,5 +45,5 @@ type LoginAttemptStore interface {
}
type HealthCheker interface {
IsHealthy() bool
IsHealthy() error
}