Skip to content

Commit

Permalink
Updating behavior or dashboard to not be so intrusive.
Browse files Browse the repository at this point in the history
Fixes #296

Previous behavior:
  1. Delete all monitored dashboards
  2. Upload all dashboards from backup.

New Behavior:
  1. Upload all dashboards from backup overwriting existing Dashboards.
  2. Delete any dashboards that exists in grafana but are missing from backup.
  • Loading branch information
safaci2000 committed Jan 16, 2025
1 parent 0bb1b07 commit f189025
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 44 deletions.
28 changes: 25 additions & 3 deletions internal/service/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) error {

}

// Delete all dashboards that match prior to import
s.DeleteAllDashboards(filterReq)
currentDashboards := s.ListDashboards(filterReq)

folderUidMap := s.getFolderNameUIDMap(s.ListFolders(NewFolderFilter()))

Expand Down Expand Up @@ -641,9 +640,32 @@ func (s *DashNGoImpl) UploadDashboards(filterReq filters.Filter) error {
}

}

for _, item := range currentDashboards {
if ok := alreadyProcessed[item.UID]; !ok {
slog.Info("Deleting Dashboard not found in backup", "folder", item.FolderTitle, "dashboard", item.Title)
err := s.deleteDashboard(item)
if err != nil {
slog.Error("Unable to delete dashboard", "folder", item.FolderTitle, "dashboard", item.Title)
}
}
}
return nil
}

// deleteDashboard removes a dashboard from grafana. If the dashboard doesn't exist,
// an error is returned.
//
// Parameters:
// item - dashboard to be deleted
//
// Returns:
// error - error returned from the grafana API
func (s *DashNGoImpl) deleteDashboard(item *models.Hit) error {
_, err := s.GetClient().Dashboards.DeleteDashboardByUID(item.UID)
return err
}

