diff --git a/pkg/api/apierrors/dashboard.go b/pkg/api/apierrors/dashboard.go index 6f740d80afd..e05c81ce329 100644 --- a/pkg/api/apierrors/dashboard.go +++ b/pkg/api/apierrors/dashboard.go @@ -7,9 +7,11 @@ import ( "net/http" "github.com/grafana/grafana/pkg/api/response" + "github.com/grafana/grafana/pkg/services/apiserver" "github.com/grafana/grafana/pkg/services/dashboards" "github.com/grafana/grafana/pkg/services/pluginsintegration/pluginstore" "github.com/grafana/grafana/pkg/util" + apierrors "k8s.io/apimachinery/pkg/api/errors" ) // ToDashboardErrorResponse returns a different response status according to the dashboard error type @@ -39,5 +41,9 @@ func ToDashboardErrorResponse(ctx context.Context, pluginStore pluginstore.Store return response.JSON(http.StatusPreconditionFailed, util.DynMap{"status": "plugin-dashboard", "message": message}) } + if apierrors.IsRequestEntityTooLargeError(err) { + return response.Error(http.StatusRequestEntityTooLarge, fmt.Sprintf("Dashboard is too large, max is %d MB", apiserver.MaxRequestBodyBytes/1024/1024), err) + } + return response.Error(http.StatusInternalServerError, "Failed to save dashboard", err) } diff --git a/pkg/services/apiserver/service.go b/pkg/services/apiserver/service.go index 18be2d05f84..4a4b5ac3ab0 100644 --- a/pkg/services/apiserver/service.go +++ b/pkg/services/apiserver/service.go @@ -80,6 +80,8 @@ var ( ready = make(chan struct{}) ) +const MaxRequestBodyBytes = 16 * 1024 * 1024 // 16MB - determined by the size of `mediumtext` on mysql, which is used to save dashboard data + func init() { // we need to add the options to empty v1 metav1.AddToGroupVersion(Scheme, schema.GroupVersion{Group: "", Version: "v1"}) @@ -335,7 +337,7 @@ func (s *service) start(ctx context.Context) error { transport := &roundTripperFunc{ready: make(chan struct{})} serverConfig.LoopbackClientConfig.Transport = transport serverConfig.LoopbackClientConfig.TLSClientConfig = clientrest.TLSClientConfig{} - serverConfig.MaxRequestBodyBytes = 16 * 1024 * 1024 // 16MB - determined by the size of `mediumtext` on mysql, which is used to save dashboard data + serverConfig.MaxRequestBodyBytes = MaxRequestBodyBytes var optsregister apistore.StorageOptionsRegister