Context: Add context to /api/health calls (#40031)

Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
Carl Bergquist
2021-10-11 14:35:03 +02:00
committed by GitHub
parent 57fcfd578d
commit c9f25cf0a5
5 changed files with 22 additions and 13 deletions

View File

@@ -1,20 +1,21 @@
package api
import (
"context"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/models"
)
func (hs *HTTPServer) databaseHealthy() bool {
func (hs *HTTPServer) databaseHealthy(ctx context.Context) bool {
const cacheKey = "db-healthy"
if cached, found := hs.CacheService.Get(cacheKey); found {
return cached.(bool)
}
healthy := bus.Dispatch(&models.GetDBHealthQuery{}) == nil
healthy := bus.DispatchCtx(ctx, &models.GetDBHealthQuery{}) == nil
hs.CacheService.Set(cacheKey, healthy, time.Second*5)
return healthy