@@ -3,6 +3,7 @@ package gapi
3
3
import (
4
4
"encoding/json"
5
5
"testing"
6
+ "time"
6
7
7
8
"github.com/gobs/pretty"
8
9
)
@@ -26,17 +27,17 @@ func TestAlertRules(t *testing.T) {
26
27
server , client := gapiTestTools (t , 200 , getAlertRuleGroupJSON )
27
28
defer server .Close ()
28
29
29
- group , err := client .AlertRuleGroup ("d8-gk06nz " , "test " )
30
+ group , err := client .AlertRuleGroup ("project_test " , "eval_group_1 " )
30
31
31
32
if err != nil {
32
33
t .Error (err )
33
34
}
34
35
t .Log (pretty .PrettyFormat (group ))
35
- if group .Title != "test " {
36
- t .Errorf ("incorrect title - expected %s got %s" , "test " , group .Title )
36
+ if group .Title != "eval_group_1 " {
37
+ t .Errorf ("incorrect title - expected %s got %s" , "eval_group_1 " , group .Title )
37
38
}
38
- if group .FolderUID != "d8-gk06nz " {
39
- t .Errorf ("incorrect folderUID - expected %s got %s" , "d8-gk06nz " , group .FolderUID )
39
+ if group .FolderUID != "project_test " {
40
+ t .Errorf ("incorrect folderUID - expected %s got %s" , "project_test " , group .FolderUID )
40
41
}
41
42
if len (group .Rules ) != 1 {
42
43
t .Errorf ("wrong number of rules, got %d" , len (group .Rules ))
@@ -138,7 +139,7 @@ func createAlertRule() AlertRule {
138
139
OrgID : 1 ,
139
140
RuleGroup : "eval_group_1" ,
140
141
Title : "Always in alarm" ,
141
- ForDuration : 0 ,
142
+ ForDuration : 60 * time . Second ,
142
143
}
143
144
}
144
145
@@ -165,7 +166,7 @@ const writeAlertRuleJSON = `
165
166
"orgId": 1,
166
167
"ruleGroup": "eval_group_1",
167
168
"title": "Always in alarm",
168
- "for": 0
169
+ "for": "1m"
169
170
}
170
171
`
171
172
@@ -180,95 +181,84 @@ const getAlertRuleJSON = `
180
181
"uid": "123abcd",
181
182
"ruleGroup": "eval_group_1",
182
183
"title": "Always in alarm",
183
- "for": 0
184
+ "for": "1m"
184
185
}
185
186
`
186
187
187
188
const getAlertRuleGroupJSON = `
188
189
{
189
- "title": "test ",
190
- "folderUid": "d8-gk06nz ",
190
+ "title": "eval_group_1 ",
191
+ "folderUid": "project_test ",
191
192
"interval": 60,
192
193
"rules": [
193
- {
194
- "ID": 1,
195
- "OrgID": 1,
196
- "Title": "abc",
197
- "Condition": "B",
198
- "Data": [
199
- {
200
- "refId": "A",
201
- "queryType": "",
202
- "relativeTimeRange": {
203
- "from": 600,
204
- "to": 0
194
+ {
195
+ "id": 212,
196
+ "uid": "HW7RYci4z",
197
+ "orgID": 1,
198
+ "folderUID": "project_test",
199
+ "ruleGroup": "eval_group_1",
200
+ "title": "Always in alarm",
201
+ "condition": "A",
202
+ "data": [
203
+ {
204
+ "refId": "A",
205
+ "queryType": "",
206
+ "relativeTimeRange": {
207
+ "from": 0,
208
+ "to": 0
209
+ },
210
+ "datasourceUid": "-100",
211
+ "model": {
212
+ "datasourceUid": "-100",
213
+ "intervalMs": 1000,
214
+ "maxDataPoints": 43200,
215
+ "model": {
216
+ "conditions": [
217
+ {
218
+ "evaluator": {
219
+ "params": [
220
+ 0,
221
+ 0
222
+ ],
223
+ "type": "gt"
205
224
},
206
- "datasourceUid": "PD8C576611E62080A",
207
- "model": {
208
- "hide": false,
209
- "intervalMs": 1000,
210
- "maxDataPoints": 43200,
211
- "refId": "A"
212
- }
213
- },
214
- {
215
- "refId": "B",
216
- "queryType": "",
217
- "relativeTimeRange": {
218
- "from": 0,
219
- "to": 0
225
+ "operator": {
226
+ "type": "and"
220
227
},
221
- "datasourceUid": "-100",
222
- "model": {
223
- "conditions": [
224
- {
225
- "evaluator": {
226
- "params": [
227
- 3
228
- ],
229
- "type": "gt"
230
- },
231
- "operator": {
232
- "type": "and"
233
- },
234
- "query": {
235
- "params": [
236
- "A"
237
- ]
238
- },
239
- "reducer": {
240
- "params": [],
241
- "type": "last"
242
- },
243
- "type": "query"
244
- }
245
- ],
246
- "datasource": {
247
- "type": "__expr__",
248
- "uid": "-100"
249
- },
250
- "hide": false,
251
- "intervalMs": 1000,
252
- "maxDataPoints": 43200,
253
- "refId": "B",
254
- "type": "classic_conditions"
255
- }
256
- }
257
- ],
258
- "Updated": "2022-07-07T16:23:56-05:00",
259
- "IntervalSeconds": 60,
260
- "Version": 1,
261
- "UID": "hsXgz0enz",
262
- "NamespaceUID": "d8-gk06nz",
263
- "DashboardUID": null,
264
- "PanelID": null,
265
- "RuleGroup": "test",
266
- "RuleGroupIndex": 1,
267
- "NoDataState": "NoData",
268
- "ExecErrState": "Alerting",
269
- "For": 300000000000,
270
- "Annotations": {},
271
- "Labels": {}
272
- }
228
+ "query": {
229
+ "params": []
230
+ },
231
+ "reducer": {
232
+ "params": [],
233
+ "type": "avg"
234
+ },
235
+ "type": "query"
236
+ }
237
+ ],
238
+ "datasource": {
239
+ "type": "__expr__",
240
+ "uid": "__expr__"
241
+ },
242
+ "expression": "1 == 1",
243
+ "hide": false,
244
+ "intervalMs": 1000,
245
+ "maxDataPoints": 43200,
246
+ "refId": "A",
247
+ "type": "math"
248
+ },
249
+ "queryType": "",
250
+ "refId": "A",
251
+ "relativeTimeRange": {
252
+ "from": 0,
253
+ "to": 0
254
+ }
255
+ }
256
+ }
257
+ ],
258
+ "updated": "2022-08-12T15:44:43-05:00",
259
+ "noDataState": "OK",
260
+ "execErrState": "OK",
261
+ "for": "2m"
262
+ }
273
263
]
274
- }`
264
+ }`
0 commit comments