2016-08-01 03:07:00 -05:00
|
|
|
package annotations
|
|
|
|
|
2020-09-02 01:07:31 -05:00
|
|
|
import (
|
|
|
|
"context"
|
2021-03-29 08:47:16 -05:00
|
|
|
"errors"
|
2020-09-02 01:07:31 -05:00
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
"github.com/grafana/grafana/pkg/setting"
|
|
|
|
)
|
2016-08-01 03:07:00 -05:00
|
|
|
|
2021-03-29 08:47:16 -05:00
|
|
|
var (
|
|
|
|
ErrTimerangeMissing = errors.New("missing timerange")
|
|
|
|
)
|
|
|
|
|
2016-08-01 03:07:00 -05:00
|
|
|
type Repository interface {
|
|
|
|
Save(item *Item) error
|
2017-04-12 09:26:34 -05:00
|
|
|
Update(item *Item) error
|
2017-10-07 03:31:39 -05:00
|
|
|
Find(query *ItemQuery) ([]*ItemDTO, error)
|
2016-10-14 02:33:16 -05:00
|
|
|
Delete(params *DeleteParams) error
|
2021-06-30 06:42:54 -05:00
|
|
|
FindTags(query *TagsQuery) (FindTagsResult, error)
|
2016-08-30 02:32:56 -05:00
|
|
|
}
|
|
|
|
|
2020-09-02 01:07:31 -05:00
|
|
|
// AnnotationCleaner is responsible for cleaning up old annotations
|
|
|
|
type AnnotationCleaner interface {
|
2020-12-08 12:41:35 -06:00
|
|
|
CleanAnnotations(ctx context.Context, cfg *setting.Cfg) (int64, int64, error)
|
2020-09-02 01:07:31 -05:00
|
|
|
}
|
|
|
|
|
2016-08-30 02:32:56 -05:00
|
|
|
type ItemQuery struct {
|
2017-12-20 17:52:21 -06:00
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
From int64 `json:"from"`
|
|
|
|
To int64 `json:"to"`
|
2018-03-22 09:52:09 -05:00
|
|
|
UserId int64 `json:"userId"`
|
2017-12-20 17:52:21 -06:00
|
|
|
AlertId int64 `json:"alertId"`
|
|
|
|
DashboardId int64 `json:"dashboardId"`
|
|
|
|
PanelId int64 `json:"panelId"`
|
|
|
|
AnnotationId int64 `json:"annotationId"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Type string `json:"type"`
|
2018-09-13 08:15:42 -05:00
|
|
|
MatchAny bool `json:"matchAny"`
|
2016-08-30 02:32:56 -05:00
|
|
|
|
2017-02-15 07:15:42 -06:00
|
|
|
Limit int64 `json:"limit"`
|
2016-08-01 03:07:00 -05:00
|
|
|
}
|
|
|
|
|
2021-07-01 03:23:33 -05:00
|
|
|
// TagsQuery is the query for a tags search.
|
2021-06-30 06:42:54 -05:00
|
|
|
type TagsQuery struct {
|
|
|
|
OrgID int64 `json:"orgId"`
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
|
|
|
|
Limit int64 `json:"limit"`
|
|
|
|
}
|
|
|
|
|
2021-07-01 03:23:33 -05:00
|
|
|
// Tag is the DB result of a tags search.
|
|
|
|
type Tag struct {
|
2021-06-30 06:42:54 -05:00
|
|
|
Key string
|
|
|
|
Value string
|
|
|
|
Count int64
|
|
|
|
}
|
|
|
|
|
2021-07-01 03:23:33 -05:00
|
|
|
// TagsDTO is the frontend DTO for Tag.
|
2021-06-30 06:42:54 -05:00
|
|
|
type TagsDTO struct {
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
Count int64 `json:"count"`
|
|
|
|
}
|
|
|
|
|
2021-07-01 03:23:33 -05:00
|
|
|
// FindTagsResult is the result of a tags search.
|
2021-06-30 06:42:54 -05:00
|
|
|
type FindTagsResult struct {
|
|
|
|
Tags []*TagsDTO `json:"tags"`
|
|
|
|
}
|
|
|
|
|
2021-07-01 03:23:33 -05:00
|
|
|
// GetAnnotationTagsResponse is a response struct for FindTagsResult.
|
|
|
|
type GetAnnotationTagsResponse struct {
|
|
|
|
Result FindTagsResult `json:"result"`
|
|
|
|
}
|
|
|
|
|
2016-10-14 02:33:16 -05:00
|
|
|
type DeleteParams struct {
|
2018-06-25 09:02:34 -05:00
|
|
|
OrgId int64
|
|
|
|
Id int64
|
|
|
|
AlertId int64
|
|
|
|
DashboardId int64
|
|
|
|
PanelId int64
|
2016-10-14 02:33:16 -05:00
|
|
|
}
|
|
|
|
|
2016-08-01 03:07:00 -05:00
|
|
|
var repositoryInstance Repository
|
2020-09-02 01:07:31 -05:00
|
|
|
var cleanerInstance AnnotationCleaner
|
|
|
|
|
|
|
|
func GetAnnotationCleaner() AnnotationCleaner {
|
|
|
|
return cleanerInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetAnnotationCleaner(rep AnnotationCleaner) {
|
|
|
|
cleanerInstance = rep
|
|
|
|
}
|
2016-08-01 03:07:00 -05:00
|
|
|
|
|
|
|
func GetRepository() Repository {
|
|
|
|
return repositoryInstance
|
|
|
|
}
|
|
|
|
|
|
|
|
func SetRepository(rep Repository) {
|
|
|
|
repositoryInstance = rep
|
|
|
|
}
|
|
|
|
|
|
|
|
type Item struct {
|
2017-10-07 03:31:39 -05:00
|
|
|
Id int64 `json:"id"`
|
|
|
|
OrgId int64 `json:"orgId"`
|
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
DashboardId int64 `json:"dashboardId"`
|
|
|
|
PanelId int64 `json:"panelId"`
|
|
|
|
Text string `json:"text"`
|
|
|
|
AlertId int64 `json:"alertId"`
|
|
|
|
PrevState string `json:"prevState"`
|
|
|
|
NewState string `json:"newState"`
|
|
|
|
Epoch int64 `json:"epoch"`
|
2019-08-16 03:49:30 -05:00
|
|
|
EpochEnd int64 `json:"epochEnd"`
|
2018-03-21 20:22:58 -05:00
|
|
|
Created int64 `json:"created"`
|
2018-03-22 09:52:09 -05:00
|
|
|
Updated int64 `json:"updated"`
|
2017-10-07 03:31:39 -05:00
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Data *simplejson.Json `json:"data"`
|
|
|
|
|
|
|
|
// needed until we remove it from db
|
|
|
|
Type string
|
|
|
|
Title string
|
|
|
|
}
|
2016-08-01 03:07:00 -05:00
|
|
|
|
2020-09-02 01:07:31 -05:00
|
|
|
func (i Item) TableName() string {
|
|
|
|
return "annotation"
|
|
|
|
}
|
|
|
|
|
2017-10-07 03:31:39 -05:00
|
|
|
type ItemDTO struct {
|
|
|
|
Id int64 `json:"id"`
|
|
|
|
AlertId int64 `json:"alertId"`
|
|
|
|
AlertName string `json:"alertName"`
|
|
|
|
DashboardId int64 `json:"dashboardId"`
|
|
|
|
PanelId int64 `json:"panelId"`
|
|
|
|
UserId int64 `json:"userId"`
|
|
|
|
NewState string `json:"newState"`
|
|
|
|
PrevState string `json:"prevState"`
|
2018-03-21 20:22:58 -05:00
|
|
|
Created int64 `json:"created"`
|
2018-03-22 09:52:09 -05:00
|
|
|
Updated int64 `json:"updated"`
|
2017-10-07 03:31:39 -05:00
|
|
|
Time int64 `json:"time"`
|
2019-08-16 03:49:30 -05:00
|
|
|
TimeEnd int64 `json:"timeEnd"`
|
2017-10-07 03:31:39 -05:00
|
|
|
Text string `json:"text"`
|
|
|
|
Tags []string `json:"tags"`
|
|
|
|
Login string `json:"login"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
Data *simplejson.Json `json:"data"`
|
2016-08-01 03:07:00 -05:00
|
|
|
}
|