diff --git a/go.mod b/go.mod index 19e59b937f..6f323a38d2 100644 --- a/go.mod +++ b/go.mod @@ -37,7 +37,7 @@ require ( github.com/hashicorp/vault/api v1.0.2 github.com/imdario/mergo v0.3.9 // indirect github.com/influxdata/cron v0.0.0-20201006132531-4bb0a200dcbe - github.com/influxdata/flux v0.139.0 + github.com/influxdata/flux v0.140.0 github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 github.com/influxdata/influxql v1.1.1-0.20211004132434-7e7d61973256 github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 diff --git a/go.sum b/go.sum index 4c2e4ddbc6..ce9612e9e1 100644 --- a/go.sum +++ b/go.sum @@ -426,8 +426,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/cron v0.0.0-20201006132531-4bb0a200dcbe h1:7j4SdN/BvQwN6WoUq7mv0kg5U9NhnFBxPGMafYRKym0= github.com/influxdata/cron v0.0.0-20201006132531-4bb0a200dcbe/go.mod h1:XabtPPW2qsCg0tl+kjaPU+cFS+CjQXEXbT1VJvHT4og= -github.com/influxdata/flux v0.139.0 h1:xCvnfaYG9ShrHqRH2BP3K/75a4zS2gTeNV81n7zM1sc= -github.com/influxdata/flux v0.139.0/go.mod h1:Q1kyXp+qkeAkX0T8wiNKCU7lqtEep1aK7QqrXntPPD4= +github.com/influxdata/flux v0.140.0 h1:0iwqUeJLGPN18URgpPRYSoygqJ+iXQJeMyqNXPtWIII= +github.com/influxdata/flux v0.140.0/go.mod h1:Q1kyXp+qkeAkX0T8wiNKCU7lqtEep1aK7QqrXntPPD4= github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 h1:WQsmW0fXO4ZE/lFGIE84G6rIV5SJN3P3sjIXAP1a8eU= github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69/go.mod h1:pwymjR6SrP3gD3pRj9RJwdl1j5s3doEEV8gS4X9qSzA= github.com/influxdata/influx-cli/v2 v2.1.1-0.20211007122339-c4a5a13c8ee3 h1:DJFtOP/Gji5K6iut794K1pTKPd9SqM9J+Cb7vXgsnq0= diff --git a/notification/rule/http_test.go b/notification/rule/http_test.go index 2f445bd2c7..7219d826fe 100644 --- a/notification/rule/http_test.go +++ b/notification/rule/http_test.go @@ -3,6 +3,7 @@ package rule_test import ( "testing" + "github.com/andreyvit/diff" "github.com/influxdata/influxdb/v2" "github.com/influxdata/influxdb/v2/kit/platform" "github.com/influxdata/influxdb/v2/notification" @@ -27,11 +28,16 @@ statuses = monitor["from"](start: -2h) crit = statuses |> filter(fn: (r) => r["_level"] == "crit") all_statuses = crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 1h)) -all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => { - body = {r with _version: 1} - - return {headers: headers, data: json["encode"](v: body)} -}))` +all_statuses |> monitor["notify"]( + data: notification, + endpoint: endpoint( + mapFn: (r) => { + body = {r with _version: 1} + + return {headers: headers, data: json["encode"](v: body)} + }, + ), +)` s := &rule.HTTP{ Base: rule.Base{ @@ -64,7 +70,7 @@ all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: } if f != want { - t.Errorf("scripts did not match. want:\n%v\n\ngot:\n%v", want, f) + t.Errorf("\n\nScripts did not match:\n\n%s", diff.LineDiff(f, want)) } } @@ -84,11 +90,16 @@ statuses = monitor["from"](start: -2h) crit = statuses |> filter(fn: (r) => r["_level"] == "crit") all_statuses = crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 1h)) -all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => { - body = {r with _version: 1} - - return {headers: headers, data: json["encode"](v: body)} -}))` +all_statuses |> monitor["notify"]( + data: notification, + endpoint: endpoint( + mapFn: (r) => { + body = {r with _version: 1} + + return {headers: headers, data: json["encode"](v: body)} + }, + ), +)` s := &rule.HTTP{ Base: rule.Base{ ID: 1, @@ -127,7 +138,7 @@ all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: } if f != want { - t.Errorf("scripts did not match. want:\n%v\n\ngot:\n%v", want, f) + t.Errorf("\n\nScripts did not match:\n\n%s", diff.LineDiff(f, want)) } } @@ -147,11 +158,16 @@ statuses = monitor["from"](start: -2h) crit = statuses |> filter(fn: (r) => r["_level"] == "crit") all_statuses = crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 1h)) -all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => { - body = {r with _version: 1} - - return {headers: headers, data: json["encode"](v: body)} -}))` +all_statuses |> monitor["notify"]( + data: notification, + endpoint: endpoint( + mapFn: (r) => { + body = {r with _version: 1} + + return {headers: headers, data: json["encode"](v: body)} + }, + ), +)` s := &rule.HTTP{ Base: rule.Base{ @@ -188,7 +204,7 @@ all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: } if f != want { - t.Errorf("scripts did not match. want:\n%v\n\ngot:\n%v", want, f) + t.Errorf("\n\nScripts did not match:\n\n%s", diff.LineDiff(f, want)) } } @@ -208,11 +224,16 @@ statuses = monitor["from"](start: -10s) crit = statuses |> filter(fn: (r) => r["_level"] == "crit") all_statuses = crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 5s)) -all_statuses |> monitor["notify"](data: notification, endpoint: endpoint(mapFn: (r) => { - body = {r with _version: 1} - - return {headers: headers, data: json["encode"](v: body)} -}))` +all_statuses |> monitor["notify"]( + data: notification, + endpoint: endpoint( + mapFn: (r) => { + body = {r with _version: 1} + + return {headers: headers, data: json["encode"](v: body)} + }, + ), +)` s := &rule.HTTP{ Base: rule.Base{ diff --git a/notification/rule/pagerduty_test.go b/notification/rule/pagerduty_test.go index 5b9e53560f..9b10efe3e2 100644 --- a/notification/rule/pagerduty_test.go +++ b/notification/rule/pagerduty_test.go @@ -73,18 +73,23 @@ statuses = monitor["from"](start: -2h, fn: (r) => r["foo"] == "bar" and r["baz"] crit = statuses |> filter(fn: (r) => r["_level"] == "crit") all_statuses = crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 1h)) -all_statuses |> 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"]), -})))`, +all_statuses |> 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"]), + }), + ), +)`, }, { name: "notify on info to crit", @@ -143,18 +148,23 @@ statuses = monitor["from"](start: -2h, fn: (r) => r["foo"] == "bar" and r["baz"] info_to_crit = statuses |> monitor["stateChanges"](fromLevel: "info", toLevel: "crit") all_statuses = info_to_crit |> filter(fn: (r) => r["_time"] >= experimental["subDuration"](from: now(), d: 1h)) -all_statuses |> 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"]), -})))`, +all_statuses |> 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"]), + }), + ), +)`, }, { name: "notify on crit or ok to warn", @@ -217,18 +227,23 @@ crit = statuses |> filter(fn: (r) => r["_level"] == "crit") ok_to_warn = statuses |> 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)) -all_statuses |> 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"]), -})))`, +all_statuses |> 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"]), + }), + ), +)`, }, }