feat: add health check to telemetry server

Signed-off-by: Mark Sagi-Kazar <mark.sagikazar@gmail.com>
This commit is contained in:
Mark Sagi-Kazar
2021-02-11 00:13:07 +01:00
parent 10597cf09f
commit 024f69b2c7
4 changed files with 61 additions and 0 deletions

29
storage/health.go Normal file
View File

@@ -0,0 +1,29 @@
package storage
import (
"fmt"
"time"
)
// NewCustomHealthCheckFunc returns a new health check function.
func NewCustomHealthCheckFunc(s Storage, now func() time.Time) func() (details interface{}, err error) {
return func() (details interface{}, err error) {
a := AuthRequest{
ID: NewID(),
ClientID: NewID(),
// Set a short expiry so if the delete fails this will be cleaned up quickly by garbage collection.
Expiry: now().Add(time.Minute),
}
if err := s.CreateAuthRequest(a); err != nil {
return nil, fmt.Errorf("create auth request: %v", err)
}
if err := s.DeleteAuthRequest(a.ID); err != nil {
return nil, fmt.Errorf("delete auth request: %v", err)
}
return nil, nil
}
}