grafana/pkg/api/frontend_metrics.go
Piotr Jamróz bb24e8d578
Chore: Report frontend metrics for JS/CSS load time (#42421)
* Report frontend metrics for js/css load time

* Add FCP metric

* Change comment

* Simplify reporting frontend metrics
2021-12-02 09:34:39 +01:00

26 lines
705 B
Go

package api
import (
"net/http"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/infra/metrics"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/web"
)
func (hs *HTTPServer) PostFrontendMetrics(c *models.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)
}