Skip to content

Commit 9216492

Browse files
committed
Merge branch 'alert_handles' into alert_ui_take2
Conflicts: pkg/services/alerting/commands.go
2 parents 77746f2 + e3b281d commit 9216492

File tree

16 files changed

+427
-262
lines changed

16 files changed

+427
-262
lines changed

pkg/services/alerting/alert_rule.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type AlertRule struct {
2626
Transformer transformer.Transformer
2727
}
2828

29+
func getTimeDurationStringToSeconds(str string) int64 {
30+
return 60
31+
}
32+
2933
func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
3034
model := &AlertRule{}
3135
model.Id = ruleDef.Id
@@ -40,13 +44,13 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
4044
Level: critical.Get("level").MustFloat64(),
4145
}
4246

43-
warning := ruleDef.Expression.Get("warning")
47+
warning := ruleDef.Expression.Get("warn")
4448
model.Warning = Level{
4549
Operator: warning.Get("op").MustString(),
4650
Level: warning.Get("level").MustFloat64(),
4751
}
4852

49-
model.Frequency = ruleDef.Expression.Get("frequency").MustInt64()
53+
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Expression.Get("frequency").MustString())
5054
model.Transform = ruleDef.Expression.Get("transform").Get("type").MustString()
5155
model.TransformParams = *ruleDef.Expression.Get("transform")
5256

pkg/services/alerting/commands.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package alerting
22

33
import (
4-
"fmt"
5-
64
"github.com/grafana/grafana/pkg/bus"
75
m "github.com/grafana/grafana/pkg/models"
8-
"github.com/grafana/grafana/pkg/services/alerting/transformers"
96
)
107

118
type UpdateDashboardAlertsCommand struct {
@@ -39,56 +36,3 @@ func updateDashboardAlerts(cmd *UpdateDashboardAlertsCommand) error {
3936

4037
return nil
4138
}
42-
43-
func getTimeDurationStringToSeconds(str string) int64 {
44-
return 60
45-
}
46-
47-
func ConvetAlertModelToAlertRule(ruleDef *m.Alert) (*AlertRule, error) {
48-
model := &AlertRule{}
49-
model.Id = ruleDef.Id
50-
model.OrgId = ruleDef.OrgId
51-
model.Name = ruleDef.Name
52-
model.Description = ruleDef.Description
53-
model.State = ruleDef.State
54-
55-
critical := ruleDef.Expression.Get("critical")
56-
model.Critical = Level{
57-
Operator: critical.Get("op").MustString(),
58-
Level: critical.Get("level").MustFloat64(),
59-
}
60-
61-
warning := ruleDef.Expression.Get("warning")
62-
model.Warning = Level{
63-
Operator: warning.Get("op").MustString(),
64-
Level: warning.Get("level").MustFloat64(),
65-
}
66-
67-
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Expression.Get("frequency").MustString())
68-
model.Transform = ruleDef.Expression.Get("transform").Get("type").MustString()
69-
model.TransformParams = *ruleDef.Expression.Get("transform")
70-
71-
if model.Transform == "aggregation" {
72-
method := ruleDef.Expression.Get("transform").Get("method").MustString()
73-
model.Transformer = transformer.NewAggregationTransformer(method)
74-
}
75-
76-
query := ruleDef.Expression.Get("query")
77-
model.Query = AlertQuery{
78-
Query: query.Get("query").MustString(),
79-
DatasourceId: query.Get("datasourceId").MustInt64(),
80-
From: query.Get("from").MustString(),
81-
To: query.Get("to").MustString(),
82-
Aggregator: query.Get("agg").MustString(),
83-
}
84-
85-
if model.Query.Query == "" {
86-
return nil, fmt.Errorf("missing query.query")
87-
}
88-
89-
if model.Query.DatasourceId == 0 {
90-
return nil, fmt.Errorf("missing query.datasourceId")
91-
}
92-
93-
return model, nil
94-
}

pkg/services/alerting/extractor.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
5757

