Public Dashboards: use intervalMs and maxDataPoints from request (#53613)
This commit is contained in:
@@ -11,14 +11,11 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins/backendplugin"
|
||||
"github.com/grafana/grafana/pkg/services/accesscontrol"
|
||||
"github.com/grafana/grafana/pkg/services/dashboards"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
"github.com/grafana/grafana/pkg/services/publicdashboards"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
"github.com/grafana/grafana/pkg/services/query"
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
@@ -27,7 +24,6 @@ type Api struct {
|
||||
PublicDashboardService publicdashboards.Service
|
||||
RouteRegister routing.RouteRegister
|
||||
AccessControl accesscontrol.AccessControl
|
||||
QueryDataService *query.Service
|
||||
Features *featuremgmt.FeatureManager
|
||||
}
|
||||
|
||||
@@ -35,14 +31,12 @@ func ProvideApi(
|
||||
pd publicdashboards.Service,
|
||||
rr routing.RouteRegister,
|
||||
ac accesscontrol.AccessControl,
|
||||
qds *query.Service,
|
||||
features *featuremgmt.FeatureManager,
|
||||
) *Api {
|
||||
api := &Api{
|
||||
PublicDashboardService: pd,
|
||||
RouteRegister: rr,
|
||||
AccessControl: ac,
|
||||
QueryDataService: qds,
|
||||
Features: features,
|
||||
}
|
||||
|
||||
@@ -157,35 +151,16 @@ func (api *Api) QueryPublicDashboard(c *models.ReqContext) response.Response {
|
||||
return response.Error(http.StatusBadRequest, "invalid panel ID", err)
|
||||
}
|
||||
|
||||
// Get the dashboard
|
||||
pubdash, dashboard, err := api.PublicDashboardService.GetPublicDashboard(c.Req.Context(), web.Params(c.Req)[":accessToken"])
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "could not fetch dashboard", err)
|
||||
reqDTO := &PublicDashboardQueryDTO{}
|
||||
if err = web.Bind(c.Req, reqDTO); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
|
||||
// Build the request data objecct
|
||||
reqDTO, err := api.PublicDashboardService.BuildPublicDashboardMetricRequest(
|
||||
c.Req.Context(),
|
||||
dashboard,
|
||||
pubdash,
|
||||
panelId,
|
||||
)
|
||||
resp, err := api.PublicDashboardService.GetQueryDataResponse(c.Req.Context(), c.SkipCache, reqDTO, panelId, web.Params(c.Req)[":accessToken"])
|
||||
if err != nil {
|
||||
return handleDashboardErr(http.StatusInternalServerError, "Failed to get queries for public dashboard", err)
|
||||
return handlePublicDashboardErr(err)
|
||||
}
|
||||
|
||||
// Build anonymous user for the request
|
||||
anonymousUser, err := api.PublicDashboardService.BuildAnonymousUser(c.Req.Context(), dashboard)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "could not create anonymous user", err)
|
||||
}
|
||||
|
||||
// Make the request
|
||||
resp, err := api.QueryDataService.QueryDataMultipleSources(c.Req.Context(), anonymousUser, c.SkipCache, reqDTO, true)
|
||||
|
||||
if err != nil {
|
||||
return handleQueryMetricsError(err)
|
||||
}
|
||||
return toJsonStreamingResponse(api.Features, resp)
|
||||
}
|
||||
|
||||
@@ -209,24 +184,8 @@ func handleDashboardErr(defaultCode int, defaultMsg string, err error) response.
|
||||
return response.Error(defaultCode, defaultMsg, err)
|
||||
}
|
||||
|
||||
// Copied from pkg/api/metrics.go
|
||||
func handleQueryMetricsError(err error) *response.NormalResponse {
|
||||
if errors.Is(err, datasources.ErrDataSourceAccessDenied) {
|
||||
return response.Error(http.StatusForbidden, "Access denied to data source", err)
|
||||
}
|
||||
if errors.Is(err, datasources.ErrDataSourceNotFound) {
|
||||
return response.Error(http.StatusNotFound, "Data source not found", err)
|
||||
}
|
||||
var badQuery *query.ErrBadQuery
|
||||
if errors.As(err, &badQuery) {
|
||||
return response.Error(http.StatusBadRequest, util.Capitalize(badQuery.Message), err)
|
||||
}
|
||||
|
||||
if errors.Is(err, backendplugin.ErrPluginNotRegistered) {
|
||||
return response.Error(http.StatusNotFound, "Plugin not found", err)
|
||||
}
|
||||
|
||||
return response.Error(http.StatusInternalServerError, "Query data error", err)
|
||||
func handlePublicDashboardErr(err error) response.Response {
|
||||
return handleDashboardErr(http.StatusInternalServerError, "Unexpected Error", err)
|
||||
}
|
||||
|
||||
// Copied from pkg/api/metrics.go
|
||||
|
||||
Reference in New Issue
Block a user