Skip to content

Commit

Permalink
Deprecating FilterOverride in favor of DashboardSettings property
Browse files Browse the repository at this point in the history
  • Loading branch information
safaci2000 committed Sep 11, 2024
1 parent e9b3f74 commit d8ab3cc
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 23 deletions.
8 changes: 0 additions & 8 deletions internal/config/config_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions internal/config/connection_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion internal/config/grafana_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
Expand Down
6 changes: 3 additions & 3 deletions internal/service/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/folders.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/libraryelements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/test_tooling/nested_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/dashboard_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8ab3cc

Please sign in to comment.