5858
for _, panelObj := range row.Get("panels").MustArray() {
5959
panel := simplejson.NewFromAny(panelObj)
60-
jsonAlert := panel.Get("alert")
60+
jsonAlert, hasAlert := panel.CheckGet("alert")
6161

62-
// check if marked for deletion
63-
deleted := jsonAlert.Get("deleted").MustBool()
64-
if deleted {
65-
e.log.Info("Deleted alert rule found")
62+
if !hasAlert {
6663
continue
6764
}
6865

pkg/services/alerting/extractor_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestAlertRuleExtraction(t *testing.T) {
5555
"method": "avg",
5656
"type": "aggregation"
5757
},
58-
"warning": {
58+
"warn": {
5959
"level": 10,
6060
"op": ">"
6161
}
@@ -90,7 +90,7 @@ func TestAlertRuleExtraction(t *testing.T) {
9090
"method": "avg",
9191
"name": "aggregation"
9292
},
93-
"warning": {
93+
"warn": {
9494
"level": 10,
9595
"op": ">"
9696
}
@@ -149,10 +149,7 @@ func TestAlertRuleExtraction(t *testing.T) {
149149
],
150150
"title": "Broken influxdb panel",
151151
"transform": "table",
152-
"type": "table",
153-
"alert": {
154-
"deleted": true
155-
}
152+
"type": "table"
156153
}
157154
],
158155
"title": "New row"
@@ -185,7 +182,7 @@ func TestAlertRuleExtraction(t *testing.T) {
185182
return nil
186183
})
187184

188-
alerts, err := extractor.GetRuleModels()
185+
alerts, err := extractor.GetAlerts()
189186

190187
Convey("Get rules without error", func() {
191188
So(err, ShouldBeNil)

pkg/services/alerting/reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (arr *AlertRuleReader) Fetch() []*AlertRule {
4949

5050
res := make([]*AlertRule, len(cmd.Result))
5151
for i, ruleDef := range cmd.Result {
52-
model, _ := ConvetAlertModelToAlertRule(ruleDef)
52+
model, _ := NewAlertRuleFromDBModel(ruleDef)
5353
res[i] = model
5454
}
5555

pkg/services/sqlstore/alert_rule_parser_test.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

public/app/features/dashboard/viewStateSrv.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,25 +120,28 @@ function (angular, _, $) {
120120
if (this.panelScopes.length === 0) { return; }
121121

122122
if (this.dashboard.meta.fullscreen) {
123-
if (this.fullscreenPanel) {
124-
this.leaveFullscreen(false);
125-
}
126123
var panelScope = this.getPanelScope(this.state.panelId);
127-
// panel could be about to be created/added and scope does
128-
// not exist yet
129124
if (!panelScope) {
130125
return;
131126
}
132127

128+
if (this.fullscreenPanel) {
129+
// if already fullscreen
130+
if (this.fullscreenPanel === panelScope) {
131+
return;
132+
} else {
133+
this.leaveFullscreen(false);
134+
}
135+
}
136+
133137
if (!panelScope.ctrl.editModeInitiated) {
134138
panelScope.ctrl.initEditMode();
135139
}
136140

137-
this.enterFullscreen(panelScope);
138-
return;
139-
}
140-
141-
if (this.fullscreenPanel) {
141+
if (!panelScope.ctrl.fullscreen) {
142+
this.enterFullscreen(panelScope);
143+
}
144+
} else if (this.fullscreenPanel) {
142145
this.leaveFullscreen(true);
143146
}
144147
};

public/app/features/panel/panel_ctrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ export class PanelCtrl {
152152
calculatePanelHeight() {
153153
if (this.fullscreen) {
154154
var docHeight = $(window).height();
155-
var editHeight = Math.floor(docHeight * 0.3);
156-
var fullscreenHeight = Math.floor(docHeight * 0.7);
155+
var editHeight = Math.floor(docHeight * 0.4);
156+
var fullscreenHeight = Math.floor(docHeight * 0.6);
157157
this.containerHeight = this.editMode ? editHeight : fullscreenHeight;
158158
} else {
159159
this.containerHeight = this.panel.height || this.row.height;

0 commit comments

Comments
 (0)