grafana/pkg/api/health.go
Serge Zaitsev af7d293eaf
Chore: Remove Store interface and use db.DB instead (#60160)
* Chore: Remove Store interface and use db.DB instead

* use old-style session exec
2022-12-13 11:03:36 +01:00

26 lines
497 B
Go

package api
import (
"context"
"time"
"github.com/grafana/grafana/pkg/infra/db"
)
func (hs *HTTPServer) databaseHealthy(ctx context.Context) bool {
const cacheKey = "db-healthy"
if cached, found := hs.CacheService.Get(cacheKey); found {
return cached.(bool)
}
err := hs.SQLStore.WithDbSession(ctx, func(session *db.Session) error {
_, err := session.Exec("SELECT 1")
return err
})
healthy := err == nil
hs.CacheService.Set(cacheKey, healthy, time.Second*5)
return healthy
}