Skip to content

update alert request/response json #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 34 additions & 68 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,27 +507,11 @@ func getAlertBody(stream string, targetId string) string {
{
"severity": "medium",
"title": "AlertTitle",
"stream": "%s",
"query": "select count(level) from %s where level = 'info'",
"alertType": "threshold",
"aggregates": {
"operator": null,
"aggregateConfig": [
{
"aggregateFunction": "count",
"conditions": {
"conditionConfig": [
{
"column": "level",
"operator": "=",
"value": "info"
}
]
},
"column": "level",
"operator": "=",
"value": 100
}
]
"thresholdConfig": {
"operator": "=",
"value": 100
},
"evalConfig": {
"rollingWindow": {
Expand All @@ -544,15 +528,15 @@ func getAlertBody(stream string, targetId string) string {

func getIdStateFromAlertResponse(body io.Reader) (string, string) {
type AlertConfig struct {
Severity string `json:"severity"`
Title string `json:"title"`
Id string `json:"id"`
State string `json:"state"`
Stream string `json:"stream"`
AlertType string `json:"alertType"`
Aggregates string `json:"aggregates"`
EvalConfig string `json:"evalConfig"`
Targets string `json:"targets"`
Severity string `json:"severity"`
Title string `json:"title"`
Id string `json:"id"`
State string `json:"state"`
Query string `json:"query"`
AlertType string `json:"alertType"`
ThresholdConfig string `json:"thresholdConfig"`
EvalConfig string `json:"evalConfig"`
Targets string `json:"targets"`
}

var response []AlertConfig
Expand All @@ -567,44 +551,26 @@ func getIdStateFromAlertResponse(body io.Reader) (string, string) {
func createAlertResponse(id string, state string, stream string, targetId string) string {
return fmt.Sprintf(`
[{
"version": "v1",
"id": "%s",
"state": "%s",
"severity": "medium",
"title": "AlertTitle",
"stream": "%s",
"alertType": "threshold",
"aggregates": {
"operator": null,
"aggregateConfig": [
{
"aggregateFunction": "count",
"conditions": {
"operator": null,
"conditionConfig": [
{
"column": "level",
"operator": "=",
"value": "info"
}
]
},
"groupBy": null,
"column": "level",
"operator": "=",
"value": 100
"version": "v2",
"id": "%s",
"severity": "medium",
"title": "AlertTitle",
"query": "select count(level) from %s where level = 'info'",
"alertType": "threshold",
"thresholdConfig": {
"operator": "=",
"value": 100.0
},
"evalConfig": {
"rollingWindow": {
"evalStart": "5m",
"evalEnd": "now",
"evalFrequency": 1
}
]
},
"evalConfig": {
"rollingWindow": {
"evalStart": "5m",
"evalEnd": "now",
"evalFrequency": 1
}
},
"targets": [
"%s"
]
}]`, id, state, stream, targetId)
},
"targets": [
"%s"
],
"state": "%s"
}]`, id, stream, targetId, state)
}
3 changes: 0 additions & 3 deletions quest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,6 @@ func TestSmokeSetAlert(t *testing.T) {
cmd.Output()
}
time.Sleep(120 * time.Second)
schemaReq, _ := NewGlob.QueryClient.NewRequest("GET", "/logstream/"+stream+"/schema", nil)
schemaResponse, _ := NewGlob.QueryClient.Do(schemaReq)
require.Equalf(t, 200, schemaResponse.StatusCode, "Server returned http code: %s and response: %s", schemaResponse.Status, readAsString(schemaResponse.Body))
req, _ := NewGlob.QueryClient.NewRequest("GET", "/targets", nil)
response, err := NewGlob.QueryClient.Do(req)
require.NoErrorf(t, err, "Request failed: %s", err)
Expand Down