Merge pull request #435 from influxdata/flux-0.41

Flux 0.41
pull/441/head
Scott Anderson 2019-09-05 11:25:03 -06:00 committed by GitHub
commit 799880417d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 825 additions and 15 deletions

View File

@ -26,26 +26,24 @@ range(start: -15m, stop: now())
## Parameters
### start
Specifies the oldest time to be included in the results.
The earliest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
Relative start times are defined using negative durations.
Negative durations are relative to now.
Absolute start times are defined using timestamps.
_**Data type:** Duration or Timestamp_
_**Data type:** Duration | Time_
### stop
Specifies the newest time to be included in the results. Defaults to `now`.
The latest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
Defaults to `now()`.
Relative stop times are defined using negative durations.
Negative durations are relative to now.
Absolute stop times are defined using timestamps.
_**Data type:** Duration or Timestamp_
_**Data type:** Duration | Time_
{{% note %}}
Flux only honors [RFC3339 timestamps](/v2.0/reference/flux/language/types#timestamp-format)
and ignores dates and times provided in other formats.
Time values in Flux must be in [RFC3339 format](/v2.0/reference/flux/language/types#timestamp-format).
{{% /note %}}
## Examples

View File

@ -0,0 +1,22 @@
---
title: Flux HTTP package
list_title: HTTP package
description: >
The Flux HTTP package provides functions for transferring data using the HTTP protocol.
Import the `http` package.
menu:
v2_0_ref:
name: HTTP
parent: Flux packages and functions
weight: 202
v2.0/tags: [functions, http, package]
---
The Flux HTTP package provides functions for transferring data using the HTTP protocol.
Import the `http` package:
```js
import "http"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,63 @@
---
title: http.endpoint() function
description: >
The `http.endpoint()` function sends output data to an HTTP URL using the POST request method.
menu:
v2_0_ref:
name: http.endpoint
parent: HTTP
weight: 202
---
The `http.endpoint()` function sends output data to an HTTP URL using the POST request method.
_**Function type:** Output_
```js
import "http"
http.endpoint(
url: "http://localhost:1234/"
)
```
## Parameters
### url
The URL to POST to.
_**Data type:** String_
### mapFn
A function that builds the object used to generate the POST request.
{{% note %}}
_You should rarely need to override the default `mapFn` parameter.
To see the default `mapFn` value or for insight into possible overrides, view the
[`http.endpoint()` source code](https://github.com/influxdata/flux/blob/master/stdlib/http/http.flux)._
{{% /note %}}
_**Data type:** Function_
The returned object must include the following fields:
- `headers`
- `data`
_For more information, see [`http.post()`](/v2.0/reference/flux/functions/http/post/)_
## Examples
##### Send critical statuses to an HTTP endpoint
```js
import "monitor"
import "http"
endpoint = http.endpoint(url: "http://myawsomeurl.com/api/notify")
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
|> map(fn: (r) => { return {status: r._status} })
|> monitor.notify(endpoint: endpoint)
```

View File

@ -0,0 +1,64 @@
---
title: http.post() function
description: >
The `http.post()` function submits an HTTP POST request to the specified URL with headers and data.
The HTTP status code is returned.
menu:
v2_0_ref:
name: http.post
parent: HTTP
weight: 202
---
The `http.post()` function submits an HTTP POST request to the specified URL with
headers and data and returns the HTTP status code.
_**Function type:** Output_
```js
import "http"
http.post(
url: "http://localhost:9999/",
headers: {x:"a", y:"b", z:"c"},
data: bytes(v: "body")
)
```
## Parameters
### url
The URL to POST to.
_**Data type:** String_
### headers
Headers to include with the POST request.
_**Data type:** Object_
### data
The data body to include with the POST request.
_**Data type:** Bytes_
## Examples
##### Send the last reported status to a URL
```js
import "json"
import "http"
lastReported =
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses")
|> last()
|> map(fn: (r) => { return {status: r._status} })
http.post(
url: "http://myawsomeurl.com/api/notify",
headers: {Authorization: "Bearer mySuPerSecRetTokEn"},
data: bytes(v: lastReported)
)
```

View File

@ -0,0 +1,22 @@
---
title: Flux InfluxDB Monitor package
list_title: InfluxDB Monitor package
description: >
The Flux Monitor package provides tools for monitoring and alerting with InfluxDB.
Import the `influxdata/influxdb/monitor` package.
menu:
v2_0_ref:
name: InfluxDB Monitor
parent: Flux packages and functions
weight: 202
v2.0/tags: [functions, monitor, alerts, package]
---
The Flux monitor package provides tools for monitoring and alerting with InfluxDB.
Import the `influxdata/influxdb/monitor` package:
```js
import "influxdata/influxdb/monitor"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,95 @@
---
title: monitor.check() function
description: >
The `monitor.check()` function function checks input data and assigns a level
(`ok`, `info`, `warn`, or `crit`) to each row based on predicate functions.
menu:
v2_0_ref:
name: monitor.check
parent: InfluxDB Monitor
weight: 202
---
The `monitor.check()` function function checks input data and assigns a level
(`ok`, `info`, `warn`, or `crit`) to each row based on predicate functions.
_**Function type:** Transformation_
```js
import "influxdata/influxdb/monitor"
monitor.check(
crit: (r) => r._value > 90.0,
warn: (r) => r._value > 80.0,
info: (r) => r._value > 60.0,
ok: (r) => r._value <= 20.0,
messageFn: (r) => "The current level is ${r._level}",
data: {}
)
```
`monitor.check()` stores statuses in the `_level` column and writes results
to the `statuses` measurement in the `_monitoring` bucket.
## Parameters
### crit
Predicate function that determines `crit` status.
Default is `(r) => false`.
_**Data type:** Function_
### warn
Predicate function that determines `warn` status.
Default is `(r) => false`.
_**Data type:** Function_
### info
Predicate function that determines `info` status.
Default is `(r) => false`.
_**Data type:** Function_
### ok
Predicate function that determines `ok` status.
Default is `(r) => true`.
_**Data type:** Function_
### messageFn
A function that constructs a message to append to each row.
The message is stored in the `_message` column.
_**Data type:** Function_
### data
Data to append to the output.
**InfluxDB populates check data.**
_**Data type:** Object_
## Examples
### Monitor disk usage
```js
import "influxdata/influxdb/monitor"
from(bucket: "telegraf")
|> range(start: -1h)
|> filter(fn: (r) =>
r._measurement == "disk" and
r._field = "used_percent"
)
|> monitor.check(
crit: (r) => r._value > 90.0,
warn: (r) => r._value > 80.0,
info: (r) => r._value > 70.0,
ok: (r) => r._value <= 60.0,
messageFn: (r) =>
if r._level == "crit" then "Critical alert!! Disk usage is at ${r._value}%!"
else if r._level == "warn" then "Warning! Disk usage is at ${r._value}%."
else if r._level == "info" then "Disk usage is at ${r._value}%."
else "Things are looking good."
)
```

View File

@ -0,0 +1,46 @@
---
title: monitor.deadman() function
description: >
The `monitor.deadman()` function detects when a group stops reporting data.
menu:
v2_0_ref:
name: monitor.deadman
parent: InfluxDB Monitor
weight: 202
cloud_all: true
---
The `monitor.deadman()` function detects when a group stops reporting data.
It takes a stream of tables and reports if groups have been observed since time `t`.
_**Function type:** Transformation_
```js
import "influxdata/influxdb/monitor"
monitor.deadman(t: 2019-08-30T12:30:00Z)
```
`monitor.deadman()` retains the most recent row from each input table and adds a `dead` column.
If a record appears **after** time `t`, `monitor.deadman()` sets `dead` to `false`.
Otherwise, `dead` is set to `true`.
## Parameters
### t
The time threshold for the deadman check.
_**Data type:** Time_
## Examples
### Detect if a host hasn't reported in the last five minutes
```js
import "influxdata/influxdb/monitor"
import "experimental"
from(bucket: "example-bucket")
|> range(start: -10m)
|> group(columns: ["host"])
|> monitor.deadman(t: experimental.subDuration(d: 5m, from: now() ))
```

View File

@ -0,0 +1,67 @@
---
title: monitor.from() function
description: >
The `monitor.from()` function retrieves check statuses stored in the `_monitoring` bucket.
menu:
v2_0_ref:
name: monitor.from
parent: InfluxDB Monitor
weight: 202
---
The `monitor.from()` function retrieves check statuses stored in the `_monitoring` bucket.
_**Function type:** Input_
```js
import "influxdata/influxdb/monitor"
monitor.from(
start: -1h,
stop: now(),
fn: (r) => true
)
```
## Parameters
### start
The earliest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
_**Data type:** Duration | Time_
### stop
The latest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
Defaults to `now()`.
_**Data type:** Duration | Time_
{{% note %}}
Time values in Flux must be in [RFC3339 format](/v2.0/reference/flux/language/types#timestamp-format).
{{% /note %}}
### fn
A single argument predicate function that evaluates `true` or `false`.
Records or rows (`r`) that evaluate to `true` are included in output tables.
Records that evaluate to _null_ or `false` are not included in output tables.
_**Data type:** Function_
## Examples
### View critical check statuses from the last hour
```js
import "influxdata/influxdb/monitor"
monitor.from(
start: -1h,
fn: (r) => r._level == "crit"
)
```

View File

@ -0,0 +1,63 @@
---
title: monitor.logs() function
description: >
The `monitor.logs()` function retrieves notification events stored in the `_monitoring` bucket.
menu:
v2_0_ref:
name: monitor.logs
parent: InfluxDB Monitor
weight: 202
---
The `monitor.logs()` function retrieves notification events stored in the `_monitoring` bucket.
_**Function type:** Input_
```js
import "influxdata/influxdb/monitor"
monitor.logs(
start: -1h,
stop: now(),
fn: (r) => true
)
```
## Parameters
### start
The earliest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
_**Data type:** Duration | Time_
### stop
The latest time to include in results.
Use a relative duration or absolute time.
For example, `-1h` or `2019-08-28T22:00:00Z`.
Durations are relative to `now()`.
Defaults to `now()`.
_**Data type:** Duration | Time_
{{% note %}}
Time values in Flux must be in [RFC3339 format](/v2.0/reference/flux/language/types#timestamp-format).
{{% /note %}}
### fn
A single argument predicate function that evaluates `true` or `false`.
Records or rows (`r`) that evaluate to `true` are included in output tables.
Records that evaluate to _null_ or `false` are not included in output tables.
_**Data type:** Function_
## Examples
### Query notification events from the last hour
```js
import "influxdata/influxdb/monitor"
monitor.logs(start: -1h)
```

View File

@ -0,0 +1,52 @@
---
title: monitor.notify() function
description: >
The `monitor.notify()` function sends a notification to an endpoint and logs it
in the `notifications` measurement in the `_monitoring` bucket.
menu:
v2_0_ref:
name: monitor.notify
parent: InfluxDB Monitor
weight: 202
---
The `monitor.notify()` function sends a notification to an endpoint and logs it
in the `notifications` measurement in the `_monitoring` bucket.
_**Function type:** Output_
```js
import "influxdata/influxdb/monitor"
monitor.notify(
endpoint: endpoint,
data: {}
)
```
## Parameters
### endpoint
A function that constructs and sends the notification to an endpoint.
_**Data type:** Function_
### data
Data to append to the output.
**InfluxDB populates notification data.**
_**Data type:** Object_
## Examples
### Send a notification to Slack
```js
import "influxdata/influxdb/monitor"
import "slack"
endpoint = slack.endpoint(name: "slack", channel: "#flux")
from(bucket: "system")
|> range(start: -5m)
|> monitor.notify(endpoint: endpoint)
```

View File

@ -0,0 +1,22 @@
---
title: Flux InfluxDB Secrets package
list_title: InfluxDB Secrets package
description: >
The Flux InfluxDB Secrets package provides functions for working with sensitive secrets managed by InfluxDB.
Import the `influxdata/influxdb/secrets` package.
menu:
v2_0_ref:
name: InfluxDB Secrets
parent: Flux packages and functions
weight: 202
v2.0/tags: [functions, secrets, package]
---
InfluxDB Secrets Flux functions provide tools for working with sensitive secrets managed by InfluxDB.
Import the `influxdata/influxdb/secrets` package:
```js
import "influxdata/influxdb/secrets"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,44 @@
---
title: secrets.get() function
description: >
The `secrets.get()` function retrieves a secret from the InfluxDB secret store.
menu:
v2_0_ref:
name: secrets.get
parent: InfluxDB Secrets
weight: 202
---
The `secrets.get()` function retrieves a secret from the InfluxDB secret store.
_**Function type:** Miscellaneous_
```js
import "influxdata/influxdb/secrets"
secrets.get(key: "KEY_NAME")
```
## Parameters
### key
The secret key to retrieve.
_**Data type:** String_
## Examples
### Populate sensitive credentials with secrets
```js
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USERNAME")
password = secrets.get(key: "POSTGRES_PASSWORD")
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost",
query:"SELECT * FROM example-table"
)
```

View File

@ -0,0 +1,22 @@
---
title: Flux Slack package
list_title: Slack package
description: >
The Flux Slack package provides functions for sending data to Slack.
Import the `slack` package.
menu:
v2_0_ref:
name: Slack
parent: Flux packages and functions
weight: 202
v2.0/tags: [functions, slack, package]
---
The Flux Slack package provides functions for sending data to Slack.
Import the `slack` package:
```js
import "slack"
```
{{< children type="functions" show="pages" >}}

View File

@ -0,0 +1,85 @@
---
title: slack.endpoint() function
description: >
The `slack.endpoint()` function sends a message to Slack that includes output data.
menu:
v2_0_ref:
name: slack.endpoint
parent: Slack
weight: 202
---
The `slack.endpoint()` function sends a message to Slack that includes output data.
_**Function type:** Output_
```js
import "slack"
slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "mySuPerSecRetTokEn"
)
```
## Parameters
### url
The Slack API URL.
Defaults to `https://slack.com/api/chat.postMessage`.
{{% note %}}
If using a Slack webhook, you'll receive a Slack webhook URL when you
[create an incoming webhook](https://api.slack.com/incoming-webhooks#create_a_webhook).
{{% /note %}}
_**Data type:** String_
### token
The [Slack API token](https://get.slack.help/hc/en-us/articles/215770388-Create-and-regenerate-API-tokens)
used to interact with Slack.
Defaults to `""`.
{{% note %}}
A token is only required if using the Slack chat.postMessage API.
{{% /note %}}
_**Data type:** String_
### mapFn
A function that builds the object used to generate the POST request.
{{% note %}}
_You should rarely need to override the default `mapFn` parameter.
To see the default `mapFn` value or for insight into possible overrides, view the
[`slack.endpoint()` source code](https://github.com/influxdata/flux/blob/master/stdlib/slack/slack.flux)._
{{% /note %}}
_**Data type:** Function_
The returned object must include the following fields:
- `username`
- `channel`
- `workspace`
- `text`
- `iconEmoji`
- `color`
_For more information, see [`slack.message()`](/v2.0/reference/flux/functions/slack/message/)_
## Examples
##### Send critical statuses to a Slack endpoint
```js
import "monitor"
import "slack"
endpoint = slack.endpoint(token: "mySuPerSecRetTokEn")
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses" and status == "crit")
|> map(fn: (r) => { return {r with status: r._status} })
|> monitor.notify(endpoint: endpoint)
```

View File

@ -0,0 +1,124 @@
---
title: slack.message() function
description: >
The `slack.message()` function sends a single message to a Slack channel.
The function works with either with the chat.postMessage API or with a Slack webhook.
menu:
v2_0_ref:
name: slack.message
parent: Slack
weight: 202
---
The `slack.message()` function sends a single message to a Slack channel.
The function works with either with the [chat.postMessage API](https://api.slack.com/methods/chat.postMessage)
or with a [Slack webhook](https://api.slack.com/incoming-webhooks).
_**Function type:** Output_
```js
import "slack"
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mySuPerSecRetTokEn",
username: "Fluxtastic",
channel: "#flux",
workspace: "",
text: "This is a message from the Flux slack.message() function.",
iconEmoji: "wave",
color: "good"
)
```
## Parameters
### url
The Slack API URL.
Defaults to `https://slack.com/api/chat.postMessage`.
{{% note %}}
If using a Slack webhook, you'll receive a Slack webhook URL when you
[create an incoming webhook](https://api.slack.com/incoming-webhooks#create_a_webhook).
{{% /note %}}
_**Data type:** String_
### token
The [Slack API token](https://get.slack.help/hc/en-us/articles/215770388-Create-and-regenerate-API-tokens)
used to interact with Slack.
Defaults to `""`.
{{% note %}}
A token is only required if using the Slack chat.postMessage API.
{{% /note %}}
_**Data type:** String_
### username
The username to use when posting the message to a Slack channel. <span class="required">Required</span>
_**Data type:** String_
### channel
The name of channel to post the message to. <span class="required">Required</span>
_**Data type:** String_
### workspace
The name of the Slack workspace to use if there are multiple.
Defaults to `""`.
_**Data type:** String_
### text
The text to display in the Slack message. <span class="required">Required</span>
_**Data type:** String_
### iconEmoji
The name of emoji to use as the user avatar when posting the message to Slack.
<span class="required">Required</span>
_**Data type:** String_
{{% note %}}
#### Things to know about iconEmoji
- **Do not** enclose the name in colons `:` as you do in the Slack client.
- `iconEmoji` only appears as the user avatar when using the Slack chat.postMessage API.
{{% /note %}}
### color
The color to include with the message.
<span class="required">Required</span>
**Valid values include:**
- `good`
- `warning`
- `danger`
- Any valid RGB hex color code. For example, `#439FE0`.
_**Data type:** String_
## Examples
##### Send the last reported status to Slack
```js
import "slack"
lastReported =
from(bucket: "example-bucket")
|> range(start: -1m)
|> filter(fn: (r) => r._measurement == "statuses")
|> last()
|> map(fn: (r) => { return {status: r._status} })
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mySuPerSecRetTokEn",
username: "johndoe",
channel: "#system-status",
text: "The last reported status was \"${lastReported.status}\"."
)
```

View File

@ -11,13 +11,34 @@ aliases:
---
{{% note %}}
_The latest release of InfluxDB v2.0 alpha includes **Flux v0.40.2**.
_The latest release of InfluxDB v2.0 alpha includes **Flux v0.41.0**.
Though newer versions of Flux may be available, they will not be included with
InfluxDB until the next InfluxDB v2.0 release._
{{% /note %}}
---
## v0.41.0 [2019-08-26]
### Features
- Add ability to validate URLs before making `http.post` requests.
- Evaluate string interpolation.
- Implement the `secrets.get` function.
- Added secret service interface.
- Add secrets package that will construct a secret object.
- Added a SecretService interface and a new dependencies package and a basic test of functionality.
- Add Slack endpoint.
### Bug fixes
- Make `reset()` check for non-nil data before calling `Release()`.
- Add test case for `notify` function.
- Add missing math import to test case.
- Make packages aware of options.
- Resolved `holtWinters` panic.
- Use non-pointer receiver for `interpreter.function`.
---
## v0.40.2 [2019-08-22]
### Bug fixes