Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alerting: Prevent cleanup of non-empty folders on migration revert #76439

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

JacobsonMT
Copy link
Member

@JacobsonMT JacobsonMT commented Oct 12, 2023

What is this feature?

Currently, when the migration reverts, it cleans up folders created during the previous migration. If, between when the migration was run and revert, other resources were added to the automatically created folders, the revert will delete these descendants as well.

For example, if a dashboard is added to the folder, the dashboard will also be deleted.

This PR will verify that the folder is empty before deleting it. If it is not empty, a warning will be logged and the delete will be skipped.

Who is this feature for?

Users migrating from Legacy Alerting to Grafana Alerting.

Special notes for your reviewer:

When we attempt the create a folder during the migration, we can no longer fail if the folder already exists. As this possibility will become much more common now. Instead, we will log an informational message and use the existing folder.

This is not a perfect solution, as these existing folders could have different permissions that what would have otherwise been created by the migration. However, the risk of conflict is low because of the strict naming scheme for created folders.

Depends on: #74504

Please check that:

  • It works as expected from a user's perspective.
  • If this is a pre-GA feature, it is behind a feature toggle.
  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

@JacobsonMT JacobsonMT added area/alerting Grafana Alerting add to changelog no-backport Skip backport of PR labels Oct 12, 2023
@JacobsonMT JacobsonMT added this to the 10.2.x milestone Oct 12, 2023
@JacobsonMT JacobsonMT changed the base branch from main to jacobsonmt/migration_fix_permissions October 12, 2023 12:22
@JacobsonMT JacobsonMT marked this pull request as ready for review October 12, 2023 12:23
@JacobsonMT JacobsonMT requested review from a team, rwwiv, yuri-tceretian and grobinson-grafana and removed request for a team October 12, 2023 12:23
@JacobsonMT JacobsonMT force-pushed the jacobsonmt/migration_fix_permissions branch from e56e6e7 to dc6b396 Compare October 12, 2023 13:05
@JacobsonMT JacobsonMT force-pushed the jacobsonmt/migration_nonempty_folder branch from 9cc2691 to 2e86691 Compare October 12, 2023 13:07
Copy link
Contributor

@yuri-tceretian yuri-tceretian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I agree that it's ok to reuse the folder with the same title because it was created during the the previous migration

var descendantCounts []string
var cntErr error
for kind, cnt := range count {
if cnt > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe revert?

errs = errors.Join(errs, fmt.Errorf("folder %s: %w", folderUID, err))
continue
}
var descendantCounts []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be pre-allocated

Base automatically changed from jacobsonmt/migration_fix_permissions to main October 12, 2023 22:12
@JacobsonMT JacobsonMT force-pushed the jacobsonmt/migration_nonempty_folder branch from 2e86691 to 56b4ba6 Compare October 12, 2023 22:19
@JacobsonMT JacobsonMT changed the title Alerting: Prevent cleanup of non-empty folders on revert Alerting: Prevent cleanup of non-empty folders on migration revert Oct 12, 2023
@JacobsonMT JacobsonMT merged commit a6d928e into main Oct 12, 2023
15 checks passed
@JacobsonMT JacobsonMT deleted the jacobsonmt/migration_nonempty_folder branch October 12, 2023 22:40
@zerok zerok modified the milestones: 10.2.x, 10.2.0 Oct 23, 2023
darrenjaneczek pushed a commit that referenced this pull request Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants