Context: Add context to /api/health calls (#40031)
Signed-off-by: bergquist <carl.bergquist@gmail.com>
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
func init() {
|
||||
bus.AddHandler("sql", GetDBHealthQuery)
|
||||
bus.AddHandlerCtx("sql", GetDBHealthQuery)
|
||||
}
|
||||
|
||||
func GetDBHealthQuery(query *models.GetDBHealthQuery) error {
|
||||
_, err := x.Exec("SELECT 1")
|
||||
return err
|
||||
// GetDBHealthQuery executes a query to check
|
||||
// the availability of the database.
|
||||
func GetDBHealthQuery(ctx context.Context, query *models.GetDBHealthQuery) error {
|
||||
return withDbSession(ctx, x, func(session *DBSession) error {
|
||||
_, err := session.Exec("SELECT 1")
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
@@ -14,6 +15,6 @@ func TestGetDBHealthQuery(t *testing.T) {
|
||||
InitTestDB(t)
|
||||
|
||||
query := models.GetDBHealthQuery{}
|
||||
err := GetDBHealthQuery(&query)
|
||||
err := GetDBHealthQuery(context.Background(), &query)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user