grafana/pkg/infra/usagestats/service/api.go
J Guerreiro 1e9818a69f
Add usage stats preview endpoint (#43899)
* Stats: add preview route for usage statistics

* Stats: respect reporting settings

* Stats: add tests to api endpoint

* Stats: unregister route

* Stats: always possible to preview stats

* Update pkg/infra/usagestats/service/api.go

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>

Co-authored-by: Gabriel MABILLE <gamab@users.noreply.github.com>
2022-01-14 10:16:07 +01:00

28 lines
802 B
Go

package service
import (
"net/http"
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/api/routing"
"github.com/grafana/grafana/pkg/middleware"
"github.com/grafana/grafana/pkg/models"
)
const rootUrl = "/api/admin"
func (uss *UsageStats) registerAPIEndpoints() {
uss.RouteRegister.Group(rootUrl, func(subrouter routing.RouteRegister) {
subrouter.Get("/usage-report-preview", middleware.ReqGrafanaAdmin, routing.Wrap(uss.getUsageReportPreview))
})
}
func (uss *UsageStats) getUsageReportPreview(ctx *models.ReqContext) response.Response {
usageReport, err := uss.GetUsageReport(ctx.Req.Context())
if err != nil {
return response.Error(http.StatusInternalServerError, "failed to get usage report", err)
}
return response.JSON(http.StatusOK, usageReport)
}