fix(notification/rule): pivot table from monitor

pull/14934/head
Michael Desa 2019-09-04 20:33:53 -04:00
parent 07e7309c48
commit 5ff6f8b9ca
No known key found for this signature in database
GPG Key ID: 87002651EC5DFFE6
5 changed files with 10 additions and 3 deletions

View File

@ -32,7 +32,7 @@ func (s *HTTP) GenerateFlux(e influxdb.NotificationEndpoint) (string, error) {
func (s *HTTP) GenerateFluxAST(e *endpoint.HTTP) (*ast.Package, error) { func (s *HTTP) GenerateFluxAST(e *endpoint.HTTP) (*ast.Package, error) {
f := flux.File( f := flux.File(
s.Name, s.Name,
flux.Imports("influxdata/influxdb/monitor", "http", "json", "experimental"), flux.Imports("influxdata/influxdb/monitor", "http", "json", "experimental", "influxdata/influxdb/v1"),
s.generateFluxASTBody(e), s.generateFluxASTBody(e),
) )
return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil

View File

@ -16,6 +16,7 @@ import "influxdata/influxdb/monitor"
import "http" import "http"
import "json" import "json"
import "experimental" import "experimental"
import "influxdata/influxdb/v1"
option task = {name: "foo", every: 2h, offset: 1s} option task = {name: "foo", every: 2h, offset: 1s}
@ -28,6 +29,7 @@ notification = {
} }
statuses = monitor.from(start: -2h, fn: (r) => statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang")) (r.foo == "bar" and r.baz == "bang"))
|> v1.fieldsAsCols()
any_to_crit = statuses any_to_crit = statuses
|> monitor.stateChanges(fromLevel: "any", toLevel: "crit") |> monitor.stateChanges(fromLevel: "any", toLevel: "crit")
all_statuses = any_to_crit all_statuses = any_to_crit

View File

@ -263,7 +263,10 @@ func (b *Base) generateFluxASTStatuses() ast.Statement {
props = append(props, flux.Property("fn", flux.Function(flux.FunctionParams("r"), body))) props = append(props, flux.Property("fn", flux.Function(flux.FunctionParams("r"), body)))
} }
base := flux.Call(flux.Member("monitor", "from"), flux.Object(props...)) base := flux.Pipe(
flux.Call(flux.Member("monitor", "from"), flux.Object(props...)),
flux.Call(flux.Member("v1", "fieldsAsCols"), flux.Object()),
)
return flux.DefineVariable("statuses", base) return flux.DefineVariable("statuses", base)
} }

View File

@ -34,7 +34,7 @@ func (s *Slack) GenerateFlux(e influxdb.NotificationEndpoint) (string, error) {
func (s *Slack) GenerateFluxAST(e *endpoint.Slack) (*ast.Package, error) { func (s *Slack) GenerateFluxAST(e *endpoint.Slack) (*ast.Package, error) {
f := flux.File( f := flux.File(
s.Name, s.Name,
flux.Imports("influxdata/influxdb/monitor", "slack", "influxdata/influxdb/secrets", "experimental"), flux.Imports("influxdata/influxdb/monitor", "slack", "influxdata/influxdb/secrets", "experimental", "influxdata/influxdb/v1"),
s.generateFluxASTBody(e), s.generateFluxASTBody(e),
) )
return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil return &ast.Package{Package: "main", Files: []*ast.File{f}}, nil

View File

@ -30,6 +30,7 @@ import "influxdata/influxdb/monitor"
import "slack" import "slack"
import "influxdata/influxdb/secrets" import "influxdata/influxdb/secrets"
import "experimental" import "experimental"
import "influxdata/influxdb/v1"
option task = {name: "foo", every: 2h} option task = {name: "foo", every: 2h}
@ -43,6 +44,7 @@ notification = {
} }
statuses = monitor.from(start: -2h, fn: (r) => statuses = monitor.from(start: -2h, fn: (r) =>
(r.foo == "bar" and r.baz == "bang")) (r.foo == "bar" and r.baz == "bang"))
|> v1.fieldsAsCols()
any_to_crit = statuses any_to_crit = statuses
|> monitor.stateChanges(fromLevel: "any", toLevel: "crit") |> monitor.stateChanges(fromLevel: "any", toLevel: "crit")
info_to_warn = statuses info_to_warn = statuses