From d8ab3cc5ea30b1a6731fc2f39671ccb0c3b1b064 Mon Sep 17 00:00:00 2001 From: Samir Faci Date: Wed, 11 Sep 2024 13:23:33 -0400 Subject: [PATCH] Deprecating FilterOverride in favor of DashboardSettings property --- internal/config/config_model.go | 8 -------- internal/config/connection_config.go | 6 ------ internal/config/grafana_config.go | 2 +- internal/service/dashboards.go | 6 +++--- internal/service/folders.go | 2 +- internal/service/libraryelements.go | 2 +- pkg/test_tooling/nested_setup.go | 2 +- test/dashboard_integration_test.go | 4 ++-- 8 files changed, 9 insertions(+), 23 deletions(-) diff --git a/internal/config/config_model.go b/internal/config/config_model.go index 885e3eaf..ee782a28 100644 --- a/internal/config/config_model.go +++ b/internal/config/config_model.go @@ -99,14 +99,6 @@ func (s *GrafanaConfig) GetDashboardSettings() *DashboardSettings { return s.DashboardSettings } -// GetFilterOverrides returns the filter overrides for the connection -func (s *GrafanaConfig) GetFilterOverrides() *FilterOverrides { - if s.FilterOverrides == nil { - s.FilterOverrides = &FilterOverrides{IgnoreDashboardFilters: false} - } - return s.FilterOverrides -} - // GetDataSourceSettings returns the datasource settings for the connection func (s *GrafanaConfig) GetDataSourceSettings() *ConnectionSettings { if s.ConnectionSettings == nil { diff --git a/internal/config/connection_config.go b/internal/config/connection_config.go index 63d39361..fc75cbda 100644 --- a/internal/config/connection_config.go +++ b/internal/config/connection_config.go @@ -54,12 +54,6 @@ type MatchingRule struct { Inclusive bool `yaml:"inclusive,omitempty" mapstructure:"inclusive,omitempty"` } -// TODO: Move setting into DashboardSettings -// FilterOverrides model wraps filter overrides for grafana -type FilterOverrides struct { - 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" mapstructure:"name_exclusions"` diff --git a/internal/config/grafana_config.go b/internal/config/grafana_config.go index ad568382..e84cd13d 100644 --- a/internal/config/grafana_config.go +++ b/internal/config/grafana_config.go @@ -2,6 +2,7 @@ package config type DashboardSettings struct { NestedFolders bool `mapstructure:"nested_folders" yaml:"nested_folders"` + IgnoreFilters bool `yaml:"ignore_filters" mapstructure:"ignore_filters" ` } // GrafanaConfig model wraps auth and watched list for grafana @@ -17,7 +18,6 @@ type GrafanaConfig struct { MonitoredFolders []string `mapstructure:"watched" yaml:"watched"` ConnectionSettings *ConnectionSettings `mapstructure:"connections" yaml:"connections"` UserSettings *UserSettings `mapstructure:"user" yaml:"user"` - FilterOverrides *FilterOverrides `mapstructure:"filter_override" yaml:"filter_override"` DashboardSettings *DashboardSettings `mapstructure:"dashboard_settings" yaml:"dashboard_settings"` OutputPath string `mapstructure:"output_path" yaml:"output_path"` } diff --git a/internal/service/dashboards.go b/internal/service/dashboards.go index 53e2e182..a6cbf121 100644 --- a/internal/service/dashboards.go +++ b/internal/service/dashboards.go @@ -154,7 +154,7 @@ func (s *DashNGoImpl) LintDashboards(req types.LintRequest) []string { continue } if req.FolderName != "" { - if !slices.Contains(validFolders, req.FolderName) && !config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters { + if !slices.Contains(validFolders, req.FolderName) && !config.Config().GetDefaultGrafanaConfig().GetDashboardSettings().IgnoreFilters { slog.Debug("Skipping file since it doesn't match any valid folders", "filename", file) continue } @@ -322,7 +322,7 @@ func (s *DashNGoImpl) ListDashboards(filterReq filters.Filter) []*models.Hit { } // accepts all folders - if config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters { + if config.Config().GetDefaultGrafanaConfig().GetDashboardSettings().IgnoreFilters { validFolder = true } else if validateFolderRegex(folderFilters, folderMatch) { // validFolder = true @@ -606,7 +606,7 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) { if folderName == "" { folderName = DefaultFolderName } - if !slices.Contains(validFolders, folderName) && !config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters { + if !slices.Contains(validFolders, folderName) && !config.Config().GetDefaultGrafanaConfig().GetDashboardSettings().IgnoreFilters { slog.Debug("Skipping file since it doesn't match any valid folders", "filename", file) continue } diff --git a/internal/service/folders.go b/internal/service/folders.go index be61cc5b..bb78c6d7 100644 --- a/internal/service/folders.go +++ b/internal/service/folders.go @@ -167,7 +167,7 @@ func (s *DashNGoImpl) ListFolderPermissions(filter filters.Filter) map[*types.Fo // ListFolder list the current existing folders that match the given filter. func (s *DashNGoImpl) ListFolders(filter filters.Filter) []*types.FolderDetails { result := make([]*types.FolderDetails, 0) - if config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters { + if config.Config().GetDefaultGrafanaConfig().GetDashboardSettings().IgnoreFilters { filter = nil } if err := s.nestedFoldersSanityCheck(); err != nil { diff --git a/internal/service/libraryelements.go b/internal/service/libraryelements.go index 79957089..3d21821a 100644 --- a/internal/service/libraryelements.go +++ b/internal/service/libraryelements.go @@ -43,7 +43,7 @@ func (s *DashNGoImpl) ListLibraryElementsConnections(filter filters.Filter, conn } func (s *DashNGoImpl) ListLibraryElements(filter filters.Filter) []*models.LibraryElementDTO { - ignoreFilters := config.Config().GetDefaultGrafanaConfig().GetFilterOverrides().IgnoreDashboardFilters + ignoreFilters := config.Config().GetDefaultGrafanaConfig().GetDashboardSettings().IgnoreFilters folderFilter := NewFolderFilter() if ignoreFilters { folderFilter = nil diff --git a/pkg/test_tooling/nested_setup.go b/pkg/test_tooling/nested_setup.go index a6562748..e17c0f6e 100644 --- a/pkg/test_tooling/nested_setup.go +++ b/pkg/test_tooling/nested_setup.go @@ -14,7 +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" + IgnoreDashFilters = "GDG_CONTEXTS__TESTING__DASHBOARD_SETTINGS__IGNORE_FILTERS" ) // setupNestedProps adds the nestedFolder feature to the given Env properties map diff --git a/test/dashboard_integration_test.go b/test/dashboard_integration_test.go index ac3f1b08..8b29f75b 100644 --- a/test/dashboard_integration_test.go +++ b/test/dashboard_integration_test.go @@ -253,8 +253,8 @@ func TestWildcardFilter(t *testing.T) { // Enable Wildcard testingContext := config.Config().GetGDGConfig().GetContexts()["testing"] - testingContext.GetFilterOverrides().IgnoreDashboardFilters = true - assert.True(t, testingContext.GetFilterOverrides().IgnoreDashboardFilters) + testingContext.GetDashboardSettings().IgnoreFilters = true + assert.True(t, testingContext.GetDashboardSettings().IgnoreFilters) // Testing Exporting with Wildcard apiClient.UploadDashboards(emptyFilter)