use logger context in cloudwatch (#57842)
This commit is contained in:
@@ -4,11 +4,12 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/cwlog"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
||||
)
|
||||
|
||||
func ResourceRequestMiddleware(handleFunc models.RouteHandlerFunc, reqCtxFactory models.RequestContextFactoryFunc) func(rw http.ResponseWriter, req *http.Request) {
|
||||
func ResourceRequestMiddleware(handleFunc models.RouteHandlerFunc, logger log.Logger, reqCtxFactory models.RequestContextFactoryFunc) func(rw http.ResponseWriter, req *http.Request) {
|
||||
return func(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "GET" {
|
||||
respondWithError(rw, models.NewHttpError("Invalid method", http.StatusMethodNotAllowed, nil))
|
||||
@@ -19,7 +20,7 @@ func ResourceRequestMiddleware(handleFunc models.RouteHandlerFunc, reqCtxFactory
|
||||
pluginContext := httpadapter.PluginConfigFromContext(ctx)
|
||||
json, httpError := handleFunc(pluginContext, reqCtxFactory, req.URL.Query())
|
||||
if httpError != nil {
|
||||
cwlog.Error("error handling resource request", "error", httpError.Message)
|
||||
logger.Error("error handling resource request", "error", httpError.Message)
|
||||
respondWithError(rw, httpError)
|
||||
return
|
||||
}
|
||||
@@ -27,7 +28,7 @@ func ResourceRequestMiddleware(handleFunc models.RouteHandlerFunc, reqCtxFactory
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
_, err := rw.Write(json)
|
||||
if err != nil {
|
||||
cwlog.Error("error handling resource request", "error", err)
|
||||
logger.Error("error handling resource request", "error", err)
|
||||
respondWithError(rw, models.NewHttpError("error writing response in resource request middleware", http.StatusInternalServerError, err))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user