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

Annotations: Clean up old annotations job #20815

Closed
wants to merge 18 commits into from

Conversation

malish8632
Copy link

What this PR does / why we need it:
This adds automatic clean up job to remove expired annotations and fixes existing issue #8224
Current number of days back to clean annotations is set to 60 and could be updated in defaults.ini settings.
This PR is not distinguishing between types of annotations. Any alerts or user created annotations treated the same.
This PR is also increasing the size of annotation.tags field as we encountered issues with VARCHAR(500) as a limit on our instance.

Which issue(s) this PR fixes:

Fixes #8224

Special notes for your reviewer:

@marefr marefr added area/backend pr/external This PR is from external contributor labels Dec 4, 2019
@malish8632
Copy link
Author

Hej @marefr any feedback here?

@aknuds1 aknuds1 self-assigned this Jan 29, 2020
@aknuds1 aknuds1 self-requested a review January 29, 2020 14:07
@aknuds1 aknuds1 added this to Under review in Backend Platform Squad Jan 29, 2020
@aknuds1
Copy link
Contributor

aknuds1 commented Jan 29, 2020

Thanks for the PR, I will have a look at it.

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.

After my revisions to this PR, it looks good to me. I need input from others on the team though.

conf/defaults.ini Outdated Show resolved Hide resolved
conf/sample.ini Outdated Show resolved Hide resolved
pkg/models/annotations.go Outdated Show resolved Hide resolved
pkg/services/cleanup/cleanup.go Outdated Show resolved Hide resolved
pkg/services/cleanup/cleanup.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/annotations_cleanup.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/annotations_cleanup.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/annotations_cleanup.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/annotations_cleanup.go Outdated Show resolved Hide resolved
pkg/services/sqlstore/annotations_cleanup.go Outdated Show resolved Hide resolved
@aknuds1 aknuds1 requested a review from a team February 6, 2020 12:50
// read dashboard settings
annotations := iniFile.Section("annotations")
DaysToKeepAnnotations = annotations.Key("days_to_keep").MustInt(60)
if DaysToKeepAnnotations < 5 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts about this? Why not below 5? :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm actually unsure about this too @bergquist - 5 was the minimum before my revising the PR.


[annotations]
# Number of days to keep annotations (per alert). Default: 60, Minimum: 5
days_to_keep = 60
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm torn about having this on by default.

Copy link
Contributor

@aknuds1 aknuds1 Feb 6, 2020

Choose a reason for hiding this comment

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

@bergquist I guess it should be turned off by default?

Copy link
Member

Choose a reason for hiding this comment

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

I agree! At least now when it operates on all kinds of annotations. Maybe cleanup of alert annotations enabled per default would have made sense if it was the default from the beginning when alerting was introduced, but now it's sort of a breaking change so think we have to have it disabled per default.

#################################### Annotations ##################

[annotations]
# Number of days to keep annotations (per alert). Default: 60, Minimum: 5
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment says per alert but the SQL statement deletes all kinds of annotations. I think we should be clear about this and perhaps have different settings per kind of annotation.

Copy link
Contributor

Choose a reason for hiding this comment

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

@bergquist Thanks for clarifying that 👍

Copy link
Member

@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.

Some smaller things, see comments. In addition, configuration documentation needs to be updated as well.