// DeleteAllDashboards clears all current dashboards being monitored. Any folder not white listed
// will not be affected
func (s *DashNGoImpl) DeleteAllDashboards(filter filters.Filter) []string {
Expand All @@ -652,7 +674,7 @@ func (s *DashNGoImpl) DeleteAllDashboards(filter filters.Filter) []string {
items := s.ListDashboards(filter)
for _, item := range items {
if filter.ValidateAll(map[filters.FilterType]string{filters.FolderFilter: item.FolderTitle, filters.DashFilter: item.Slug}) {
_, err := s.GetClient().Dashboards.DeleteDashboardByUID(item.UID)
err := s.deleteDashboard(item)
if err == nil {
dashboardListing = append(dashboardListing, item.Title)
} else {
Expand Down
3 changes: 0 additions & 3 deletions test/connections_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ func TestConnectionsCRUD(t *testing.T) {

// TestConnectionFilter ensures the regex matching and datasource type filters work as expected
func TestConnectionFilter(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
_, _, _, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer func() {
cleanErr := cleanup()
Expand Down
17 changes: 0 additions & 17 deletions test/dashboard_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ func TestDashboardNestedFolderCRUD(t *testing.T) {
}

func TestDashboardCRUD(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
config.InitGdgConfig("testing")
apiClient, _, cleanup := test_tooling.InitTest(t, service.DefaultConfigProvider, nil)
defer func() {
Expand Down Expand Up @@ -151,10 +148,6 @@ func TestDashboardCRUD(t *testing.T) {
// If a duplicate file with the same UID exists, the upload should fail. Having a cleanup flag turned on, should
// fix that issue.
func TestDashboardCleanUpCrud(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

config.InitGdgConfig("testing")
cfgProvider := func() *config.Configuration {
cfg := config.Config()
Expand Down Expand Up @@ -196,9 +189,6 @@ func TestDashboardCleanUpCrud(t *testing.T) {
}

func TestDashboardCRUDTags(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
apiClient, _, container, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer func() {
err := cleanup()
Expand Down Expand Up @@ -260,9 +250,6 @@ func TestDashboardCRUDTags(t *testing.T) {
}

func TestDashboardTagsFilter(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
apiClient, _, _, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer cleanup()
emptyFilter := filters.NewBaseFilter()
Expand Down Expand Up @@ -365,10 +352,6 @@ func TestDashboardPermissionsCrud(t *testing.T) {
}

func TestWildcardFilter(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

// Setup Filters
apiClient, _, _, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer cleanup()
Expand Down
3 changes: 0 additions & 3 deletions test/folder_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
)

func TestFolderCRUD(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
apiClient, _, _, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer cleanup()
slog.Info("Exporting all folders")
Expand Down
4 changes: 0 additions & 4 deletions test/libraryelements_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
)

func TestLibraryElementsCRUD(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}

apiClient, _, _, cleanup := test_tooling.InitTestLegacy(t, nil, nil)
defer cleanup()
filtersEntity := service.NewDashboardFilter("", "", "")
Expand Down
9 changes: 0 additions & 9 deletions test/organizations_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import (
)

func TestOrganizationCrud(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if os.Getenv("TEST_TOKEN_CONFIG") == "1" {
t.Skip("Skipping Token configuration, Organization CRUD requires Basic SecureData")
}
Expand All @@ -40,9 +37,6 @@ func TestOrganizationCrud(t *testing.T) {
}

func TestOrganizationUserMembership(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if os.Getenv(test_tooling.EnableTokenTestsEnv) == "1" {
t.Skip("Skipping Token configuration, Organization CRUD requires Basic SecureData")
}
Expand Down Expand Up @@ -93,9 +87,6 @@ func TestOrganizationUserMembership(t *testing.T) {
}

func TestOrganizationProperties(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if os.Getenv(test_tooling.EnableTokenTestsEnv) == "1" {
t.Skip("Skipping Token configuration, Organization CRUD requires Basic SecureData")
}
Expand Down
3 changes: 0 additions & 3 deletions test/team_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import (
)

func TestTeamCRUD(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test")
}
if os.Getenv("TEST_TOKEN_CONFIG") == "1" {
t.Skip("Skipping Token configuration, Team and User CRUD requires Basic SecureData")
}
Expand Down
10 changes: 8 additions & 2 deletions website/content/docs/releases/gdg_0.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,36 @@ toc: true


## Release Notes for v0.7.2
**Release Date: TBD**
**Release Date: 01/17/2025**

### Breaking Changes
- [#318](https://github.com/esnet/gdg/pull/318) Only affects those with no valid configuration present. Removed the default
config fall back. For backup and tools functionality a valid configuration file is now required. A new cli parameter is introduced: `default-config`
which will print an example configuration to stdout.
### Feature Changes
- [#319](https://github.com/esnet/gdg/pull/319) Remove the requirement for GF_FEATURE_TOGGLES_ENABLE for nested folder as it was incorrectly required in 0.7.1
- [#302](https://github.com/esnet/gdg/pull/302) Adding Contact Points support.
- [#302](https://github.com/esnet/gdg/pull/302) Adding Alerting Contact Points support. (Beta Feature, API/format may change in the next release)
- [#303](https://github.com/esnet/gdg/pull/303) Cleaning up Permission based listings. (Visualization)
- [#274](https://github.com/esnet/gdg/pull/274) Adding Dashboard Permissions, enterprise feature.
- [#337](https://github.com/esnet/gdg/pull/337) Fix to maintain UIDs when updating dashboards
- [#324](https://github.com/esnet/gdg/pull/324) Introducing a new config option to disregard bad folders

Example:
```yaml
dashboard_settings:
ignore_bad_folders: true
```
### Bug Fixes
- [#330](https://github.com/esnet/gdg/pull/330) Fix bug with leading prefix in path when using cloud storage
- [#333](https://github.com/esnet/gdg/pull/333) Fix bug with documentation search
- [#314](https://github.com/esnet/gdg/pull/314) Update README to reflected newly supported features
### Security Fixes / Technical Debt
- [#326](https://github.com/esnet/gdg/pull/326) Bump golang.org/x/crypto from 0.28.0 to 0.31.0
- [#327](https://github.com/esnet/gdg/pull/327) Security Fix: Non-linear parsing of case-insensitive content in net/html
- [#328](https://github.com/esnet/gdg/pull/328) Security: Fixing NPM security issues. #328
- [320](https://github.com/esnet/gdg/pull/320) Changed default branch from `master` to `main`
- [332](https://github.com/esnet/gdg/pull/332) Added a VHS tape to programmatically re-generate quickstart.gif


## Release Notes for v0.7.1
Expand Down

0 comments on commit f189025

Please sign in to comment.