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

Provisioning: Remove provisioned dashboards without parental reader #26143

Merged

Conversation

nabokihms
Copy link
Contributor

Signed-off-by: m.nabokikh maksim.nabokikh@flant.com

What this PR does / why we need it:
This PR adds deletion of provisioned dashboards, which have no link with provision reader configuration (or you can say, that they are orphan).

The deletion process starts on the Grafana load and occurs on every dashboard provision configuration reloading (requesting /api/admin/provisioning/dashboards/reload endpoint).

Which issue(s) this PR fixes:
Fixes #15716

Special notes for your reviewer:
There are two problems:

  • This realization ignores providers[].disableDeletion flag, because there is no information about previous file readers' settings in the database. In my opinion, to solve this problem we need to add a column to the dashboard_provisioning table and store the information about dashboards deletion possibility in it.
  • We don't delete folders, because there is no information either folder provisioned or not.

I also wanted to mention that I tried to reuse existed code as much as possible.

@nabokihms nabokihms requested a review from a team as a code owner July 8, 2020 00:11
@nabokihms nabokihms requested review from kylebrandt and removed request for a team July 8, 2020 00:11
@nabokihms nabokihms force-pushed the delete-orphaned-provisioned-dashboards branch from bc66b95 to 26cf253 Compare July 8, 2020 05:23
@bergquist
Copy link
Contributor

Nice! :) 🎆

I won't have time to review this as I'll be on vacation for a while but I'll make sure to help someone catching up on provisioning to be able to review this.

@bergquist bergquist added this to the 7.2 milestone Jul 8, 2020
@kylebrandt kylebrandt requested review from a team, aknuds1 and marefr and removed request for a team and kylebrandt July 15, 2020 13:55
@aknuds1
Copy link
Contributor

aknuds1 commented Jul 24, 2020

Do you mind merging this with master, in order to include Drone CI configuration?

Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

Looks generally good AFAICT, but I saw some things that should be fixed.

pkg/services/provisioning/dashboards/dashboard.go Outdated Show resolved Hide resolved
pkg/services/provisioning/provisioning.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/dashboard_provisioning.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/dashboard_provisioning.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/dashboard_provisioning.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/dashboard_provisioning_test.go Outdated Show resolved Hide resolved
@nabokihms nabokihms force-pushed the delete-orphaned-provisioned-dashboards branch from edacd35 to 5953e0f Compare July 24, 2020 12:19
@nabokihms
Copy link
Contributor Author

nabokihms commented Jul 24, 2020

@aknuds1 I applied your suggestions, moved commentary, and rebased the current branch on the master. The drone pipeline passed.

@aknuds1
Copy link
Contributor

aknuds1 commented Jul 24, 2020

Thanks @nabokihms.

Copy link
Contributor

@aknuds1 aknuds1 left a comment

Choose a reason for hiding this comment

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

Looks good AFAICT, but I'll let @bergquist have his say since I'm new to the functionality.

@aknuds1 aknuds1 requested a review from bergquist September 9, 2020 09:33
@mckn mckn modified the milestones: 7.2.0-beta1, 7.2.0-beta2 Sep 9, 2020
Copy link
Contributor

@marefr marefr left a comment

Choose a reason for hiding this comment

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

Tested it and works as expected. LGTM

Copy link
Contributor

@bergquist bergquist left a comment

Choose a reason for hiding this comment

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

Very sorry for the slow response. I dropped this completely. Things have been upside down since I got back from vacation :) Any chance you could address the minor comment in this PR? Otherwise I'll do it before 7.2 stable.

Cheers for your great work!

}

for _, deleteDashCommand := range result {
err := deleteDashboard(&models.DeleteDashboardCommand{Id: deleteDashCommand.DashboardId}, sess)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great if we could move this deletion loop outside the inTransaction wrapper. This could create very large transactions without any clear upsides. I suggest we query for potential dashboards to delete without a transaction and then delete each dashboard in its own transition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it makes sense. I have changed the DeleteOrphanedProvisionedDashboards function behavior according to your suggestions. To make CI works, I also rebased the branch onto master.

@nabokihms nabokihms force-pushed the delete-orphaned-provisioned-dashboards branch from 074bb99 to 821a636 Compare September 9, 2020 20:26
nabokihms and others added 5 commits September 10, 2020 00:27
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
Signed-off-by: m.nabokikh <maksim.nabokikh@flant.com>
@nabokihms nabokihms force-pushed the delete-orphaned-provisioned-dashboards branch from 821a636 to a2cf1fa Compare September 9, 2020 20:28
Copy link
Contributor

@bergquist bergquist left a comment

Choose a reason for hiding this comment

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

LGTM!

The folder still says around in the database but that can be solved in another PR. Thank you for contributing and your patience :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing files for provisioned folders and dashboards does not delete them from Grafana's database
7 participants