Skip to content

Commit cf0fe27

Browse files
update alert listing, config (#109)
1 parent 62ed4cb commit cf0fe27

File tree

2 files changed

+25
-37
lines changed

2 files changed

+25
-37
lines changed

model.go

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,20 @@ func getAlertBody(stream string, targetId string) string {
522522
},
523523
"targets": [
524524
"%s"
525-
]
525+
],
526+
"tags": ["quest-test"]
526527
}`, stream, targetId)
527528
}
528529

529-
func getIdStateFromAlertResponse(body io.Reader) (string, string) {
530+
func getMetadataFromAlertResponse(body io.Reader) (string, string, string) {
530531
type AlertConfig struct {
531-
Severity string `json:"severity"`
532-
Title string `json:"title"`
533-
Id string `json:"id"`
534-
State string `json:"state"`
535-
Query string `json:"query"`
536-
AlertType string `json:"alertType"`
537-
ThresholdConfig string `json:"thresholdConfig"`
538-
EvalConfig string `json:"evalConfig"`
539-
Targets string `json:"targets"`
532+
Severity string `json:"severity"`
533+
Title string `json:"title"`
534+
Id string `json:"id"`
535+
State string `json:"state"`
536+
AlertType string `json:"alertType"`
537+
Tags []string `json:"tags"`
538+
Created string `json:"created"`
540539
}
541540

542541
var response []AlertConfig
@@ -545,32 +544,22 @@ func getIdStateFromAlertResponse(body io.Reader) (string, string) {
545544
}
546545

547546
alert := response[0]
548-
return alert.Id, alert.State
547+
return alert.Id, alert.State, alert.Created
549548
}
550549

551-
func createAlertResponse(id string, state string, stream string, targetId string) string {
550+
func createAlertResponse(id string, state string, created string) string {
552551
return fmt.Sprintf(`
553-
[{
554-
"version": "v2",
555-
"id": "%s",
556-
"severity": "medium",
552+
[
553+
{
557554
"title": "AlertTitle",
558-
"query": "select count(level) from %s where level = 'info'",
555+
"created": "%s",
559556
"alertType": "threshold",
560-
"thresholdConfig": {
561-
"operator": "=",
562-
"value": 100.0
563-
},
564-
"evalConfig": {
565-
"rollingWindow": {
566-
"evalStart": "5m",
567-
"evalEnd": "now",
568-
"evalFrequency": 1
569-
}
570-
},
571-
"targets": [
572-
"%s"
573-
],
574-
"state": "%s"
575-
}]`, id, stream, targetId, state)
557+
"id": "%s",
558+
"severity": "Medium (P2)",
559+
"state": "%s",
560+
"tags": [
561+
"quest-test"
562+
]
563+
}
564+
]`, created, id, state)
576565
}

quest_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ func TestSmokeLoad_CustomPartition_WithK6Stream(t *testing.T) {
375375
// }
376376

377377
func TestSmokeSetTarget(t *testing.T) {
378-
// RunFlog(t, NewGlob.QueryClient, NewGlob.Stream)
379378
body := getTargetBody()
380379
req, _ := NewGlob.QueryClient.NewRequest("POST", "/targets", strings.NewReader(body))
381380
response, err := NewGlob.QueryClient.Do(req)
@@ -438,9 +437,9 @@ func TestSmokeGetAlert(t *testing.T) {
438437
reader1 = bytes.NewReader(body)
439438
reader2 := bytes.NewReader(body)
440439
expected := readAsString(reader1)
441-
id, state := getIdStateFromAlertResponse(reader2)
440+
id, state, created := getMetadataFromAlertResponse(reader2)
442441
require.Equalf(t, 200, response.StatusCode, "Server returned http code: %s and response: %s", response.Status, body)
443-
res := createAlertResponse(id, state, stream, targetId)
442+
res := createAlertResponse(id, state, created)
444443
require.JSONEq(t, expected, res, "Get alert response doesn't match with Alert config returned")
445444
DeleteAlert(t, NewGlob.QueryClient, id)
446445
DeleteTarget(t, NewGlob.QueryClient, targetId)

0 commit comments

Comments
 (0)