Skip to content

Commit

Permalink
Added PreviousLevel to Alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
sputnik13 committed Oct 19, 2017
1 parent 6e45b39 commit 5b676c0
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 306 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

### Features
- [#1408](https://github.com/influxdata/kapacitor/issues/1408): Add Previous state

- [#1413](https://github.com/influxdata/kapacitor/issues/1413): Add subscriptions modes to InfluxDB subscriptions.
- [#1436](https://github.com/influxdata/kapacitor/issues/1436): Add linear fill support for QueryNode.
Expand Down
30 changes: 16 additions & 14 deletions alert/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ type Event struct {

func (e Event) AlertData() Data {
return Data{
ID: e.State.ID,
Message: e.State.Message,
Details: e.State.Details,
Time: e.State.Time,
Duration: e.State.Duration,
Level: e.State.Level,
Data: e.Data.Result,
ID: e.State.ID,
Message: e.State.Message,
Details: e.State.Details,
Time: e.State.Time,
Duration: e.State.Duration,
Level: e.State.Level,
Data: e.Data.Result,
PreviousLevel: e.previousState.Level,
}
}

Expand Down Expand Up @@ -170,11 +171,12 @@ type TopicState struct {
// Data is a structure that contains relevant data about an alert event.
// The structure is intended to be JSON encoded, providing a consistent data format.
type Data struct {
ID string `json:"id"`
Message string `json:"message"`
Details string `json:"details"`
Time time.Time `json:"time"`
Duration time.Duration `json:"duration"`
Level Level `json:"level"`
Data models.Result `json:"data"`
ID string `json:"id"`
Message string `json:"message"`
Details string `json:"details"`
Time time.Time `json:"time"`
Duration time.Duration `json:"duration"`
Level Level `json:"level"`
Data models.Result `json:"data"`
PreviousLevel Level `json:"previousLevel"`
}
56 changes: 35 additions & 21 deletions integrations/batcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1449,22 +1449,24 @@ func TestBatch_AlertStateChangesOnly(t *testing.T) {
atomic.AddInt32(&requestCount, 1)
if rc := atomic.LoadInt32(&requestCount); rc == 1 {
expAd := alert.Data{
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is CRITICAL",
Time: time.Date(1971, 1, 1, 0, 0, 0, 0, time.UTC),
Level: alert.Critical,
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is CRITICAL",
Time: time.Date(1971, 1, 1, 0, 0, 0, 0, time.UTC),
Level: alert.Critical,
PreviousLevel: alert.OK,
}
ad.Data = models.Result{}
if eq, msg := compareAlertData(expAd, ad); !eq {
t.Error(msg)
}
} else {
expAd := alert.Data{
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is OK",
Time: time.Date(1971, 1, 1, 0, 0, 38, 0, time.UTC),
Duration: 38 * time.Second,
Level: alert.OK,
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is OK",
Time: time.Date(1971, 1, 1, 0, 0, 38, 0, time.UTC),
Duration: 38 * time.Second,
Level: alert.OK,
PreviousLevel: alert.Critical,
}
ad.Data = models.Result{}
if eq, msg := compareAlertData(expAd, ad); !eq {
Expand Down Expand Up @@ -1516,21 +1518,33 @@ func TestBatch_AlertStateChangesOnlyExpired(t *testing.T) {
var expAd alert.Data
atomic.AddInt32(&requestCount, 1)
rc := atomic.LoadInt32(&requestCount)
if rc < 3 {
switch rc {
case 1:
expAd = alert.Data{
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is CRITICAL",
Time: time.Date(1971, 1, 1, 0, 0, int(rc-1)*20, 0, time.UTC),
Duration: time.Duration(rc-1) * 20 * time.Second,
Level: alert.Critical,
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is CRITICAL",
Time: time.Date(1971, 1, 1, 0, 0, int(rc-1)*20, 0, time.UTC),
Duration: time.Duration(rc-1) * 20 * time.Second,
Level: alert.Critical,
PreviousLevel: alert.OK,
}
} else {
case 2:
expAd = alert.Data{
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is CRITICAL",
Time: time.Date(1971, 1, 1, 0, 0, int(rc-1)*20, 0, time.UTC),
Duration: time.Duration(rc-1) * 20 * time.Second,
Level: alert.Critical,
PreviousLevel: alert.Critical,
}
case 3:
expAd = alert.Data{
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is OK",
Time: time.Date(1971, 1, 1, 0, 0, 38, 0, time.UTC),
Duration: 38 * time.Second,
Level: alert.OK,
ID: "cpu_usage_idle:cpu=cpu-total",
Message: "cpu_usage_idle:cpu=cpu-total is OK",
Time: time.Date(1971, 1, 1, 0, 0, 38, 0, time.UTC),
Duration: 38 * time.Second,
Level: alert.OK,
PreviousLevel: alert.Critical,
}
}
if eq, msg := compareAlertData(expAd, ad); !eq {
Expand Down
Loading

0 comments on commit 5b676c0

Please sign in to comment.