grafana/pkg/api/frontend_metrics.go
idafurjes 6c5a573772
Chore: Move ReqContext to contexthandler service (#62102)
* Chore: Move ReqContext to contexthandler service

* Rename package to contextmodel

* Generate ngalert files

* Remove unused imports
2023-01-27 08:50:36 +01:00

26 lines
747 B
Go

package api
import (
"net/http"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/metrics"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/web"
)
func (hs *HTTPServer) PostFrontendMetrics(c *contextmodel.ReqContext) response.Response {
cmd := metrics.PostFrontendMetricsCommand{}
if err := web.Bind(c.Req, &cmd); err != nil {
return response.Error(http.StatusBadRequest, "bad request data", err)
}
for _, event := range cmd.Events {
if recorder, ok := metrics.FrontendMetrics[event.Name]; ok {
recorder(event)
} else {
c.Logger.Debug("Received unknown frontend metric", "metric", event.Name)
}
}
return response.Empty(200)
}