mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-45536: Track GraphQL queries in Grafana (#20609)
https://mattermost.atlassian.net/browse/MM-45536 ```release-note NONE ```
This commit is contained in:
@@ -101,6 +101,8 @@ func (api *API) graphQL(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
c.GraphQLOperationName = params.OperationName
|
||||
|
||||
// Populate the context with required info.
|
||||
reqCtx := r.Context()
|
||||
reqCtx = context.WithValue(reqCtx, webCtx, c)
|
||||
|
||||
@@ -19,12 +19,15 @@ import (
|
||||
)
|
||||
|
||||
type Context struct {
|
||||
App app.AppIface
|
||||
AppContext *request.Context
|
||||
Logger *mlog.Logger
|
||||
Params *Params
|
||||
Err *model.AppError
|
||||
siteURLHeader string
|
||||
App app.AppIface
|
||||
AppContext *request.Context
|
||||
Logger *mlog.Logger
|
||||
Params *Params
|
||||
Err *model.AppError
|
||||
// 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.
|
||||
|
||||
@@ -382,7 +382,14 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if r.URL.Path != model.APIURLSuffix+"/websocket" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user