diff --git a/config/testing.yml b/config/testing.yml index 615487a4..9b7f9d7b 100644 --- a/config/testing.yml +++ b/config/testing.yml @@ -4,7 +4,6 @@ context_name: testing contexts: testing: output_path: test/data - enterprise_support: true connections: credential_rules: - rules: @@ -21,7 +20,8 @@ contexts: user_name: admin organization_name: Main Org. password: admin - ignore_filters: False # When set to true all Watched filtered folders will be ignored and ALL folders will be acted on + filter_override: + ignore_dashboard_filters: false dashboard_settings: nested_folders: false watched: @@ -47,7 +47,6 @@ contexts: dashboard_settings: nested_folders: false organization_name: Your Org - ignore_filters: False # When set to true all Watched filtered folders will be ignored and ALL folders will be acted on watched: - General qa: @@ -72,7 +71,6 @@ contexts: organization_name: Your Org dashboard_settings: nested_folders: false - ignore_filters: False # When set to true all Watched filtered folders will be ignored and ALL folders will be acted on watched: - Folder1 - Folder2 diff --git a/internal/config/config_loader.go b/internal/config/config_loader.go index 104be6ed..f1c92835 100644 --- a/internal/config/config_loader.go +++ b/internal/config/config_loader.go @@ -298,22 +298,9 @@ func InitGdgConfig(override, defaultConfig string) { log.Fatal("Invalid configuration detected, please fix your configuration and try again.") } if configData.viperConfiguration == nil { - configData.viperConfiguration = make(map[string]*viper.Viper, 0) + configData.viperConfiguration = make(map[string]*viper.Viper) } configData.viperConfiguration[ViperGdgConfig] = v - - // unmarshall struct - //contexts := configData.GetViperConfig(ViperGdgConfig).GetStringMap("contexts") - //contexts = applyEnvOverrides(contexts, "contexts", v) - // - //contextMaps, err := yaml.Marshal(contexts) - //if err != nil { - // log.Fatal("Failed to decode context map, please check your configuration") - //} - //err = yaml.Unmarshal(contextMaps, &configData.gdgConfig.Contexts) - //if err != nil { - // log.Fatal("No valid configuration file has been found") - //} } // readViperConfig utilizes the viper library to load the config from the selected paths @@ -331,7 +318,7 @@ func readViperConfig[T any](appName string, configDirs []string, object *T) (*vi err := v.ReadInConfig() if err == nil { - // Marshall the data read into a app struct + // Marshall the data read into app struct err = v.Unmarshal(object) } diff --git a/internal/config/connection_config.go b/internal/config/connection_config.go index 37453321..185cdbe6 100644 --- a/internal/config/connection_config.go +++ b/internal/config/connection_config.go @@ -49,21 +49,20 @@ type CredentialRule struct { // MatchingRule defines a single matching rule for Grafana Connections type MatchingRule struct { - Field string `yaml:"field,omitempty"` - Regex string `yaml:"regex,omitempty"` - Inclusive bool `yaml:"inclusive,omitempty"` + Field string `yaml:"field,omitempty" mapstructure:"field,omitempty"` + Regex string `yaml:"regex,omitempty" mapstructure:"regex,omitempty"` + Inclusive bool `yaml:"inclusive,omitempty" mapstructure:"inclusive,omitempty"` } // FilterOverrides model wraps filter overrides for grafana type FilterOverrides struct { - IgnoreDashboardFilters bool `yaml:"ignore_dashboard_filters"` + IgnoreDashboardFilters bool `yaml:"ignore_dashboard_filters" mapstructure:"ignore_dashboard_filters" ` } // ConnectionFilters model wraps connection filters for grafana type ConnectionFilters struct { - NameExclusions string `yaml:"name_exclusions"` - ConnectionTypes []string `yaml:"valid_types"` - // pattern *regexp.Regexp + NameExclusions string `yaml:"name_exclusions" mapstructure:"name_exclusions"` + ConnectionTypes []string `yaml:"valid_types" mapstructure:"valid_types"` } func (g GrafanaConnection) User() string { diff --git a/internal/service/dashboards.go b/internal/service/dashboards.go index 3edcaba4..57b46e64 100644 --- a/internal/service/dashboards.go +++ b/internal/service/dashboards.go @@ -519,7 +519,7 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) { if len(invalidCount) > 0 { log.Fatal("nested folder feature is disabled in GDG but import path contains a nested folder. Please fix the import or configuration. ", slog.String("files", strings.Join(invalidCount, ", "))) } - // Check duplicates + } // Delete all dashboards that match prior to import @@ -591,7 +591,7 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) { slog.Warn("unable to determine dashboard folder name, falling back on default") } - if folderName == "" || folderName == DefaultFolderName { + if folderName == "" { folderName = DefaultFolderName } if !slices.Contains(validFolders, folderName) && !config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters { diff --git a/pkg/test_tooling/nested_setup.go b/pkg/test_tooling/nested_setup.go index 007f2391..22272151 100644 --- a/pkg/test_tooling/nested_setup.go +++ b/pkg/test_tooling/nested_setup.go @@ -14,6 +14,7 @@ const ( OrgNameOverride = "GDG_CONTEXTS__TESTING__ORGANIZATION_NAME" EnableNestedBehavior = "GDG_CONTEXTS__TESTING__DASHBOARD_SETTINGS__NESTED_FOLDERS" grafanaNestedToggle = "GF_FEATURE_TOGGLES_ENABLE" + IgnoreDashFilters = "GDG_CONTEXTS__TESTING__FILTER_OVERRIDE__IGNORE_DASHBOARD_FILTERS" ) func setupNestedProps(t *testing.T, enterprise bool) map[string]string { diff --git a/test/dashboard_integration_test.go b/test/dashboard_integration_test.go index 262370bf..cab02dc7 100644 --- a/test/dashboard_integration_test.go +++ b/test/dashboard_integration_test.go @@ -12,65 +12,52 @@ import ( "github.com/esnet/gdg/internal/service" "github.com/esnet/gdg/internal/service/filters" "github.com/esnet/gdg/pkg/test_tooling" - "github.com/esnet/gdg/pkg/test_tooling/containers" "github.com/grafana/grafana-openapi-client-go/models" "github.com/stretchr/testify/assert" ) func TestDashboardNestedFolderCRUD(t *testing.T) { - t.Skip() if os.Getenv(test_tooling.EnableTokenTestsEnv) == "1" { - t.Log("Skipping token test for nested folders") - t.Skip() + t.Skip("skipping token based tests") } + containerObj, cleanup := test_tooling.InitOrgs(t, false) + assert.NoError(t, os.Setenv(test_tooling.OrgNameOverride, "testing")) + assert.NoError(t, os.Setenv(test_tooling.EnableNestedBehavior, "true")) + assert.NoError(t, os.Setenv(test_tooling.IgnoreDashFilters, "true")) - props := containers.DefaultGrafanaEnv() - props["GF_FEATURE_TOGGLES_ENABLE"] = "nestedFolders" - apiClient, _, _, cleanup := test_tooling.InitTest(t, nil, props) defer func() { - err := cleanup() - if err != nil { - slog.Warn("Unable to clean up after dashboard tests") - } + os.Unsetenv(test_tooling.OrgNameOverride) + os.Unsetenv(test_tooling.EnableNestedBehavior) + cleanup() }() + + apiClient, _ := test_tooling.CreateSimpleClient(t, nil, containerObj) + filtersEntity := service.NewDashboardFilter("", "", "") slog.Info("Exporting all dashboards") apiClient.UploadDashboards(filtersEntity) slog.Info("Listing all dashboards") boards := apiClient.ListDashboards(filtersEntity) slog.Info("Imported dashboards", "count", len(boards)) - ignoredSkipped := true var generalBoard *models.Hit - var otherBoard *models.Hit + var nestedFolder *models.Hit for ndx, board := range boards { slog.Info(board.Slug) - if board.Slug == "latency-patterns" { - ignoredSkipped = false - } - if board.Slug == "individual-flows" { + if board.Slug == "rabbitmq-overview" { generalBoard = boards[ndx] } - if board.Slug == "flow-information" { - otherBoard = boards[ndx] + if board.Slug == "node-exporter-full" { + nestedFolder = boards[ndx] } } - assert.NotNil(t, otherBoard) assert.NotNil(t, generalBoard) - assert.True(t, ignoredSkipped) - validateGeneralBoard(t, generalBoard) - validateOtherBoard(t, otherBoard) - // Validate filters - - filterFolder := service.NewDashboardFilter("Other", "", "") - boards = apiClient.ListDashboards(filterFolder) - assert.Equal(t, 8, len(boards)) - dashboardFilter := service.NewDashboardFilter("", "flow-information", "") - boards = apiClient.ListDashboards(dashboardFilter) - assert.Equal(t, 1, len(boards)) + assert.NotNil(t, nestedFolder) + nestedPath := service.GetNestedFolder(nestedFolder.FolderTitle, nestedFolder.FolderUID, apiClient) + assert.Equal(t, nestedPath, "Others/dummy") // Import Dashboards - numBoards := 16 + numBoards := 3 slog.Info("Importing Dashboards") list := apiClient.DownloadDashboards(filtersEntity) assert.Equal(t, len(list), numBoards) diff --git a/test/data/org_testing/dashboards/General/rabbitmq-overview.json b/test/data/org_testing/dashboards/General/rabbitmq-overview.json index 31409f34..865a4994 100644 --- a/test/data/org_testing/dashboards/General/rabbitmq-overview.json +++ b/test/data/org_testing/dashboards/General/rabbitmq-overview.json @@ -23,7 +23,7 @@ "fiscalYearStartMonth": 0, "gnetId": 10991, "graphTooltip": 1, - "id": 677, + "id": 1, "iteration": 1659711638455, "links": [ { diff --git a/test/data/org_testing/dashboards/Others/dummy/node-exporter-full.json b/test/data/org_testing/dashboards/Others/dummy/node-exporter-full.json index b725055d..9d33ad89 100644 --- a/test/data/org_testing/dashboards/Others/dummy/node-exporter-full.json +++ b/test/data/org_testing/dashboards/Others/dummy/node-exporter-full.json @@ -26,7 +26,7 @@ "fiscalYearStartMonth": 0, "gnetId": 1860, "graphTooltip": 1, - "id": 678, + "id": 4, "links": [ { "icon": "external link", @@ -23303,6 +23303,6 @@ "timezone": "browser", "title": "Node Exporter Full", "uid": "rYdddlPWk", - "version": 2, + "version": 1, "weekStart": "" } diff --git a/test/data/org_testing/dashboards/someFolder/k8s-storage-volumes-cluster.json b/test/data/org_testing/dashboards/someFolder/k8s-storage-volumes-cluster.json index 6ade44bf..d82dec41 100644 --- a/test/data/org_testing/dashboards/someFolder/k8s-storage-volumes-cluster.json +++ b/test/data/org_testing/dashboards/someFolder/k8s-storage-volumes-cluster.json @@ -3,7 +3,7 @@ "editable": true, "gnetId": 11454, "graphTooltip": 1, - "id": 679, + "id": 6, "iteration": 1577045029184, "links": [], "panels": [ @@ -2232,5 +2232,5 @@ "timezone": "", "title": "K8s / Storage / Volumes / Cluster", "uid": "bdx48n30kejuoa", - "version": 2 + "version": 1 }