Skip to content

Commit

Permalink
fix(ui): fixed threshold check bug that wouldn't allow threshold chec…
Browse files Browse the repository at this point in the history
…ks to be created where fields had spaces in them (#17391)
asalem1 authored Mar 24, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent c926acc commit 4f65cda
Showing 9 changed files with 295 additions and 138 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@

1. [17240](https://github.com/influxdata/influxdb/pull/17240): NodeJS logo displays properly in Firefox
1. [17363](https://github.com/influxdata/influxdb/pull/17363): Fixed telegraf configuration bugs where system buckets were appearing in the buckets dropdown
1. [17391](https://github.com/influxdata/influxdb/pull/17391): Fixed threshold check bug where checks could not be created when a field had a space in the name

### UI Improvements

2 changes: 1 addition & 1 deletion http/check_test.go
Original file line number Diff line number Diff line change
@@ -409,7 +409,7 @@ func TestService_handleGetCheckQuery(t *testing.T) {
wants: wants{
statusCode: http.StatusOK,
contentType: "application/json; charset=utf-8",
body: "{\"flux\":\"package main\\nimport \\\"influxdata/influxdb/monitor\\\"\\nimport \\\"influxdata/influxdb/v1\\\"\\n\\ndata = from(bucket: \\\"foo\\\")\\n\\t|\\u003e range(start: -1h)\\n\\t|\\u003e filter(fn: (r) =\\u003e\\n\\t\\t(r._field == \\\"usage_idle\\\"))\\n\\t|\\u003e aggregateWindow(every: 1h, fn: mean, createEmpty: false)\\n\\noption task = {name: \\\"hello\\\", every: 1h}\\n\\ncheck = {\\n\\t_check_id: \\\"020f755c3c082000\\\",\\n\\t_check_name: \\\"hello\\\",\\n\\t_type: \\\"threshold\\\",\\n\\ttags: {aaa: \\\"vaaa\\\", bbb: \\\"vbbb\\\"},\\n}\\nok = (r) =\\u003e\\n\\t(r.usage_idle \\u003e 10.0)\\ninfo = (r) =\\u003e\\n\\t(r.usage_idle \\u003c 40.0)\\nwarn = (r) =\\u003e\\n\\t(r.usage_idle \\u003c 40.0 and r.usage_idle \\u003e 10.0)\\ncrit = (r) =\\u003e\\n\\t(r.usage_idle \\u003c 40.0 and r.usage_idle \\u003e 10.0)\\nmessageFn = (r) =\\u003e\\n\\t(\\\"whoa! {check.yeah}\\\")\\n\\ndata\\n\\t|\\u003e v1.fieldsAsCols()\\n\\t|\\u003e monitor.check(\\n\\t\\tdata: check,\\n\\t\\tmessageFn: messageFn,\\n\\t\\tok: ok,\\n\\t\\tinfo: info,\\n\\t\\twarn: warn,\\n\\t\\tcrit: crit,\\n\\t)\"}",
body: "{\"flux\":\"package main\\nimport \\\"influxdata/influxdb/monitor\\\"\\nimport \\\"influxdata/influxdb/v1\\\"\\n\\ndata = from(bucket: \\\"foo\\\")\\n\\t|\\u003e range(start: -1h)\\n\\t|\\u003e filter(fn: (r) =\\u003e\\n\\t\\t(r._field == \\\"usage_idle\\\"))\\n\\t|\\u003e aggregateWindow(every: 1h, fn: mean, createEmpty: false)\\n\\noption task = {name: \\\"hello\\\", every: 1h}\\n\\ncheck = {\\n\\t_check_id: \\\"020f755c3c082000\\\",\\n\\t_check_name: \\\"hello\\\",\\n\\t_type: \\\"threshold\\\",\\n\\ttags: {aaa: \\\"vaaa\\\", bbb: \\\"vbbb\\\"},\\n}\\nok = (r) =\\u003e\\n\\t(r[\\\"usage_idle\\\"] \\u003e 10.0)\\ninfo = (r) =\\u003e\\n\\t(r[\\\"usage_idle\\\"] \\u003c 40.0)\\nwarn = (r) =\\u003e\\n\\t(r[\\\"usage_idle\\\"] \\u003c 40.0 and r[\\\"usage_idle\\\"] \\u003e 10.0)\\ncrit = (r) =\\u003e\\n\\t(r[\\\"usage_idle\\\"] \\u003c 40.0 and r[\\\"usage_idle\\\"] \\u003e 10.0)\\nmessageFn = (r) =\\u003e\\n\\t(\\\"whoa! {check.yeah}\\\")\\n\\ndata\\n\\t|\\u003e v1[\\\"fieldsAsCols\\\"]()\\n\\t|\\u003e monitor[\\\"check\\\"](\\n\\t\\tdata: check,\\n\\t\\tmessageFn: messageFn,\\n\\t\\tok: ok,\\n\\t\\tinfo: info,\\n\\t\\twarn: warn,\\n\\t\\tcrit: crit,\\n\\t)\"}\n",
},
},
}
89 changes: 77 additions & 12 deletions notification/check/deadman_test.go
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ func TestDeadman_GenerateFlux(t *testing.T) {
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r.dead}",
StatusMessageTemplate: "whoa! {r[\"dead\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> aggregateWindow(fn: mean, every: 1m) |> yield()`,
BuilderConfig: influxdb.BuilderConfig{
@@ -74,14 +74,14 @@ check = {
tags: {aaa: "vaaa", bbb: "vbbb"},
}
info = (r) =>
(r.dead)
(r["dead"])
messageFn = (r) =>
("whoa! {r.dead}")
("whoa! {r[\"dead\"]}")
data
|> v1.fieldsAsCols()
|> monitor.deadman(t: experimental.subDuration(from: now(), d: 60s))
|> monitor.check(data: check, messageFn: messageFn, info: info)`,
|> v1["fieldsAsCols"]()
|> monitor["deadman"](t: experimental["subDuration"](from: now(), d: 60s))
|> monitor["check"](data: check, messageFn: messageFn, info: info)`,
},
},
{
@@ -96,7 +96,7 @@ data
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r.dead}",
StatusMessageTemplate: "whoa! {r[\"dead\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> yield()`,
BuilderConfig: influxdb.BuilderConfig{
@@ -137,14 +137,79 @@ check = {
tags: {aaa: "vaaa", bbb: "vbbb"},
}
info = (r) =>
(r.dead)
(r["dead"])
messageFn = (r) =>
("whoa! {r.dead}")
("whoa! {r[\"dead\"]}")
data
|> v1.fieldsAsCols()
|> monitor.deadman(t: experimental.subDuration(from: now(), d: 60s))
|> monitor.check(data: check, messageFn: messageFn, info: info)`,
|> v1["fieldsAsCols"]()
|> monitor["deadman"](t: experimental["subDuration"](from: now(), d: 60s))
|> monitor["check"](data: check, messageFn: messageFn, info: info)`,
},
},
{
name: "basic with space in field name",
args: args{
deadman: check.Deadman{
Base: check.Base{
ID: 10,
Name: "moo",
Tags: []influxdb.Tag{
{Key: "aaa", Value: "vaaa"},
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r[\"dead\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> filter(fn: (r) => r._field == "usage user") |> yield()`,
BuilderConfig: influxdb.BuilderConfig{
Tags: []struct {
Key string `json:"key"`
Values []string `json:"values"`
AggregateFunctionType string `json:"aggregateFunctionType"`
}{
{
Key: "_field",
Values: []string{"usage_user"},
AggregateFunctionType: "filter",
},
},
},
},
},
TimeSince: mustDuration("60s"),
StaleTime: mustDuration("10m"),
Level: notification.Info,
},
},
wants: wants{
script: `package main
import "influxdata/influxdb/monitor"
import "experimental"
import "influxdata/influxdb/v1"
data = from(bucket: "foo")
|> range(start: -10m)
|> filter(fn: (r) =>
(r._field == "usage user"))
option task = {name: "moo", every: 1h}
check = {
_check_id: "000000000000000a",
_check_name: "moo",
_type: "deadman",
tags: {aaa: "vaaa", bbb: "vbbb"},
}
info = (r) =>
(r["dead"])
messageFn = (r) =>
("whoa! {r[\"dead\"]}")
data
|> v1["fieldsAsCols"]()
|> monitor["deadman"](t: experimental["subDuration"](from: now(), d: 60s))
|> monitor["check"](data: check, messageFn: messageFn, info: info)`,
},
},
}
139 changes: 115 additions & 24 deletions notification/check/threshold_test.go
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ func TestThreshold_GenerateFlux(t *testing.T) {
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r.usage_user}",
StatusMessageTemplate: "whoa! {r[\"usage_user\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d, stop: now()) |> filter(fn: (r) => r._field == "usage_user") |> aggregateWindow(every: 1m, fn: mean) |> yield()`,
},
@@ -95,19 +95,19 @@ check = {
tags: {aaa: "vaaa", bbb: "vbbb"},
}
ok = (r) =>
(r.usage_user > 10.0)
(r["usage_user"] > 10.0)
info = (r) =>
(r.usage_user < 40.0)
(r["usage_user"] < 40.0)
warn = (r) =>
(r.usage_user < 40.0 and r.usage_user > 10.0)
(r["usage_user"] < 40.0 and r["usage_user"] > 10.0)
crit = (r) =>
(r.usage_user < 10.0 or r.usage_user > 40.0)
(r["usage_user"] < 10.0 or r["usage_user"] > 40.0)
messageFn = (r) =>
("whoa! {r.usage_user}")
("whoa! {r[\"usage_user\"]}")
data
|> v1.fieldsAsCols()
|> monitor.check(
|> v1["fieldsAsCols"]()
|> monitor["check"](
data: check,
messageFn: messageFn,
ok: ok,
@@ -129,7 +129,7 @@ data
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r.usage_user}",
StatusMessageTemplate: "whoa! {r[\"usage_user\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d) |> filter(fn: (r) => r._field == "usage_user") |> aggregateWindow(every: 1m, fn: mean) |> yield()`,
},
@@ -186,19 +186,110 @@ check = {
tags: {aaa: "vaaa", bbb: "vbbb"},
}
ok = (r) =>
(r.usage_user > 10.0)
(r["usage_user"] > 10.0)
info = (r) =>
(r.usage_user < 40.0)
(r["usage_user"] < 40.0)
warn = (r) =>
(r.usage_user < 40.0 and r.usage_user > 10.0)
(r["usage_user"] < 40.0 and r["usage_user"] > 10.0)
crit = (r) =>
(r.usage_user < 10.0 or r.usage_user > 40.0)
(r["usage_user"] < 10.0 or r["usage_user"] > 40.0)
messageFn = (r) =>
("whoa! {r.usage_user}")
("whoa! {r[\"usage_user\"]}")
data
|> v1.fieldsAsCols()
|> monitor.check(
|> v1["fieldsAsCols"]()
|> monitor["check"](
data: check,
messageFn: messageFn,
ok: ok,
info: info,
warn: warn,
crit: crit,
)`,
},
},
{
name: "all levels with yield and space in field name",
args: args{
threshold: check.Threshold{
Base: check.Base{
ID: 10,
Name: "moo",
Tags: []influxdb.Tag{
{Key: "aaa", Value: "vaaa"},
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r[\"usage user\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d) |> filter(fn: (r) => r._field == "usage user") |> aggregateWindow(every: 1m, fn: mean) |> yield()`,
},
},
Thresholds: []check.ThresholdConfig{
check.Greater{
ThresholdConfigBase: check.ThresholdConfigBase{
Level: notification.Ok,
},
Value: l,
},
check.Lesser{
ThresholdConfigBase: check.ThresholdConfigBase{
Level: notification.Info,
},
Value: u,
},
check.Range{
ThresholdConfigBase: check.ThresholdConfigBase{
Level: notification.Warn,
},
Min: l,
Max: u,
Within: true,
},
check.Range{
ThresholdConfigBase: check.ThresholdConfigBase{
Level: notification.Critical,
},
Min: l,
Max: u,
Within: false,
},
},
},
},
wants: wants{
script: `package main
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/v1"
data = from(bucket: "foo")
|> range(start: -1h)
|> filter(fn: (r) =>
(r._field == "usage user"))
|> aggregateWindow(every: 1h, fn: mean, createEmpty: false)
option task = {name: "moo", every: 1h}
check = {
_check_id: "000000000000000a",
_check_name: "moo",
_type: "threshold",
tags: {aaa: "vaaa", bbb: "vbbb"},
}
ok = (r) =>
(r["usage user"] > 10.0)
info = (r) =>
(r["usage user"] < 40.0)
warn = (r) =>
(r["usage user"] < 40.0 and r["usage user"] > 10.0)
crit = (r) =>
(r["usage user"] < 10.0 or r["usage user"] > 40.0)
messageFn = (r) =>
("whoa! {r[\"usage user\"]}")
data
|> v1["fieldsAsCols"]()
|> monitor["check"](
data: check,
messageFn: messageFn,
ok: ok,
@@ -220,7 +311,7 @@ data
{Key: "bbb", Value: "vbbb"},
},
Every: mustDuration("1h"),
StatusMessageTemplate: "whoa! {r.usage_user}",
StatusMessageTemplate: "whoa! {r[\"usage_user\"]}",
Query: influxdb.DashboardQuery{
Text: `from(bucket: "foo") |> range(start: -1d) |> filter(fn: (r) => r._field == "usage_user") |> aggregateWindow(every: 1m, fn: mean)`,
},
@@ -277,19 +368,19 @@ check = {
tags: {aaa: "vaaa", bbb: "vbbb"},
}
ok = (r) =>
(r.usage_user > 10.0)
(r["usage_user"] > 10.0)
info = (r) =>
(r.usage_user < 40.0)
(r["usage_user"] < 40.0)
warn = (r) =>
(r.usage_user < 40.0 and r.usage_user > 10.0)
(r["usage_user"] < 40.0 and r["usage_user"] > 10.0)
crit = (r) =>
(r.usage_user < 40.0 and r.usage_user > 10.0)
(r["usage_user"] < 40.0 and r["usage_user"] > 10.0)
messageFn = (r) =>
("whoa! {r.usage_user}")
("whoa! {r[\"usage_user\"]}")
data
|> v1.fieldsAsCols()
|> monitor.check(
|> v1["fieldsAsCols"]()
|> monitor["check"](
data: check,
messageFn: messageFn,
ok: ok,
2 changes: 1 addition & 1 deletion notification/flux/ast.go
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ func Add(lhs, rhs ast.Expression) *ast.BinaryExpression {
func Member(p, c string) *ast.MemberExpression {
return &ast.MemberExpression{
Object: &ast.Identifier{Name: p},
Property: &ast.Identifier{Name: c},
Property: String(c),
}
}

54 changes: 27 additions & 27 deletions notification/rule/http_test.go
Original file line number Diff line number Diff line change
@@ -20,26 +20,26 @@ import "experimental"
option task = {name: "foo", every: 1h, offset: 1s}
headers = {"Content-Type": "application/json"}
endpoint = http.endpoint(url: "http://localhost:7777")
endpoint = http["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h)
statuses = monitor["from"](start: -2h)
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
all_statuses = crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: endpoint(mapFn: (r) => {
|> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => {
body = {r with _version: 1}
return {headers: headers, data: json.encode(v: body)}
return {headers: headers, data: json["encode"](v: body)}
}))`

s := &rule.HTTP{
@@ -88,27 +88,27 @@ import "influxdata/influxdb/secrets"
option task = {name: "foo", every: 1h, offset: 1s}
headers = {"Content-Type": "application/json", "Authorization": http.basicAuth(u: secrets.get(key: "000000000000000e-username"), p: secrets.get(key: "000000000000000e-password"))}
endpoint = http.endpoint(url: "http://localhost:7777")
headers = {"Content-Type": "application/json", "Authorization": http["basicAuth"](u: secrets["get"](key: "000000000000000e-username"), p: secrets["get"](key: "000000000000000e-password"))}
endpoint = http["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h)
statuses = monitor["from"](start: -2h)
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
all_statuses = crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: endpoint(mapFn: (r) => {
|> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => {
body = {r with _version: 1}
return {headers: headers, data: json.encode(v: body)}
return {headers: headers, data: json["encode"](v: body)}
}))`
s := &rule.HTTP{
Base: rule.Base{
@@ -163,27 +163,27 @@ import "influxdata/influxdb/secrets"
option task = {name: "foo", every: 1h, offset: 1s}
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + secrets.get(key: "000000000000000e-token")}
endpoint = http.endpoint(url: "http://localhost:7777")
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + secrets["get"](key: "000000000000000e-token")}
endpoint = http["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h)
statuses = monitor["from"](start: -2h)
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
all_statuses = crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: endpoint(mapFn: (r) => {
|> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => {
body = {r with _version: 1}
return {headers: headers, data: json.encode(v: body)}
return {headers: headers, data: json["encode"](v: body)}
}))`

s := &rule.HTTP{
@@ -236,27 +236,27 @@ import "influxdata/influxdb/secrets"
option task = {name: "foo", every: 5s, offset: 1s}
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + secrets.get(key: "000000000000000e-token")}
endpoint = http.endpoint(url: "http://localhost:7777")
headers = {"Content-Type": "application/json", "Authorization": "Bearer " + secrets["get"](key: "000000000000000e-token")}
endpoint = http["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -10s)
statuses = monitor["from"](start: -10s)
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
all_statuses = crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 5s)))
(r["_time"] > experimental["subDuration"](from: now(), d: 5s)))
all_statuses
|> monitor.notify(data: notification, endpoint: endpoint(mapFn: (r) => {
|> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => {
body = {r with _version: 1}
return {headers: headers, data: json.encode(v: body)}
return {headers: headers, data: json["encode"](v: body)}
}))`

s := &rule.HTTP{
80 changes: 40 additions & 40 deletions notification/rule/pagerduty_test.go
Original file line number Diff line number Diff line change
@@ -68,36 +68,36 @@ import "experimental"
option task = {name: "foo", every: 1h}
pagerduty_secret = secrets.get(key: "pagerduty_token")
pagerduty_endpoint = pagerduty.endpoint()
pagerduty_secret = secrets["get"](key: "pagerduty_token")
pagerduty_endpoint = pagerduty["endpoint"]()
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
all_statuses = crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
|> monitor["notify"](data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
({
routingKey: pagerduty_secret,
client: "influxdata",
clientURL: "http://localhost:7777/host/${r.host}",
class: r._check_name,
group: r._source_measurement,
severity: pagerduty.severityFromLevel(level: r._level),
eventAction: pagerduty.actionFromLevel(level: r._level),
source: notification._notification_rule_name,
summary: r._message,
timestamp: time(v: r._source_timestamp),
group: r["_source_measurement"],
severity: pagerduty["severityFromLevel"](level: r["_level"]),
eventAction: pagerduty["actionFromLevel"](level: r["_level"]),
source: notification["_notification_rule_name"],
summary: r["_message"],
timestamp: time(v: r["_source_timestamp"]),
})))`,
},
{
@@ -152,35 +152,35 @@ import "experimental"
option task = {name: "foo", every: 1h}
pagerduty_secret = secrets.get(key: "pagerduty_token")
pagerduty_endpoint = pagerduty.endpoint()
pagerduty_secret = secrets["get"](key: "pagerduty_token")
pagerduty_endpoint = pagerduty["endpoint"]()
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
info_to_crit = statuses
|> monitor.stateChanges(fromLevel: "info", toLevel: "crit")
|> monitor["stateChanges"](fromLevel: "info", toLevel: "crit")
all_statuses = info_to_crit
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
|> monitor["notify"](data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
({
routingKey: pagerduty_secret,
client: "influxdata",
clientURL: "http://localhost:7777/host/${r.host}",
class: r._check_name,
group: r._source_measurement,
severity: pagerduty.severityFromLevel(level: r._level),
eventAction: pagerduty.actionFromLevel(level: r._level),
source: notification._notification_rule_name,
summary: r._message,
timestamp: time(v: r._source_timestamp),
group: r["_source_measurement"],
severity: pagerduty["severityFromLevel"](level: r["_level"]),
eventAction: pagerduty["actionFromLevel"](level: r["_level"]),
source: notification["_notification_rule_name"],
summary: r["_message"],
timestamp: time(v: r["_source_timestamp"]),
})))`,
},
{
@@ -238,39 +238,39 @@ import "experimental"
option task = {name: "foo", every: 1h}
pagerduty_secret = secrets.get(key: "pagerduty_token")
pagerduty_endpoint = pagerduty.endpoint()
pagerduty_secret = secrets["get"](key: "pagerduty_token")
pagerduty_endpoint = pagerduty["endpoint"]()
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
ok_to_warn = statuses
|> monitor.stateChanges(fromLevel: "ok", toLevel: "warn")
|> monitor["stateChanges"](fromLevel: "ok", toLevel: "warn")
all_statuses = union(tables: [crit, ok_to_warn])
|> sort(columns: ["_time"])
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
|> monitor["notify"](data: notification, endpoint: pagerduty_endpoint(mapFn: (r) =>
({
routingKey: pagerduty_secret,
client: "influxdata",
clientURL: "http://localhost:7777/host/${r.host}",
class: r._check_name,
group: r._source_measurement,
severity: pagerduty.severityFromLevel(level: r._level),
eventAction: pagerduty.actionFromLevel(level: r._level),
source: notification._notification_rule_name,
summary: r._message,
timestamp: time(v: r._source_timestamp),
group: r["_source_measurement"],
severity: pagerduty["severityFromLevel"](level: r["_level"]),
eventAction: pagerduty["actionFromLevel"](level: r["_level"]),
source: notification["_notification_rule_name"],
summary: r["_message"],
timestamp: time(v: r["_source_timestamp"]),
})))`,
},
}
64 changes: 32 additions & 32 deletions notification/rule/slack_test.go
Original file line number Diff line number Diff line change
@@ -46,25 +46,25 @@ import "experimental"
option task = {name: "foo", every: 1h}
slack_endpoint = slack.endpoint(url: "http://localhost:7777")
slack_endpoint = slack["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
any = statuses
|> filter(fn: (r) =>
(true))
all_statuses = any
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r._level == "crit" then "danger" else if r._level == "warn" then "warning" else "good"})))`,
|> monitor["notify"](data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r["_level"] == "crit" then "danger" else if r["_level"] == "warn" then "warning" else "good"})))`,
rule: &rule.Slack{
Channel: "bar",
MessageTemplate: "blah",
@@ -115,28 +115,28 @@ import "experimental"
option task = {name: "foo", every: 1h}
slack_endpoint = slack.endpoint(url: "http://localhost:7777")
slack_endpoint = slack["endpoint"](url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
info_to_warn = statuses
|> monitor.stateChanges(fromLevel: "info", toLevel: "warn")
|> monitor["stateChanges"](fromLevel: "info", toLevel: "warn")
all_statuses = union(tables: [crit, info_to_warn])
|> sort(columns: ["_time"])
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r._level == "crit" then "danger" else if r._level == "warn" then "warning" else "good"})))`,
|> monitor["notify"](data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r["_level"] == "crit" then "danger" else if r["_level"] == "warn" then "warning" else "good"})))`,
rule: &rule.Slack{
Channel: "bar",
MessageTemplate: "blah",
@@ -191,29 +191,29 @@ import "experimental"
option task = {name: "foo", every: 1h}
slack_secret = secrets.get(key: "slack_token")
slack_endpoint = slack.endpoint(token: slack_secret)
slack_secret = secrets["get"](key: "slack_token")
slack_endpoint = slack["endpoint"](token: slack_secret)
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
info_to_warn = statuses
|> monitor.stateChanges(fromLevel: "info", toLevel: "warn")
|> monitor["stateChanges"](fromLevel: "info", toLevel: "warn")
all_statuses = union(tables: [crit, info_to_warn])
|> sort(columns: ["_time"])
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r._level == "crit" then "danger" else if r._level == "warn" then "warning" else "good"})))`,
|> monitor["notify"](data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r["_level"] == "crit" then "danger" else if r["_level"] == "warn" then "warning" else "good"})))`,
rule: &rule.Slack{
Channel: "bar",
MessageTemplate: "blah",
@@ -270,29 +270,29 @@ import "experimental"
option task = {name: "foo", every: 1h}
slack_secret = secrets.get(key: "slack_token")
slack_endpoint = slack.endpoint(token: slack_secret, url: "http://localhost:7777")
slack_secret = secrets["get"](key: "slack_token")
slack_endpoint = slack["endpoint"](token: slack_secret, url: "http://localhost:7777")
notification = {
_notification_rule_id: "0000000000000001",
_notification_rule_name: "foo",
_notification_endpoint_id: "0000000000000002",
_notification_endpoint_name: "foo",
}
statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang"))
statuses = monitor["from"](start: -2h, fn: (r) =>
(r["foo"] == "bar" and r["baz"] == "bang"))
crit = statuses
|> filter(fn: (r) =>
(r._level == "crit"))
(r["_level"] == "crit"))
info_to_warn = statuses
|> monitor.stateChanges(fromLevel: "info", toLevel: "warn")
|> monitor["stateChanges"](fromLevel: "info", toLevel: "warn")
all_statuses = union(tables: [crit, info_to_warn])
|> sort(columns: ["_time"])
|> filter(fn: (r) =>
(r._time > experimental.subDuration(from: now(), d: 1h)))
(r["_time"] > experimental["subDuration"](from: now(), d: 1h)))
all_statuses
|> monitor.notify(data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r._level == "crit" then "danger" else if r._level == "warn" then "warning" else "good"})))`,
|> monitor["notify"](data: notification, endpoint: slack_endpoint(mapFn: (r) =>
({channel: "bar", text: "blah", color: if r["_level"] == "crit" then "danger" else if r["_level"] == "warn" then "warning" else "good"})))`,
rule: &rule.Slack{
Channel: "bar",
MessageTemplate: "blah",
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ const FunctionCategory: SFC<Props> = props => {
{funcs.map(func => (
<ToolbarFunction
onClickFunction={onClickFunction}
key={func.name}
key={`${func.name}_${func.desc}`}
func={func}
testID="toolbar-function"
/>

0 comments on commit 4f65cda

Please sign in to comment.