Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
67e5f625
Commit
67e5f625
authored
Oct 02, 2018
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move version conflict logging for mark as complete to sqlstore package
parent
9d3659d3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
19 deletions
+12
-19
pkg/services/alerting/notifier.go
+3
-14
pkg/services/sqlstore/alert_notification.go
+4
-1
pkg/services/sqlstore/alert_notification_test.go
+5
-4
No files found.
pkg/services/alerting/notifier.go
View file @
67e5f625
...
...
@@ -3,7 +3,6 @@ package alerting
import
(
"errors"
"fmt"
"time"
"github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/components/imguploader"
...
...
@@ -60,15 +59,14 @@ func (n *notificationService) SendIfNeeded(context *EvalContext) error {
func
(
n
*
notificationService
)
sendAndMarkAsComplete
(
evalContext
*
EvalContext
,
notifierState
*
notifierState
)
error
{
notifier
:=
notifierState
.
notifier
n
.
log
.
Debug
(
"Sending notification"
,
"type"
,
notifier
.
GetType
(),
"id"
,
notifier
.
GetNotifierId
(),
"isDefault"
,
notifier
.
GetIsDefault
())
metrics
.
M_Alerting_Notification_Sent
.
WithLabelValues
(
notifier
.
GetType
())
.
Inc
()
err
:=
notifier
.
Notify
(
evalContext
)
if
err
!=
nil
{
n
.
log
.
Error
(
"failed to send notification"
,
"id"
,
notifier
.
GetNotifierId
())
}
else
{
notifierState
.
state
.
UpdatedAt
=
time
.
Now
()
.
UTC
()
.
Unix
()
n
.
log
.
Error
(
"failed to send notification"
,
"id"
,
notifier
.
GetNotifierId
(),
"error"
,
err
)
}
if
evalContext
.
IsTestRun
{
...
...
@@ -80,16 +78,7 @@ func (n *notificationService) sendAndMarkAsComplete(evalContext *EvalContext, no
Version
:
notifierState
.
state
.
Version
,
}
if
err
=
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
);
err
!=
nil
{
if
err
==
m
.
ErrAlertNotificationStateVersionConflict
{
n
.
log
.
Error
(
"notification state out of sync"
,
"id"
,
notifier
.
GetNotifierId
())
return
nil
}
return
err
}
return
nil
return
bus
.
DispatchCtx
(
evalContext
.
Ctx
,
cmd
)
}
func
(
n
*
notificationService
)
sendNotification
(
evalContext
*
EvalContext
,
notifierState
*
notifierState
)
error
{
...
...
pkg/services/sqlstore/alert_notification.go
View file @
67e5f625
...
...
@@ -259,7 +259,10 @@ func SetAlertNotificationStateToCompleteCommand(ctx context.Context, cmd *m.SetA
}
if
current
.
Version
!=
version
{
return
m
.
ErrAlertNotificationStateVersionConflict
sqlog
.
Error
(
`notification state out of sync. the notification
is marked as complete but has been modified between
set as pending and completion.`
,
"notifierId"
,
current
.
NotifierId
)
}
return
nil
...
...
pkg/services/sqlstore/alert_notification_test.go
View file @
67e5f625
...
...
@@ -77,19 +77,20 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
So
(
query3
.
Result
.
UpdatedAt
,
ShouldEqual
,
now
.
Unix
())
})
Convey
(
"Update existing state to completed should update database
, but return version mismatch
"
,
func
()
{
Convey
(
"Update existing state to completed should update database
. regardless of version
"
,
func
()
{
s
:=
*
query
.
Result
unknownVersion
:=
int64
(
1000
)
cmd
:=
models
.
SetAlertNotificationStateToCompleteCommand
{
Id
:
s
.
Id
,
Version
:
1000
,
Version
:
unknownVersion
,
}
err
:=
SetAlertNotificationStateToCompleteCommand
(
context
.
Background
(),
&
cmd
)
So
(
err
,
Should
Equal
,
models
.
ErrAlertNotificationStateVersionConflict
)
So
(
err
,
Should
BeNil
)
query3
:=
&
models
.
GetOrCreateNotificationStateQuery
{
AlertId
:
alertID
,
OrgId
:
orgID
,
NotifierId
:
notifierID
}
err
=
GetOrCreateAlertNotificationState
(
context
.
Background
(),
query3
)
So
(
err
,
ShouldBeNil
)
So
(
query3
.
Result
.
Version
,
ShouldEqual
,
100
1
)
So
(
query3
.
Result
.
Version
,
ShouldEqual
,
unknownVersion
+
1
)
So
(
query3
.
Result
.
State
,
ShouldEqual
,
models
.
AlertNotificationStateCompleted
)
So
(
query3
.
Result
.
UpdatedAt
,
ShouldEqual
,
now
.
Unix
())
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment