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
4ef95cfd
Commit
4ef95cfd
authored
Dec 16, 2016
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style(api): reduce code complexity
parent
1f8f3ed0
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
18 additions
and
25 deletions
+18
-25
pkg/api/alerting.go
+8
-12
pkg/api/alerting_test.go
+0
-11
pkg/services/alerting/conditions/query.go
+1
-1
pkg/services/alerting/eval_handler_test.go
+4
-0
pkg/services/alerting/interfaces.go
+1
-1
pkg/services/alerting/rule_test.go
+4
-0
No files found.
pkg/api/alerting.go
View file @
4ef95cfd
...
@@ -288,15 +288,17 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
...
@@ -288,15 +288,17 @@ func PauseAlert(c *middleware.Context, dto dtos.PauseAlertCommand) Response {
//POST /api/alerts/pause
//POST /api/alerts/pause
func
PauseAlerts
(
c
*
middleware
.
Context
,
dto
dtos
.
PauseAlertsCommand
)
Response
{
func
PauseAlerts
(
c
*
middleware
.
Context
,
dto
dtos
.
PauseAlertsCommand
)
Response
{
updateCmd
:=
models
.
PauseAlertCommand
{
OrgId
:
c
.
OrgId
,
Paused
:
dto
.
Paused
,
}
if
len
(
dto
.
DataSourceIds
)
>
0
{
alertIdsToUpdate
,
err
:=
getAlertIdsToUpdate
(
dto
)
alertIdsToUpdate
,
err
:=
getAlertIdsToUpdate
(
dto
)
if
err
!=
nil
{
if
err
!=
nil
{
return
ApiError
(
500
,
"Failed to pause alerts"
,
err
)
return
ApiError
(
500
,
"Failed to pause alerts"
,
err
)
}
}
updateCmd
.
AlertIds
=
alertIdsToUpdate
updateCmd
:=
models
.
PauseAlertCommand
{
OrgId
:
c
.
OrgId
,
AlertIds
:
alertIdsToUpdate
,
Paused
:
dto
.
Paused
,
}
}
if
err
:=
bus
.
Dispatch
(
&
updateCmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
&
updateCmd
);
err
!=
nil
{
...
@@ -326,20 +328,14 @@ func getAlertIdsToUpdate(pauseAlertCmd dtos.PauseAlertsCommand) ([]int64, error)
...
@@ -326,20 +328,14 @@ func getAlertIdsToUpdate(pauseAlertCmd dtos.PauseAlertsCommand) ([]int64, error)
}
}
var
alertIdsToUpdate
[]
int64
var
alertIdsToUpdate
[]
int64
updateAllAlerts
:=
len
(
pauseAlertCmd
.
DataSourceIds
)
==
0
for
_
,
alert
:=
range
cmd
.
Result
{
for
_
,
alert
:=
range
cmd
.
Result
{
if
updateAllAlerts
{
alertIdsToUpdate
=
append
(
alertIdsToUpdate
,
alert
.
Id
)
continue
}
alert
,
err
:=
alerting
.
NewRuleFromDBAlert
(
alert
)
alert
,
err
:=
alerting
.
NewRuleFromDBAlert
(
alert
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
for
_
,
condition
:=
range
alert
.
Conditions
{
for
_
,
condition
:=
range
alert
.
Conditions
{
id
,
exist
:=
condition
.
GetDatsourceId
()
id
,
exist
:=
condition
.
GetDat
a
sourceId
()
if
exist
&&
existInSlice
(
pauseAlertCmd
.
DataSourceIds
,
*
id
)
{
if
exist
&&
existInSlice
(
pauseAlertCmd
.
DataSourceIds
,
*
id
)
{
alertIdsToUpdate
=
append
(
alertIdsToUpdate
,
alert
.
Id
)
alertIdsToUpdate
=
append
(
alertIdsToUpdate
,
alert
.
Id
)
}
}
...
...
pkg/api/alerting_test.go
deleted
100644 → 0
View file @
1f8f3ed0
package
api
import
(
"testing"
.
"github.com/smartystreets/goconvey/convey"
)
func
TestAlertingApi
(
t
*
testing
.
T
)
{
Convey
(
""
,
func
()
{})
}
pkg/services/alerting/conditions/query.go
View file @
4ef95cfd
...
@@ -34,7 +34,7 @@ type AlertQuery struct {
...
@@ -34,7 +34,7 @@ type AlertQuery struct {
To
string
To
string
}
}
func
(
c
*
QueryCondition
)
GetDatsourceId
()
(
datasourceId
*
int64
,
exist
bool
)
{
func
(
c
*
QueryCondition
)
GetDat
a
sourceId
()
(
datasourceId
*
int64
,
exist
bool
)
{
return
&
c
.
Query
.
DatasourceId
,
true
return
&
c
.
Query
.
DatasourceId
,
true
}
}
...
...
pkg/services/alerting/eval_handler_test.go
View file @
4ef95cfd
...
@@ -18,6 +18,10 @@ func (c *conditionStub) Eval(context *EvalContext) (*ConditionResult, error) {
...
@@ -18,6 +18,10 @@ func (c *conditionStub) Eval(context *EvalContext) (*ConditionResult, error) {
return
&
ConditionResult
{
Firing
:
c
.
firing
,
EvalMatches
:
c
.
matches
,
Operator
:
c
.
operator
,
NoDataFound
:
c
.
noData
},
nil
return
&
ConditionResult
{
Firing
:
c
.
firing
,
EvalMatches
:
c
.
matches
,
Operator
:
c
.
operator
,
NoDataFound
:
c
.
noData
},
nil
}
}
func
(
c
*
conditionStub
)
GetDatasourceId
()
(
datasourceId
*
int64
,
exist
bool
)
{
return
nil
,
false
}
func
TestAlertingExecutor
(
t
*
testing
.
T
)
{
func
TestAlertingExecutor
(
t
*
testing
.
T
)
{
Convey
(
"Test alert execution"
,
t
,
func
()
{
Convey
(
"Test alert execution"
,
t
,
func
()
{
handler
:=
NewEvalHandler
()
handler
:=
NewEvalHandler
()
...
...
pkg/services/alerting/interfaces.go
View file @
4ef95cfd
...
@@ -30,5 +30,5 @@ type ConditionResult struct {
...
@@ -30,5 +30,5 @@ type ConditionResult struct {
type
Condition
interface
{
type
Condition
interface
{
Eval
(
result
*
EvalContext
)
(
*
ConditionResult
,
error
)
Eval
(
result
*
EvalContext
)
(
*
ConditionResult
,
error
)
GetDatsourceId
()
(
datasourceId
*
int64
,
exist
bool
)
GetDat
a
sourceId
()
(
datasourceId
*
int64
,
exist
bool
)
}
}
pkg/services/alerting/rule_test.go
View file @
4ef95cfd
...
@@ -14,6 +14,10 @@ func (f *FakeCondition) Eval(context *EvalContext) (*ConditionResult, error) {
...
@@ -14,6 +14,10 @@ func (f *FakeCondition) Eval(context *EvalContext) (*ConditionResult, error) {
return
&
ConditionResult
{},
nil
return
&
ConditionResult
{},
nil
}
}
func
(
c
*
FakeCondition
)
GetDatasourceId
()
(
datasourceId
*
int64
,
exist
bool
)
{
return
nil
,
false
}
func
TestAlertRuleModel
(
t
*
testing
.
T
)
{
func
TestAlertRuleModel
(
t
*
testing
.
T
)
{
Convey
(
"Testing alert rule"
,
t
,
func
()
{
Convey
(
"Testing alert rule"
,
t
,
func
()
{
...
...
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