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
624cd6fc
Commit
624cd6fc
authored
Jul 13, 2016
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(alerting): cleanup, removed alert changes table and code
parent
d9096110
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
5 additions
and
246 deletions
+5
-246
docker/blocks/collectd/fig
+0
-1
pkg/api/alerting.go
+0
-21
pkg/api/api.go
+1
-3
pkg/services/sqlstore/alert.go
+0
-36
pkg/services/sqlstore/alert_rule_changes.go
+0
-68
pkg/services/sqlstore/alert_rule_changes_test.go
+0
-100
pkg/services/sqlstore/migrations/alert_mig.go
+4
-17
No files found.
docker/blocks/collectd/fig
View file @
624cd6fc
...
@@ -9,4 +9,3 @@ collectd:
...
@@ -9,4 +9,3 @@ collectd:
COLLECT_INTERVAL: 10
COLLECT_INTERVAL: 10
links:
links:
- graphite
- graphite
# - memcached
pkg/api/alerting.go
View file @
624cd6fc
...
@@ -22,27 +22,6 @@ func ValidateOrgAlert(c *middleware.Context) {
...
@@ -22,27 +22,6 @@ func ValidateOrgAlert(c *middleware.Context) {
}
}
}
}
// GET /api/alerting/changes
func
GetAlertChanges
(
c
*
middleware
.
Context
)
Response
{
query
:=
models
.
GetAlertChangesQuery
{
OrgId
:
c
.
OrgId
,
}
limit
:=
c
.
QueryInt64
(
"limit"
)
if
limit
==
0
{
limit
=
50
}
query
.
Limit
=
limit
query
.
SinceId
=
c
.
QueryInt64
(
"sinceId"
)
if
err
:=
bus
.
Dispatch
(
&
query
);
err
!=
nil
{
return
ApiError
(
500
,
"List alerts failed"
,
err
)
}
return
Json
(
200
,
query
.
Result
)
}
// GET /api/alerts/rules/
// GET /api/alerts/rules/
func
GetAlerts
(
c
*
middleware
.
Context
)
Response
{
func
GetAlerts
(
c
*
middleware
.
Context
)
Response
{
query
:=
models
.
GetAlertsQuery
{
query
:=
models
.
GetAlertsQuery
{
...
...
pkg/api/api.go
View file @
624cd6fc
...
@@ -245,7 +245,7 @@ func Register(r *macaron.Macaron) {
...
@@ -245,7 +245,7 @@ func Register(r *macaron.Macaron) {
// metrics
// metrics
r
.
Get
(
"/metrics"
,
wrap
(
GetInternalMetrics
))
r
.
Get
(
"/metrics"
,
wrap
(
GetInternalMetrics
))
r
.
Group
(
"/alert
s
"
,
func
()
{
r
.
Group
(
"/alert
ing
"
,
func
()
{
r
.
Group
(
"/rules"
,
func
()
{
r
.
Group
(
"/rules"
,
func
()
{
r
.
Get
(
"/:alertId/states"
,
wrap
(
GetAlertStates
))
r
.
Get
(
"/:alertId/states"
,
wrap
(
GetAlertStates
))
//r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
//r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
...
@@ -262,8 +262,6 @@ func Register(r *macaron.Macaron) {
...
@@ -262,8 +262,6 @@ func Register(r *macaron.Macaron) {
r
.
Get
(
"/:notificationId"
,
wrap
(
GetAlertNotificationById
))
r
.
Get
(
"/:notificationId"
,
wrap
(
GetAlertNotificationById
))
r
.
Delete
(
"/:notificationId"
,
wrap
(
DeleteAlertNotification
))
r
.
Delete
(
"/:notificationId"
,
wrap
(
DeleteAlertNotification
))
},
reqOrgAdmin
)
},
reqOrgAdmin
)
//r.Get("/changes", wrap(GetAlertChanges))
})
})
// error test
// error test
...
...
pkg/services/sqlstore/alert.go
View file @
624cd6fc
...
@@ -151,17 +151,6 @@ func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
...
@@ -151,17 +151,6 @@ func DeleteAlertDefinition(dashboardId int64, sess *xorm.Session) error {
}
}
sqlog
.
Debug
(
"Alert deleted (due to dashboard deletion)"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
sqlog
.
Debug
(
"Alert deleted (due to dashboard deletion)"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
cmd
:=
&
m
.
CreateAlertChangeCommand
{
Type
:
"DELETED"
,
UpdatedBy
:
1
,
AlertId
:
alert
.
Id
,
OrgId
:
alert
.
OrgId
,
NewAlertSettings
:
alert
.
Settings
,
}
if
err
:=
SaveAlertChange
(
cmd
,
sess
);
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
...
@@ -205,13 +194,6 @@ func upsertAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Sessio
...
@@ -205,13 +194,6 @@ func upsertAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Sessio
}
}
sqlog
.
Debug
(
"Alert updated"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
sqlog
.
Debug
(
"Alert updated"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
SaveAlertChange
(
&
m
.
CreateAlertChangeCommand
{
OrgId
:
alert
.
OrgId
,
AlertId
:
alert
.
Id
,
NewAlertSettings
:
alert
.
Settings
,
UpdatedBy
:
cmd
.
UserId
,
Type
:
"UPDATED"
,
},
sess
)
}
}
}
else
{
}
else
{
...
@@ -224,13 +206,6 @@ func upsertAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Sessio
...
@@ -224,13 +206,6 @@ func upsertAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm.Sessio
}
}
sqlog
.
Debug
(
"Alert inserted"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
sqlog
.
Debug
(
"Alert inserted"
,
"name"
,
alert
.
Name
,
"id"
,
alert
.
Id
)
SaveAlertChange
(
&
m
.
CreateAlertChangeCommand
{
OrgId
:
alert
.
OrgId
,
AlertId
:
alert
.
Id
,
NewAlertSettings
:
alert
.
Settings
,
UpdatedBy
:
cmd
.
UserId
,
Type
:
"CREATED"
,
},
sess
)
}
}
}
}
...
@@ -255,17 +230,6 @@ func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm
...
@@ -255,17 +230,6 @@ func deleteMissingAlerts(alerts []*m.Alert, cmd *m.SaveAlertsCommand, sess *xorm
}
}
sqlog
.
Debug
(
"Alert deleted"
,
"name"
,
missingAlert
.
Name
,
"id"
,
missingAlert
.
Id
)
sqlog
.
Debug
(
"Alert deleted"
,
"name"
,
missingAlert
.
Name
,
"id"
,
missingAlert
.
Id
)
SaveAlertChange
(
&
m
.
CreateAlertChangeCommand
{
OrgId
:
missingAlert
.
OrgId
,
AlertId
:
missingAlert
.
Id
,
NewAlertSettings
:
missingAlert
.
Settings
,
UpdatedBy
:
cmd
.
UserId
,
Type
:
"DELETED"
,
},
sess
)
if
err
!=
nil
{
return
err
}
}
}
}
}
...
...
pkg/services/sqlstore/alert_rule_changes.go
deleted
100644 → 0
View file @
d9096110
package
sqlstore
import
(
"bytes"
"time"
"github.com/go-xorm/xorm"
"github.com/grafana/grafana/pkg/bus"
m
"github.com/grafana/grafana/pkg/models"
)
func
init
()
{
bus
.
AddHandler
(
"sql"
,
GetAlertRuleChanges
)
}
func
GetAlertRuleChanges
(
query
*
m
.
GetAlertChangesQuery
)
error
{
var
sql
bytes
.
Buffer
params
:=
make
([]
interface
{},
0
)
sql
.
WriteString
(
`SELECT
alert_change.id,
alert_change.org_id,
alert_change.alert_id,
alert_change.type,
alert_change.created,
alert_change.new_alert_settings,
alert_change.updated_by
FROM alert_change
`
)
sql
.
WriteString
(
`WHERE alert_change.org_id = ?`
)
params
=
append
(
params
,
query
.
OrgId
)
if
query
.
SinceId
!=
0
{
sql
.
WriteString
(
`AND alert_change.id >= ?`
)
params
=
append
(
params
,
query
.
SinceId
)
}
if
query
.
Limit
!=
0
{
sql
.
WriteString
(
` ORDER BY alert_change.id DESC LIMIT ?`
)
params
=
append
(
params
,
query
.
Limit
)
}
alertChanges
:=
make
([]
*
m
.
AlertChange
,
0
)
if
err
:=
x
.
Sql
(
sql
.
String
(),
params
...
)
.
Find
(
&
alertChanges
);
err
!=
nil
{
return
err
}
query
.
Result
=
alertChanges
return
nil
}
func
SaveAlertChange
(
cmd
*
m
.
CreateAlertChangeCommand
,
sess
*
xorm
.
Session
)
error
{
_
,
err
:=
sess
.
Insert
(
&
m
.
AlertChange
{
OrgId
:
cmd
.
OrgId
,
Type
:
cmd
.
Type
,
Created
:
time
.
Now
(),
AlertId
:
cmd
.
AlertId
,
NewAlertSettings
:
cmd
.
NewAlertSettings
,
UpdatedBy
:
cmd
.
UpdatedBy
,
})
if
err
!=
nil
{
return
err
}
return
nil
}
pkg/services/sqlstore/alert_rule_changes_test.go
deleted
100644 → 0
View file @
d9096110
package
sqlstore
import
(
"testing"
m
"github.com/grafana/grafana/pkg/models"
.
"github.com/smartystreets/goconvey/convey"
)
var
(
FakeOrgId
int64
=
2
)
func
TestAlertRuleChangesDataAccess
(
t
*
testing
.
T
)
{
Convey
(
"Testing Alert rule changes data access"
,
t
,
func
()
{
InitTestDB
(
t
)
testDash
:=
insertTestDashboard
(
"dashboard with alerts"
,
2
,
"alert"
)
var
err
error
Convey
(
"When dashboard is removed"
,
func
()
{
items
:=
[]
*
m
.
Alert
{
{
PanelId
:
1
,
DashboardId
:
testDash
.
Id
,
Name
:
"Alerting title"
,
Description
:
"Alerting description"
,
OrgId
:
FakeOrgId
,
},
}
cmd
:=
m
.
SaveAlertsCommand
{
Alerts
:
items
,
DashboardId
:
testDash
.
Id
,
OrgId
:
FakeOrgId
,
UserId
:
2
,
}
SaveAlerts
(
&
cmd
)
query
:=
&
m
.
GetAlertChangesQuery
{
OrgId
:
FakeOrgId
}
er
:=
GetAlertRuleChanges
(
query
)
So
(
er
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
err
=
DeleteDashboard
(
&
m
.
DeleteDashboardCommand
{
OrgId
:
FakeOrgId
,
Slug
:
testDash
.
Slug
,
})
So
(
err
,
ShouldBeNil
)
Convey
(
"Alerts should be removed"
,
func
()
{
query
:=
m
.
GetAlertsQuery
{
DashboardId
:
testDash
.
Id
,
OrgId
:
1
}
err2
:=
HandleAlertsQuery
(
&
query
)
So
(
testDash
.
Id
,
ShouldEqual
,
1
)
So
(
err2
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
0
)
})
Convey
(
"should add one more alert_rule_change"
,
func
()
{
query
:=
&
m
.
GetAlertChangesQuery
{
OrgId
:
FakeOrgId
}
er
:=
GetAlertRuleChanges
(
query
)
So
(
er
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
})
Convey
(
"add 4 updates"
,
func
()
{
sess
:=
x
.
NewSession
()
updateCmd
:=
m
.
CreateAlertChangeCommand
{
AlertId
:
items
[
0
]
.
Id
,
OrgId
:
items
[
0
]
.
OrgId
,
UpdatedBy
:
1
,
}
SaveAlertChange
(
&
updateCmd
,
sess
)
SaveAlertChange
(
&
updateCmd
,
sess
)
SaveAlertChange
(
&
updateCmd
,
sess
)
SaveAlertChange
(
&
updateCmd
,
sess
)
sess
.
Commit
()
Convey
(
"query for max one change"
,
func
()
{
query
:=
&
m
.
GetAlertChangesQuery
{
OrgId
:
FakeOrgId
,
Limit
:
1
}
er
:=
GetAlertRuleChanges
(
query
)
So
(
er
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
1
)
})
Convey
(
"query for all since id 5"
,
func
()
{
query
:=
&
m
.
GetAlertChangesQuery
{
OrgId
:
FakeOrgId
,
SinceId
:
5
}
er
:=
GetAlertRuleChanges
(
query
)
So
(
er
,
ShouldBeNil
)
So
(
len
(
query
.
Result
),
ShouldEqual
,
2
)
})
})
})
})
}
pkg/services/sqlstore/migrations/alert_mig.go
View file @
624cd6fc
...
@@ -14,7 +14,7 @@ func addAlertMigrations(mg *Migrator) {
...
@@ -14,7 +14,7 @@ func addAlertMigrations(mg *Migrator) {
{
Name
:
"panel_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"panel_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"name"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"description"
,
Type
:
DB_
NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"description"
,
Type
:
DB_
Text
,
Nullable
:
false
},
{
Name
:
"state"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"state"
,
Type
:
DB_NVarchar
,
Length
:
255
,
Nullable
:
false
},
{
Name
:
"settings"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"settings"
,
Type
:
DB_Text
,
Nullable
:
false
},
{
Name
:
"frequency"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"frequency"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
...
@@ -22,34 +22,21 @@ func addAlertMigrations(mg *Migrator) {
...
@@ -22,34 +22,21 @@ func addAlertMigrations(mg *Migrator) {
{
Name
:
"enabled"
,
Type
:
DB_Bool
,
Nullable
:
false
},
{
Name
:
"enabled"
,
Type
:
DB_Bool
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated_by"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"created_by"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
},
},
}
}
// create table
// create table
mg
.
AddMigration
(
"create alert table v1"
,
NewAddTableMigration
(
alertV1
))
mg
.
AddMigration
(
"create alert table v1"
,
NewAddTableMigration
(
alertV1
))
alert_changes
:=
Table
{
Name
:
"alert_change"
,
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"alert_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"type"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"updated_by"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"new_alert_settings"
,
Type
:
DB_Text
,
Nullable
:
false
},
},
}
mg
.
AddMigration
(
"create alert_change table v1"
,
NewAddTableMigration
(
alert_changes
))
alert_state_log
:=
Table
{
alert_state_log
:=
Table
{
Name
:
"alert_state"
,
Name
:
"alert_state"
,
Columns
:
[]
*
Column
{
Columns
:
[]
*
Column
{
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"id"
,
Type
:
DB_BigInt
,
IsPrimaryKey
:
true
,
IsAutoIncrement
:
true
},
{
Name
:
"alert_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"alert_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"org_id"
,
Type
:
DB_BigInt
,
Nullable
:
false
},
{
Name
:
"
new_
state"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
false
},
{
Name
:
"state"
,
Type
:
DB_NVarchar
,
Length
:
50
,
Nullable
:
false
},
{
Name
:
"info"
,
Type
:
DB_Text
,
Nullable
:
true
},
{
Name
:
"info"
,
Type
:
DB_Text
,
Nullable
:
true
},
{
Name
:
"triggered_alerts"
,
Type
:
DB_Text
,
Nullable
:
true
},
{
Name
:
"triggered_alerts"
,
Type
:
DB_Text
,
Nullable
:
true
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
{
Name
:
"created"
,
Type
:
DB_DateTime
,
Nullable
:
false
},
...
...
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