@@ -145,6 +145,11 @@ func addAnnotationMig(mg *Migrator) {
mg.AddMigration("Remove index org_id_epoch_epoch_end from annotation table", NewDropIndexMigration(table, &Index{
Cols: []string{"org_id", "epoch", "epoch_end"}, Type: IndexType,
}))

// Increase size of tags field in annotation table
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest moving this change to a separate PR with a referenced issue (existing or new one). Easier to keep each change separate and in case this would cause problem it's easier to revert only this instead of every change in this PR.

Copy link
Author

Choose a reason for hiding this comment

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

Removing

daysToKeepAnnotations := 5
repo := SqlAnnotationRepo{}

Convey("Deletion of expired annotations", t, func() {
Copy link
Member

Choose a reason for hiding this comment

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

New tests should use standard library for testing, see backend styleguide.

Copy link
Contributor

Choose a reason for hiding this comment

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

@malish8632 Can you rewrite the new tests with the standard library as @marefr requests?

Copy link
Author

Choose a reason for hiding this comment

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

hi @aknuds1 I'm going to take a stab at this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @malish8632!

Copy link
Author

Choose a reason for hiding this comment

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

@aknuds1 @marefr updated to use standard library


[annotations]
# Number of days to keep annotations (per alert). Default: 60, Minimum: 5
days_to_keep = 60
Copy link
Member

Choose a reason for hiding this comment

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

I agree! At least now when it operates on all kinds of annotations. Maybe cleanup of alert annotations enabled per default would have made sense if it was the default from the beginning when alerting was introduced, but now it's sort of a breaking change so think we have to have it disabled per default.

return nil
}

query = fmt.Sprintf("DELETE FROM annotation_tag WHERE annotation_id IN (?%s)", strings.Repeat(",?",
Copy link
Member

Choose a reason for hiding this comment

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

Are we comfortable/sure this will not lock the table and interfere with alerting?

Copy link
Author

Choose a reason for hiding this comment

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

This was build with approach identical to how cleaning of dashboard_version table is done, which is currently the biggest in our internal system. Cleaning annotations is never being an issue for our MySQL server.

bus.AddHandler("sql", deleteExpiredAnnotations)
}

const MAX_EXPIRED_ANNOTATIONS_TO_DELETE = 900
Copy link
Member

Choose a reason for hiding this comment

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

Why 900?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm also unsure about that @marefr. Maybe we should derive a sensible number?

Copy link
Author

Choose a reason for hiding this comment

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

Initially tried 1000 but due to unit tests failures changed to 900

@malish8632
Copy link
Author

@aknuds1 For some reason grafana-docker-ubuntu-pr is failing... any pointers?

@aknuds1
Copy link
Contributor

aknuds1 commented Feb 21, 2020 via email

Sergey Rustamov and others added 15 commits February 21, 2020 15:12
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
aknuds1 and others added 3 commits February 21, 2020 15:13
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@CLAassistant
Copy link

CLA assistant check
All committers have signed the CLA.

@malish8632
Copy link
Author

@aknuds1 Is there anything else you guys expecting from me? Thanks

@aknuds1 aknuds1 requested review from bergquist and marefr March 9, 2020 16:09
@aknuds1
Copy link
Contributor

aknuds1 commented Mar 9, 2020

@malish8632 I requested new reviews from @bergquist and @marefr, let's see what they say. You also need to fix conflicts :)

const MAX_EXPIRED_ANNOTATIONS_TO_DELETE = 900

func deleteExpiredAnnotations(cmd *m.DeleteExpiredAnnotationsCommand) error {
return inTransaction(func(sess *DBSession) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Return this as inTransaction performs all these SQL operations in one transaction. I dont think that's necessary. You can use withDbSession instead to avoid transactions.

@stale
Copy link

stale bot commented Apr 1, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale Issue with no recent activity label Apr 1, 2020
@tomtastic
Copy link

Looking forward to seeing this merged.

@stale stale bot removed the stale Issue with no recent activity label Apr 11, 2020
@stale
Copy link

stale bot commented Apr 25, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale Issue with no recent activity label Apr 25, 2020
@aknuds1 aknuds1 removed the stale Issue with no recent activity label May 25, 2020
@stale
Copy link

stale bot commented Jun 8, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale Issue with no recent activity label Jun 8, 2020
@aknuds1 aknuds1 removed the stale Issue with no recent activity label Jun 8, 2020
@stale
Copy link

stale bot commented Jun 22, 2020

This pull request has been automatically marked as stale because it has not had activity in the last 2 weeks. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale Issue with no recent activity label Jun 22, 2020
@stale
Copy link

stale bot commented Jul 23, 2020

This pull request has been automatically closed because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this Jul 23, 2020
Backend Platform Squad automation moved this from Under review to Done Jul 23, 2020
@tomtastic
Copy link

Wow, stale bots suck.

@marefr
Copy link
Member

marefr commented Aug 20, 2020

@tomtastic We've opened a new PR based on discussions in related issue

@marefr marefr removed this from Done in Backend Platform Squad Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/annotations area/backend pr/external This PR is from external contributor stale Issue with no recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up job for old annotations.
6 participants