MM-45536: Track GraphQL queries in Grafana (#20609)
https://mattermost.atlassian.net/browse/MM-45536 ```release-note NONE ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ad181532af
Коммит
b0327c2953
@@ -101,6 +101,8 @@ func (api *API) graphQL(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.GraphQLOperationName = params.OperationName
|
||||||
|
|
||||||
// Populate the context with required info.
|
// Populate the context with required info.
|
||||||
reqCtx := r.Context()
|
reqCtx := r.Context()
|
||||||
reqCtx = context.WithValue(reqCtx, webCtx, c)
|
reqCtx = context.WithValue(reqCtx, webCtx, c)
|
||||||
|
|||||||
@@ -19,12 +19,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Context struct {
|
type Context struct {
|
||||||
App app.AppIface
|
App app.AppIface
|
||||||
AppContext *request.Context
|
AppContext *request.Context
|
||||||
Logger *mlog.Logger
|
Logger *mlog.Logger
|
||||||
Params *Params
|
Params *Params
|
||||||
Err *model.AppError
|
Err *model.AppError
|
||||||
siteURLHeader string
|
// This is used to track the graphQL query that's being executed,
|
||||||
|
// so that we can monitor the timings in Grafana.
|
||||||
|
GraphQLOperationName string
|
||||||
|
siteURLHeader string
|
||||||
}
|
}
|
||||||
|
|
||||||
// LogAuditRec logs an audit record using default LevelAPI.
|
// LogAuditRec logs an audit record using default LevelAPI.
|
||||||
|
|||||||
@@ -382,7 +382,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if r.URL.Path != model.APIURLSuffix+"/websocket" {
|
if r.URL.Path != model.APIURLSuffix+"/websocket" {
|
||||||
elapsed := float64(time.Since(now)) / float64(time.Second)
|
elapsed := float64(time.Since(now)) / float64(time.Second)
|
||||||
c.App.Metrics().ObserveAPIEndpointDuration(h.HandlerName, r.Method, statusCode, elapsed)
|
var endpoint string
|
||||||
|
if strings.HasPrefix(r.URL.Path, model.APIURLSuffixV5) {
|
||||||
|
// It's a graphQL query, so use the operation name.
|
||||||
|
endpoint = c.GraphQLOperationName
|
||||||
|
} else {
|
||||||
|
endpoint = h.HandlerName
|
||||||
|
}
|
||||||
|
c.App.Metrics().ObserveAPIEndpointDuration(endpoint, r.Method, statusCode, elapsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user