schema: Migrate from scuemata to thema (#49805)
* Remove crufty scuemata bits Buhbye to: cue/ dir with old definitions, CI steps for checking unnecessary things, and the original dashboard scuemata file. * Remove grafana-cli cue subcommand * Remove old testdata * Don't swallow errors from codegen * Small nits and tweaks to cuectx package * WIP - refactor pluggen to use Thema Also consolidate the embed.FS in the repo root. * Finish halfway rename * Convert all panel models.cue to thema * Rewrite pluggen to use Thema * Remove pkg/schema, and trim command * Remove schemaloader service and usages Will be replaced by coremodel-centric hydrate/dehydrate system Soon™. * Remove schemaloader from wire * Remove hangover field on histogram models.cue * Fix lint errors, some vestiges of trim service * Remove unused cuetsify cli command
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/grafana/grafana/pkg/api/apierrors"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/middleware"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/plugins"
|
||||
@@ -19,17 +18,15 @@ import (
|
||||
type ImportDashboardAPI struct {
|
||||
dashboardImportService dashboardimport.Service
|
||||
quotaService QuotaService
|
||||
schemaLoaderService SchemaLoaderService
|
||||
pluginStore plugins.Store
|
||||
ac accesscontrol.AccessControl
|
||||
}
|
||||
|
||||
func New(dashboardImportService dashboardimport.Service, quotaService QuotaService,
|
||||
schemaLoaderService SchemaLoaderService, pluginStore plugins.Store, ac accesscontrol.AccessControl) *ImportDashboardAPI {
|
||||
pluginStore plugins.Store, ac accesscontrol.AccessControl) *ImportDashboardAPI {
|
||||
return &ImportDashboardAPI{
|
||||
dashboardImportService: dashboardImportService,
|
||||
quotaService: quotaService,
|
||||
schemaLoaderService: schemaLoaderService,
|
||||
pluginStore: pluginStore,
|
||||
ac: ac,
|
||||
}
|
||||
@@ -65,14 +62,6 @@ func (api *ImportDashboardAPI) ImportDashboard(c *models.ReqContext) response.Re
|
||||
return response.Error(403, "Quota reached", nil)
|
||||
}
|
||||
|
||||
trimDefaults := c.QueryBoolWithDefault("trimdefaults", true)
|
||||
if trimDefaults && !api.schemaLoaderService.IsDisabled() {
|
||||
req.Dashboard, err = api.schemaLoaderService.DashboardApplyDefaults(req.Dashboard)
|
||||
if err != nil {
|
||||
return response.Error(http.StatusInternalServerError, "Error while applying default value to the dashboard json", err)
|
||||
}
|
||||
}
|
||||
|
||||
req.User = c.SignedInUser
|
||||
resp, err := api.dashboardImportService.ImportDashboard(c.Req.Context(), &req)
|
||||
if err != nil {
|
||||
@@ -91,8 +80,3 @@ type quotaServiceFunc func(c *models.ReqContext, target string) (bool, error)
|
||||
func (fn quotaServiceFunc) QuotaReached(c *models.ReqContext, target string) (bool, error) {
|
||||
return fn(c, target)
|
||||
}
|
||||
|
||||
type SchemaLoaderService interface {
|
||||
IsDisabled() bool
|
||||
DashboardApplyDefaults(input *simplejson.Json) (*simplejson.Json, error)
|
||||
}
|
||||
|
||||
@@ -26,15 +26,7 @@ func TestImportDashboardAPI(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
schemaLoaderServiceCalled := false
|
||||
schemaLoaderService := &schemaLoaderServiceMock{
|
||||
dashboardApplyDefaultsFunc: func(input *simplejson.Json) (*simplejson.Json, error) {
|
||||
schemaLoaderServiceCalled = true
|
||||
return input, nil
|
||||
},
|
||||
}
|
||||
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaNotReached), schemaLoaderService, nil, acmock.New().WithDisabled())
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaNotReached), nil, acmock.New().WithDisabled())
|
||||
routeRegister := routing.NewRouteRegister()
|
||||
importDashboardAPI.RegisterAPIEndpoints(routeRegister)
|
||||
s := webtest.NewServer(t, routeRegister)
|
||||
@@ -98,7 +90,6 @@ func TestImportDashboardAPI(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.False(t, schemaLoaderServiceCalled)
|
||||
require.True(t, importDashboardServiceCalled)
|
||||
})
|
||||
})
|
||||
@@ -112,16 +103,7 @@ func TestImportDashboardAPI(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
schemaLoaderServiceCalled := false
|
||||
schemaLoaderService := &schemaLoaderServiceMock{
|
||||
enabled: true,
|
||||
dashboardApplyDefaultsFunc: func(input *simplejson.Json) (*simplejson.Json, error) {
|
||||
schemaLoaderServiceCalled = true
|
||||
return input, nil
|
||||
},
|
||||
}
|
||||
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaNotReached), schemaLoaderService, nil, acmock.New().WithDisabled())
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaNotReached), nil, acmock.New().WithDisabled())
|
||||
routeRegister := routing.NewRouteRegister()
|
||||
importDashboardAPI.RegisterAPIEndpoints(routeRegister)
|
||||
s := webtest.NewServer(t, routeRegister)
|
||||
@@ -140,15 +122,13 @@ func TestImportDashboardAPI(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, resp.Body.Close())
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.True(t, schemaLoaderServiceCalled)
|
||||
require.True(t, importDashboardServiceCalled)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("Quota reached", func(t *testing.T) {
|
||||
service := &serviceMock{}
|
||||
schemaLoaderService := &schemaLoaderServiceMock{}
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaReached), schemaLoaderService, nil, acmock.New().WithDisabled())
|
||||
importDashboardAPI := New(service, quotaServiceFunc(quotaReached), nil, acmock.New().WithDisabled())
|
||||
|
||||
routeRegister := routing.NewRouteRegister()
|
||||
importDashboardAPI.RegisterAPIEndpoints(routeRegister)
|
||||
@@ -184,23 +164,6 @@ func (s *serviceMock) ImportDashboard(ctx context.Context, req *dashboardimport.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
type schemaLoaderServiceMock struct {
|
||||
enabled bool
|
||||
dashboardApplyDefaultsFunc func(input *simplejson.Json) (*simplejson.Json, error)
|
||||
}
|
||||
|
||||
func (s *schemaLoaderServiceMock) IsDisabled() bool {
|
||||
return !s.enabled
|
||||
}
|
||||
|
||||
func (s *schemaLoaderServiceMock) DashboardApplyDefaults(input *simplejson.Json) (*simplejson.Json, error) {
|
||||
if s.dashboardApplyDefaultsFunc != nil {
|
||||
return s.dashboardApplyDefaultsFunc(input)
|
||||
}
|
||||
|
||||
return input, nil
|
||||
}
|
||||
|
||||
func quotaReached(c *models.ReqContext, target string) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user