@ -78,14 +78,15 @@ func TestIntegrationAnnotations(t *testing.T) {
var err error
var err error
annotation := & annotations . Item {
annotation := & annotations . Item {
OrgID : 1 ,
OrgID : 1 ,
UserID : 1 ,
UserID : 1 ,
DashboardID : dashboard . ID ,
DashboardID : dashboard . ID , // nolint: staticcheck
Text : "hello" ,
DashboardUID : dashboard . UID ,
Type : "alert" ,
Text : "hello" ,
Epoch : 10 ,
Type : "alert" ,
Tags : [ ] string { "outage" , "error" , "type:outage" , "server:server-1" } ,
Epoch : 10 ,
Data : simplejson . NewFromAny ( map [ string ] any { "data1" : "I am a cool data" , "data2" : "I am another cool data" } ) ,
Tags : [ ] string { "outage" , "error" , "type:outage" , "server:server-1" } ,
Data : simplejson . NewFromAny ( map [ string ] any { "data1" : "I am a cool data" , "data2" : "I am another cool data" } ) ,
}
}
err = store . Add ( context . Background ( ) , annotation )
err = store . Add ( context . Background ( ) , annotation )
require . NoError ( t , err )
require . NoError ( t , err )
@ -93,14 +94,15 @@ func TestIntegrationAnnotations(t *testing.T) {
assert . Equal ( t , annotation . Epoch , annotation . EpochEnd )
assert . Equal ( t , annotation . Epoch , annotation . EpochEnd )
annotation2 := & annotations . Item {
annotation2 := & annotations . Item {
OrgID : 1 ,
OrgID : 1 ,
UserID : 1 ,
UserID : 1 ,
DashboardID : dashboard2 . ID ,
DashboardID : dashboard2 . ID , // nolint: staticcheck
Text : "hello" ,
DashboardUID : dashboard2 . UID ,
Type : "alert" ,
Text : "hello" ,
Epoch : 21 , // Should swap epoch & epochEnd
Type : "alert" ,
EpochEnd : 20 ,
Epoch : 21 , // Should swap epoch & epochEnd
Tags : [ ] string { "outage" , "type:outage" , "server:server-1" , "error" } ,
EpochEnd : 20 ,
Tags : [ ] string { "outage" , "type:outage" , "server:server-1" , "error" } ,
}
}
err = store . Add ( context . Background ( ) , annotation2 )
err = store . Add ( context . Background ( ) , annotation2 )
require . NoError ( t , err )
require . NoError ( t , err )
@ -135,7 +137,31 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can query for annotation by dashboard id" , func ( t * testing . T ) {
t . Run ( "Can query for annotation by dashboard id" , func ( t * testing . T ) {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : dashboard . ID ,
DashboardID : dashboard . ID , // nolint: staticcheck
From : 0 ,
To : 15 ,
SignedInUser : testUser ,
} , & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 {
dashboard . UID : dashboard . ID ,
} ,
CanAccessDashAnnotations : true ,
} )
require . NoError ( t , err )
assert . Len ( t , items , 1 )
assert . Equal ( t , [ ] string { "outage" , "error" , "type:outage" , "server:server-1" } , items [ 0 ] . Tags )
assert . GreaterOrEqual ( t , items [ 0 ] . Created , int64 ( 0 ) )
assert . GreaterOrEqual ( t , items [ 0 ] . Updated , int64 ( 0 ) )
assert . Equal ( t , items [ 0 ] . Updated , items [ 0 ] . Created )
} )
t . Run ( "Can query for annotation by dashboard uid" , func ( t * testing . T ) {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
@ -234,12 +260,13 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Should not find any when item is outside time range" , func ( t * testing . T ) {
t . Run ( "Should not find any when item is outside time range" , func ( t * testing . T ) {
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 12 ,
From : 12 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
@ -250,12 +277,13 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Should not find one when tag filter does not match" , func ( t * testing . T ) {
t . Run ( "Should not find one when tag filter does not match" , func ( t * testing . T ) {
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 1 ,
From : 1 ,
To : 15 ,
To : 15 ,
Tags : [ ] string { "asd" } ,
Tags : [ ] string { "asd" } ,
@ -267,12 +295,13 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Should not find one when type filter does not match" , func ( t * testing . T ) {
t . Run ( "Should not find one when type filter does not match" , func ( t * testing . T ) {
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 1 ,
From : 1 ,
To : 15 ,
To : 15 ,
Type : "alert" ,
Type : "alert" ,
@ -284,12 +313,13 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Should find one when all tag filters does match" , func ( t * testing . T ) {
t . Run ( "Should find one when all tag filters does match" , func ( t * testing . T ) {
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 1 ,
From : 1 ,
To : 15 , // this will exclude the second test annotation
To : 15 , // this will exclude the second test annotation
Tags : [ ] string { "outage" , "error" } ,
Tags : [ ] string { "outage" , "error" } ,
@ -315,12 +345,13 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Should find one when all key value tag filters does match" , func ( t * testing . T ) {
t . Run ( "Should find one when all key value tag filters does match" , func ( t * testing . T ) {
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
items , err := store . Get ( context . Background ( ) , annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 1 ,
From : 1 ,
To : 15 ,
To : 15 ,
Tags : [ ] string { "type:outage" , "server:server-1" } ,
Tags : [ ] string { "type:outage" , "server:server-1" } ,
@ -333,13 +364,14 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can update annotation and remove all tags" , func ( t * testing . T ) {
t . Run ( "Can update annotation and remove all tags" , func ( t * testing . T ) {
query := annotations . ItemQuery {
query := annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
}
}
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
@ -368,13 +400,14 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can update annotation with new tags" , func ( t * testing . T ) {
t . Run ( "Can update annotation with new tags" , func ( t * testing . T ) {
query := annotations . ItemQuery {
query := annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
}
}
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
@ -401,13 +434,14 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can update annotation with additional tags" , func ( t * testing . T ) {
t . Run ( "Can update annotation with additional tags" , func ( t * testing . T ) {
query := annotations . ItemQuery {
query := annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
}
}
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
@ -434,13 +468,14 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can update annotations with data" , func ( t * testing . T ) {
t . Run ( "Can update annotations with data" , func ( t * testing . T ) {
query := annotations . ItemQuery {
query := annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
}
}
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
@ -470,13 +505,14 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can delete annotation" , func ( t * testing . T ) {
t . Run ( "Can delete annotation" , func ( t * testing . T ) {
query := annotations . ItemQuery {
query := annotations . ItemQuery {
OrgID : 1 ,
OrgID : 1 ,
DashboardID : 1 ,
DashboardID : 1 , // nolint: staticcheck
DashboardUID : dashboard . UID ,
From : 0 ,
From : 0 ,
To : 15 ,
To : 15 ,
SignedInUser : testUser ,
SignedInUser : testUser ,
}
}
accRes := & annotation_ac . AccessResources {
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 { "foo" : 1 } ,
Dashboards : map [ string ] int64 { dashboard . UID : 1 } ,
CanAccessDashAnnotations : true ,
CanAccessDashAnnotations : true ,
}
}
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
@ -493,14 +529,53 @@ func TestIntegrationAnnotations(t *testing.T) {
t . Run ( "Can delete annotation using dashboard id and panel id" , func ( t * testing . T ) {
t . Run ( "Can delete annotation using dashboard id and panel id" , func ( t * testing . T ) {
annotation3 := & annotations . Item {
annotation3 := & annotations . Item {
OrgID : 1 ,
OrgID : 1 ,
UserID : 1 ,
UserID : 1 ,
DashboardID : dashboard2 . ID ,
DashboardID : dashboard2 . ID , // nolint: staticcheck
Text : "toBeDeletedWithPanelId" ,
DashboardUID : dashboard2 . UID ,
Type : "alert" ,
Text : "toBeDeletedWithPanelId" ,
Epoch : 11 ,
Type : "alert" ,
Tags : [ ] string { "test" } ,
Epoch : 11 ,
PanelID : 20 ,
Tags : [ ] string { "test" } ,
PanelID : 20 ,
}
err = store . Add ( context . Background ( ) , annotation3 )
require . NoError ( t , err )
accRes := & annotation_ac . AccessResources {
Dashboards : map [ string ] int64 {
dashboard2 . UID : dashboard2 . ID ,
} ,
CanAccessDashAnnotations : true ,
}
query := annotations . ItemQuery {
OrgID : 1 ,
AnnotationID : annotation3 . ID ,
SignedInUser : testUser ,
}
items , err := store . Get ( context . Background ( ) , query , accRes )
require . NoError ( t , err )
// nolint:staticcheck
err = store . Delete ( context . Background ( ) , & annotations . DeleteParams { DashboardID : items [ 0 ] . DashboardID , PanelID : items [ 0 ] . PanelID , OrgID : 1 } )
require . NoError ( t , err )
items , err = store . Get ( context . Background ( ) , query , accRes )
require . NoError ( t , err )
assert . Empty ( t , items )
} )
t . Run ( "Can delete annotation using dashboard uid and panel id" , func ( t * testing . T ) {
annotation3 := & annotations . Item {
OrgID : 1 ,
UserID : 1 ,
DashboardUID : dashboard2 . UID ,
Text : "toBeDeletedWithPanelId" ,
Type : "alert" ,
Epoch : 11 ,
Tags : [ ] string { "test" } ,
PanelID : 20 ,
}
}
err = store . Add ( context . Background ( ) , annotation3 )
err = store . Add ( context . Background ( ) , annotation3 )
require . NoError ( t , err )
require . NoError ( t , err )
@ -520,9 +595,8 @@ func TestIntegrationAnnotations(t *testing.T) {
items , err := store . Get ( context . Background ( ) , query , accRes )
items , err := store . Get ( context . Background ( ) , query , accRes )
require . NoError ( t , err )
require . NoError ( t , err )
dashboardId := items [ 0 ] . DashboardID
// nolint:staticcheck
panelId := items [ 0 ] . PanelID
err = store . Delete ( context . Background ( ) , & annotations . DeleteParams { DashboardUID : * items [ 0 ] . DashboardUID , PanelID : items [ 0 ] . PanelID , OrgID : 1 } )
err = store . Delete ( context . Background ( ) , & annotations . DeleteParams { DashboardID : dashboardId , PanelID : panelId , OrgID : 1 } )
require . NoError ( t , err )
require . NoError ( t , err )
items , err = store . Get ( context . Background ( ) , query , accRes )
items , err = store . Get ( context . Background ( ) , query , accRes )
@ -635,15 +709,16 @@ func benchmarkFindTags(b *testing.B, numAnnotations int) {
require . NoError ( b , err )
require . NoError ( b , err )
annotationWithTheTag := annotations . Item {
annotationWithTheTag := annotations . Item {
ID : int64 ( numAnnotations ) + 1 ,
ID : int64 ( numAnnotations ) + 1 ,
OrgID : 1 ,
OrgID : 1 ,
UserID : 1 ,
UserID : 1 ,
DashboardID : int64 ( 1 ) ,
DashboardID : 1 , // nolint: staticcheck
Text : "hello" ,
DashboardUID : "uid" ,
Type : "alert" ,
Text : "hello" ,
Epoch : 10 ,
Type : "alert" ,
Tags : [ ] string { "outage" , "error" , "type:outage" , "server:server-1" } ,
Epoch : 10 ,
Data : simplejson . NewFromAny ( map [ string ] any { "data1" : "I am a cool data" , "data2" : "I am another cool data" } ) ,
Tags : [ ] string { "outage" , "error" , "type:outage" , "server:server-1" } ,
Data : simplejson . NewFromAny ( map [ string ] any { "data1" : "I am a cool data" , "data2" : "I am another cool data" } ) ,
}
}
err = store . Add ( context . Background ( ) , & annotationWithTheTag )
err = store . Add ( context . Background ( ) , & annotationWithTheTag )
require . NoError ( b , err )
require . NoError ( b , err )