Add healthcheck to all stores
This commit is contained in:
		| @@ -108,3 +108,7 @@ func (s *CachingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) | |||||||
|  |  | ||||||
| 	return attempts, err | 	return attempts, err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *CachingStore) IsHealthy() bool { | ||||||
|  | 	return s.backend.IsHealthy() | ||||||
|  | } | ||||||
|   | |||||||
| @@ -142,6 +142,10 @@ func (ms *MemoryStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *MemoryStore) IsHealthy() bool { | ||||||
|  | 	return true | ||||||
|  | } | ||||||
|  |  | ||||||
| func toResults(m map[string]int) []StatsResult { | func toResults(m map[string]int) []StatsResult { | ||||||
| 	var results []StatsResult | 	var results []StatsResult | ||||||
|  |  | ||||||
|   | |||||||
| @@ -120,3 +120,7 @@ func (s *MetricsCollectingStore) Stats(statType LoginStats, limit int) ([]StatsR | |||||||
| func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) { | func (s *MetricsCollectingStore) Query(query AttemptQuery) ([]models.LoginAttempt, error) { | ||||||
| 	return s.store.Query(query) | 	return s.store.Query(query) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *MetricsCollectingStore) IsHealthy() bool { | ||||||
|  | 	return s.IsHealthy() | ||||||
|  | } | ||||||
|   | |||||||
| @@ -126,6 +126,10 @@ func (s *PostgresStore) Stats(statType LoginStats, limit int) ([]StatsResult, er | |||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *PostgresStore) IsHealthy() bool { | ||||||
|  | 	return s.db.Ping() == nil | ||||||
|  | } | ||||||
|  |  | ||||||
| func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { | func (s *PostgresStore) statsTotal(limit int) ([]StatsResult, error) { | ||||||
| 	uniquePasswordStmt := `select count(*) from (select distinct password from login_attempts) as temp` | 	uniquePasswordStmt := `select count(*) from (select distinct password from login_attempts) as temp` | ||||||
| 	uniqueUsernameStmt := `select count(*) from (select distinct username from login_attempts) as temp` | 	uniqueUsernameStmt := `select count(*) from (select distinct username from login_attempts) as temp` | ||||||
|   | |||||||
| @@ -35,4 +35,9 @@ type LoginAttemptStore interface { | |||||||
| 	All() ([]models.LoginAttempt, error) | 	All() ([]models.LoginAttempt, error) | ||||||
| 	Stats(statType LoginStats, limit int) ([]StatsResult, error) | 	Stats(statType LoginStats, limit int) ([]StatsResult, error) | ||||||
| 	Query(query AttemptQuery) ([]models.LoginAttempt, error) | 	Query(query AttemptQuery) ([]models.LoginAttempt, error) | ||||||
|  | 	HealthCheker | ||||||
|  | } | ||||||
|  |  | ||||||
|  | type HealthCheker interface { | ||||||
|  | 	IsHealthy() bool | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user