refactor(notification): rename alerts package to monitor in flux (#14788)
parent
fcfdd2b1ef
commit
c7bbfbe293
2
go.mod
2
go.mod
|
@ -38,7 +38,7 @@ require (
|
|||
github.com/hashicorp/go-msgpack v0.0.0-20150518234257-fa3f63826f7c // indirect
|
||||
github.com/hashicorp/raft v1.0.0 // indirect
|
||||
github.com/hashicorp/vault/api v1.0.2
|
||||
github.com/influxdata/flux v0.40.2-0.20190823192708-9e4b4447fced
|
||||
github.com/influxdata/flux v0.40.2-0.20190823211512-ec418d051ff0
|
||||
github.com/influxdata/influxql v0.0.0-20180925231337-1cbfca8e56b6
|
||||
github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368
|
||||
github.com/jessevdk/go-flags v1.4.0
|
||||
|
|
10
go.sum
10
go.sum
|
@ -206,14 +206,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/changelog v1.0.0 h1:RstJD6H48zLQj0GdE6E6k/6RPwtUjkyzIe/T1E/xuWU=
|
||||
github.com/influxdata/changelog v1.0.0/go.mod h1:uzpGWE/qehT8L426YuXwpMQub+a63vIINhIeEI9mnSM=
|
||||
github.com/influxdata/flux v0.40.2-0.20190822171407-6cd0e564d565 h1:bJ8xPpg47UxkZOUpcWEu+i66Z62KVe7aO4dOFvQFCDk=
|
||||
github.com/influxdata/flux v0.40.2-0.20190822171407-6cd0e564d565/go.mod h1:QvF9P06HFgYKD28Z556rFLJ0D0bvtcgEtkFALteZ4Lo=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823181615-72aaca00d4a1 h1:mpJ1He55c+dkI7gA1pteZK5SnGYLf7EG5eCD7UCwvEI=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823181615-72aaca00d4a1/go.mod h1:QvF9P06HFgYKD28Z556rFLJ0D0bvtcgEtkFALteZ4Lo=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823192708-9e4b4447fced h1:Ac4/pTd5k4otnguJJ76GXIptN6awdsupIT8v2dnu5lY=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823192708-9e4b4447fced/go.mod h1:QvF9P06HFgYKD28Z556rFLJ0D0bvtcgEtkFALteZ4Lo=
|
||||
github.com/influxdata/flux v0.40.2 h1:7teoRiHtdh7uaAg4YpwKkY4GK2oK0HjYA9uFnfx+EsQ=
|
||||
github.com/influxdata/flux v0.40.2/go.mod h1:QvF9P06HFgYKD28Z556rFLJ0D0bvtcgEtkFALteZ4Lo=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823211512-ec418d051ff0 h1:mLoY05dhJ5ZsEMuhtlgWt64QH0sBs7WSYSj6wkfiL0k=
|
||||
github.com/influxdata/flux v0.40.2-0.20190823211512-ec418d051ff0/go.mod h1:QvF9P06HFgYKD28Z556rFLJ0D0bvtcgEtkFALteZ4Lo=
|
||||
github.com/influxdata/goreleaser v0.97.0-influx h1:jT5OrcW7WfS0e2QxfwmTBjhLvpIC9CDLRhNgZJyhj8s=
|
||||
github.com/influxdata/goreleaser v0.97.0-influx/go.mod h1:MnjA0e0Uq6ISqjG1WxxMAl+3VS1QYjILSWVnMYDxasE=
|
||||
github.com/influxdata/influxql v0.0.0-20180925231337-1cbfca8e56b6 h1:CFx+pP90q/qg3spoiZjf8donE4WpAdjeJfPOcoNqkWo=
|
||||
|
|
|
@ -224,7 +224,7 @@ func (t Threshold) GenerateFluxASTReal() (*ast.Package, error) {
|
|||
f := p.Files[0]
|
||||
assignPipelineToData(f)
|
||||
|
||||
f.Imports = append(f.Imports, flux.Imports("influxdata/influxdb/alerts", "influxdata/influxdb/v1")...)
|
||||
f.Imports = append(f.Imports, flux.Imports("influxdata/influxdb/monitor", "influxdata/influxdb/v1")...)
|
||||
f.Body = append(f.Body, t.generateFluxASTBody()...)
|
||||
|
||||
return p, nil
|
||||
|
@ -283,7 +283,7 @@ func (t Threshold) generateFluxASTChecksCall() *ast.CallExpression {
|
|||
objectProps = append(objectProps, flux.Property(lvl, flux.Identifier(lvl)))
|
||||
}
|
||||
|
||||
return flux.Call(flux.Member("alerts", "check"), flux.Object(objectProps...))
|
||||
return flux.Call(flux.Member("monitor", "check"), flux.Object(objectProps...))
|
||||
}
|
||||
|
||||
func (t Threshold) generateFluxASTCheckDefinition() ast.Statement {
|
||||
|
|
|
@ -76,7 +76,7 @@ func TestThreshold_GenerateFlux(t *testing.T) {
|
|||
},
|
||||
wants: wants{
|
||||
script: `package main
|
||||
import "influxdata/influxdb/alerts"
|
||||
import "influxdata/influxdb/monitor"
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
data = from(bucket: "foo")
|
||||
|
@ -104,7 +104,7 @@ messageFn = (r, check) =>
|
|||
|
||||
data
|
||||
|> v1.fieldsAsCols()
|
||||
|> alerts.check(
|
||||
|> monitor.check(
|
||||
data: check,
|
||||
messageFn: messageFn,
|
||||
ok: ok,
|
||||
|
@ -165,7 +165,7 @@ data
|
|||
},
|
||||
wants: wants{
|
||||
script: `package main
|
||||
import "influxdata/influxdb/alerts"
|
||||
import "influxdata/influxdb/monitor"
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
data = from(bucket: "foo")
|
||||
|
@ -193,7 +193,7 @@ messageFn = (r, check) =>
|
|||
|
||||
data
|
||||
|> v1.fieldsAsCols()
|
||||
|> alerts.check(
|
||||
|> monitor.check(
|
||||
data: check,
|
||||
messageFn: messageFn,
|
||||
ok: ok,
|
||||
|
@ -254,7 +254,7 @@ data
|
|||
},
|
||||
wants: wants{
|
||||
script: `package main
|
||||
import "influxdata/influxdb/alerts"
|
||||
import "influxdata/influxdb/monitor"
|
||||
import "influxdata/influxdb/v1"
|
||||
|
||||
data = from(bucket: "foo")
|
||||
|
@ -282,7 +282,7 @@ messageFn = (r, check) =>
|
|||
|
||||
data
|
||||
|> v1.fieldsAsCols()
|
||||
|> alerts.check(
|
||||
|> monitor.check(
|
||||
data: check,
|
||||
messageFn: messageFn,
|
||||
ok: ok,
|
||||
|
@ -297,7 +297,7 @@ data
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// TODO(desa): change this to GenerateFlux() when we don't need to code
|
||||
// around the alerts package not being available.
|
||||
// around the monitor package not being available.
|
||||
p, err := tt.args.threshold.GenerateFluxASTReal()
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
|
|
@ -27,7 +27,7 @@ func (s *HTTP) GenerateFlux(e influxdb.NotificationEndpoint) (string, error) {
|
|||
func (s *HTTP) GenerateFluxAST() (*ast.Package, error) {
|
||||
f := flux.File(
|
||||
s.Name,
|
||||
flux.Imports("influxdata/influxdb/alerts", "http", "json"),
|
||||
flux.Imports("influxdata/influxdb/monitor", "http", "json"),
|
||||
s.generateFluxASTBody(),
|
||||
)
|
||||
return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil
|
||||
|
@ -95,7 +95,7 @@ func (s *HTTP) generateFluxASTStatuses() ast.Statement {
|
|||
props = append(props, flux.Property("fn", flux.Function(flux.FunctionParams("r"), body)))
|
||||
}
|
||||
|
||||
base := flux.Call(flux.Member("alerts", "from"), flux.Object(props...))
|
||||
base := flux.Call(flux.Member("monitor", "from"), flux.Object(props...))
|
||||
|
||||
return flux.DefineVariable("statuses", base)
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ func (s *HTTP) generateFluxASTNotifyPipe() ast.Statement {
|
|||
props = append(props, flux.Property("endpoint",
|
||||
flux.Call(flux.Identifier("endpoint"), flux.Object(flux.Property("mapFn", endpointFn)))))
|
||||
|
||||
call := flux.Call(flux.Member("alerts", "notify"), flux.Object(props...))
|
||||
call := flux.Call(flux.Member("monitor", "notify"), flux.Object(props...))
|
||||
|
||||
return flux.ExpressionStatement(flux.Pipe(flux.Identifier("statuses"), call))
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
func TestHTTP_GenerateFlux(t *testing.T) {
|
||||
want := `package main
|
||||
// foo
|
||||
import "influxdata/influxdb/alerts"
|
||||
import "influxdata/influxdb/monitor"
|
||||
import "http"
|
||||
import "json"
|
||||
|
||||
|
@ -23,11 +23,11 @@ notification = {
|
|||
_notification_endpoint_id: "0000000000000002",
|
||||
_notification_endpoint_name: "http-endpoint",
|
||||
}
|
||||
statuses = alerts.from(start: -1h, fn: (r) =>
|
||||
statuses = monitor.from(start: -1h, fn: (r) =>
|
||||
(r.foo == "bar" and r.baz == "bang"))
|
||||
|
||||
statuses
|
||||
|> alerts.notify(name: "foo", data: notification, endpoint: endpoint(mapFn: (r) =>
|
||||
|> monitor.notify(name: "foo", data: notification, endpoint: endpoint(mapFn: (r) =>
|
||||
({data: json.encode(v: r)})))`
|
||||
|
||||
s := &rule.HTTP{
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/influxdata/flux/ast"
|
||||
|
||||
"github.com/influxdata/influxdb"
|
||||
"github.com/influxdata/influxdb/notification"
|
||||
"github.com/influxdata/influxdb/notification/flux"
|
||||
|
@ -41,7 +40,7 @@ func (s *Slack) GenerateFluxReal(e influxdb.NotificationEndpoint) (string, error
|
|||
func (s *Slack) GenerateFluxAST() (*ast.Package, error) {
|
||||
f := flux.File(
|
||||
s.Name,
|
||||
flux.Imports("influxdata/influxdb/alerts", "slack", "secrets"),
|
||||
flux.Imports("influxdata/influxdb/monitor", "slack", "secrets"),
|
||||
s.generateFluxASTBody(),
|
||||
)
|
||||
return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil
|
||||
|
@ -136,7 +135,7 @@ func (s *Slack) generateFluxASTNotifyPipe() ast.Statement {
|
|||
props = append(props, flux.Property("endpoint",
|
||||
flux.Call(flux.Identifier("slack_endpoint"), flux.Object(flux.Property("mapFn", endpointFn)))))
|
||||
|
||||
call := flux.Call(flux.Member("alerts", "notify"), flux.Object(props...))
|
||||
call := flux.Call(flux.Member("monitor", "notify"), flux.Object(props...))
|
||||
|
||||
return flux.ExpressionStatement(flux.Pipe(flux.Identifier("statuses"), call))
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func mustDuration(d string) *notification.Duration {
|
|||
func TestSlack_GenerateFlux(t *testing.T) {
|
||||
want := `package main
|
||||
// foo
|
||||
import "influxdata/influxdb/alerts"
|
||||
import "influxdata/influxdb/monitor"
|
||||
import "slack"
|
||||
import "secrets"
|
||||
|
||||
|
@ -37,7 +37,7 @@ statuses = from(bucket: "system_bucket")
|
|||
(r.baz == "bang"))
|
||||
|
||||
statuses
|
||||
|> alerts.notify(name: "foo", notification: notification, endpoint: slack_endpoint(mapFn: (r) =>
|
||||
|> monitor.notify(name: "foo", notification: notification, endpoint: slack_endpoint(mapFn: (r) =>
|
||||
({channel: "bar", text: "blah"})))`
|
||||
|
||||
s := &rule.Slack{
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/flux/parser"
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/ast"
|
||||
"github.com/influxdata/flux/dependencies"
|
||||
"github.com/influxdata/flux"
|
||||
"github.com/influxdata/flux/parser"
|
||||
"github.com/influxdata/flux/semantic"
|
||||
"github.com/influxdata/flux/values"
|
||||
"github.com/influxdata/influxdb/pkg/pointer"
|
||||
|
|
Loading…
Reference in New Issue