mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Server: Add health check route (#26999)
* Server: Add health check route Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Server: Remove health check middleware Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -435,5 +435,8 @@ func (hs *HTTPServer) registerRoutes() {
|
|||||||
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey))
|
r.Get("/api/snapshots-delete/:deleteKey", reqSnapshotPublicModeOrSignedIn, Wrap(DeleteDashboardSnapshotByDeleteKey))
|
||||||
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
r.Delete("/api/snapshots/:key", reqEditorRole, Wrap(DeleteDashboardSnapshot))
|
||||||
|
|
||||||
|
// Health check
|
||||||
|
r.Get("/api/health", hs.healthHandler)
|
||||||
|
|
||||||
r.Get("/*", reqSignedIn, hs.Index)
|
r.Get("/*", reqSignedIn, hs.Index)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,7 +324,6 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
|
|||||||
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
Delims: macaron.Delims{Left: "[[", Right: "]]"},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
m.Use(hs.healthHandler)
|
|
||||||
m.Use(hs.metricsEndpoint)
|
m.Use(hs.metricsEndpoint)
|
||||||
m.Use(middleware.GetContextHandler(
|
m.Use(middleware.GetContextHandler(
|
||||||
hs.AuthTokenService,
|
hs.AuthTokenService,
|
||||||
@@ -386,7 +385,12 @@ func (hs *HTTPServer) healthHandler(ctx *macaron.Context) {
|
|||||||
ctx.Resp.WriteHeader(200)
|
ctx.Resp.WriteHeader(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataBytes, _ := data.EncodePretty()
|
dataBytes, err := data.EncodePretty()
|
||||||
|
if err != nil {
|
||||||
|
hs.log.Error("Failed to encode data", "err", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := ctx.Resp.Write(dataBytes); err != nil {
|
if _, err := ctx.Resp.Write(dataBytes); err != nil {
|
||||||
hs.log.Error("Failed to write to response", "err", err)
|
hs.log.Error("Failed to write to response", "err", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ func GetDataSourceById(query *models.GetDataSourceByIdQuery) error {
|
|||||||
|
|
||||||
datasource := models.DataSource{OrgId: query.OrgId, Id: query.Id}
|
datasource := models.DataSource{OrgId: query.OrgId, Id: query.Id}
|
||||||
has, err := x.Get(&datasource)
|
has, err := x.Get(&datasource)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ func (ss *SqlStore) WithDbSession(ctx context.Context, callback dbTransactionFun
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
defer sess.Close()
|
||||||
|
|
||||||
return callback(sess)
|
return callback(sess)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"xorm.io/xorm"
|
"xorm.io/xorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// WithTransactionalDbSession calls the callback with an session within a transaction
|
// WithTransactionalDbSession calls the callback with a session within a transaction.
|
||||||
func (ss *SqlStore) WithTransactionalDbSession(ctx context.Context, callback dbTransactionFunc) error {
|
func (ss *SqlStore) WithTransactionalDbSession(ctx context.Context, callback dbTransactionFunc) error {
|
||||||
return inTransactionWithRetryCtx(ctx, ss.engine, callback, 0)
|
return inTransactionWithRetryCtx(ctx, ss.engine, callback, 0)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ func (e *cloudWatchExecutor) executeLogActions(ctx context.Context, queryContext
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resultChan <- &tsdb.QueryResult{RefId: query.RefId, Dataframes: tsdb.NewDecodedDataFrames(data.Frames{dataframe})}
|
resultChan <- &tsdb.QueryResult{
|
||||||
|
RefId: query.RefId,
|
||||||
|
Dataframes: tsdb.NewDecodedDataFrames(data.Frames{dataframe}),
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -165,7 +168,7 @@ func (e *cloudWatchExecutor) handleDescribeLogGroups(ctx context.Context,
|
|||||||
|
|
||||||
var response *cloudwatchlogs.DescribeLogGroupsOutput = nil
|
var response *cloudwatchlogs.DescribeLogGroupsOutput = nil
|
||||||
var err error
|
var err error
|
||||||
if len(logGroupNamePrefix) < 1 {
|
if len(logGroupNamePrefix) == 0 {
|
||||||
response, err = logsClient.DescribeLogGroupsWithContext(ctx, &cloudwatchlogs.DescribeLogGroupsInput{
|
response, err = logsClient.DescribeLogGroupsWithContext(ctx, &cloudwatchlogs.DescribeLogGroupsInput{
|
||||||
Limit: aws.Int64(parameters.Get("limit").MustInt64(50)),
|
Limit: aws.Int64(parameters.Get("limit").MustInt64(50)),
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -109,11 +109,11 @@ type dataFrames struct {
|
|||||||
encoded [][]byte
|
encoded [][]byte
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDecodedDataFrames create new DataFrames from decoded frames.
|
// NewDecodedDataFrames instantiates DataFrames from decoded frames.
|
||||||
//
|
//
|
||||||
// This should be the primary function for creating DataFrames if your implementing a plugin.
|
// This should be the primary function for creating DataFrames if you're implementing a plugin.
|
||||||
// In Grafana alerting scenario it needs to operate on decoded frames why this function is
|
// In a Grafana alerting scenario it needs to operate on decoded frames, which is why this function is
|
||||||
// preferrable. When encoded data frames is needed, e.g. returned from Grafana HTTP API, it will
|
// preferrable. When encoded data frames are needed, e.g. returned from Grafana HTTP API, it will
|
||||||
// happen automatically when MarshalJSON() is called.
|
// happen automatically when MarshalJSON() is called.
|
||||||
func NewDecodedDataFrames(decodedFrames data.Frames) DataFrames {
|
func NewDecodedDataFrames(decodedFrames data.Frames) DataFrames {
|
||||||
return &dataFrames{
|
return &dataFrames{
|
||||||
@@ -121,7 +121,7 @@ func NewDecodedDataFrames(decodedFrames data.Frames) DataFrames {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncodedDataFrames create new DataFrames from encoded frames.
|
// NewEncodedDataFrames instantiates DataFrames from encoded frames.
|
||||||
//
|
//
|
||||||
// This one is primarily used for creating DataFrames when receiving encoded data frames from an external
|
// This one is primarily used for creating DataFrames when receiving encoded data frames from an external
|
||||||
// plugin or similar. This may allow the encoded data frames to be returned to Grafana UI without any additional
|
// plugin or similar. This may allow the encoded data frames to be returned to Grafana UI without any additional
|
||||||
|
|||||||
Reference in New Issue
Block a user