Annotation: Add clean up job for old annotations (#26156)

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Carl Bergquist
2020-09-02 08:07:31 +02:00
committed by GitHub
parent 0bc67b032a
commit 20747015f6
10 changed files with 452 additions and 1 deletions

View File

@ -1,6 +1,11 @@
package annotations
import "github.com/grafana/grafana/pkg/components/simplejson"
import (
"context"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/setting"
)
type Repository interface {
Save(item *Item) error
@ -9,6 +14,11 @@ type Repository interface {
Delete(params *DeleteParams) error
}
// AnnotationCleaner is responsible for cleaning up old annotations
type AnnotationCleaner interface {
CleanAnnotations(ctx context.Context, cfg *setting.Cfg) error
}
type ItemQuery struct {
OrgId int64 `json:"orgId"`
From int64 `json:"from"`
@ -43,6 +53,15 @@ type DeleteParams struct {
}
var repositoryInstance Repository
var cleanerInstance AnnotationCleaner
func GetAnnotationCleaner() AnnotationCleaner {
return cleanerInstance
}
func SetAnnotationCleaner(rep AnnotationCleaner) {
cleanerInstance = rep
}
func GetRepository() Repository {
return repositoryInstance
@ -74,6 +93,10 @@ type Item struct {
Title string
}
func (i Item) TableName() string {
return "annotation"
}
type ItemDTO struct {
Id int64 `json:"id"`
AlertId int64 `json:"alertId"`