Weitere ähnliche Inhalte Ähnlich wie Increasing Reuse and Time to Awesome by Using Flux Packages | Nathaniel Cook | InfluxData (20) Kürzlich hochgeladen (20) Increasing Reuse and Time to Awesome by Using Flux Packages | Nathaniel Cook | InfluxData3. © 2019 InfluxData. All rights reserved. 3
What are Flux packages?
● Flux source code
● Name
● Version
● Other Metadata
5. © 2019 InfluxData. All rights reserved. 5
Create a Flux package
alerts/
package.flux
check.flux
notify.flux
// package.flux
package alerts
option package = {
version: "0.3.1",
dependencies: [{
package: "alerta",
version: "1.0.0"
}]
}
6. A package for consistently downsampling data across teams
Example: Consistent Downsampling
7. © 2019 InfluxData. All rights reserved. 7
Downsampling Package
//downsample.flux
package downsample
bucket = "downsampled_5m"
every = 5m
mean = (tables=<-) =>
tables
|> aggregateWindow(every: every, fn: mean)
|> set(key: "agg", value: "mean")
|> to(bucket: bucket)
8. © 2019 InfluxData. All rights reserved. 8
Package Tests
//downsample_test.flux
package downsample_test
import "downsample"
test mean = () => ({
input: ...,
want: ...,
fn: downsample.mean,
})
9. © 2019 InfluxData. All rights reserved. 9
Package
//package.flux
package downsample
option package = {
version: "0.3.1",
}
10. A package for monitoring services using the RED method
Example: RED Alerts
11. © 2019 InfluxData. All rights reserved. 11
RED Package
// red.flux
package red
import "influxdata/influxdb/monitoring"
requestsCheck = ...
errorsCheck = ...
durationsCheck = ...
12. © 2019 InfluxData. All rights reserved. 12
//package.flux
package red
option package = {
version: "0.32.1",
dependencies: [{
package: "influxdata/influxdb/monitor",
version: "1.0.0"
}]
}
14. © 2019 InfluxData. All rights reserved. 14
Package Lookup
FLUX_PATH is an environment variable that defines a list of
directories to search for packages.
1. Search for directory of the form $FLUX_PATH/pauldix/foo
2. Search for version directory of the form
$FLUX_PATH/pauldix/foo/_version/v0.3.5
3. Search public registry for package (optionally download and
cache into FLUX_PATH)
15. © 2019 InfluxData. All rights reserved. 15
Dependency Resolution
What if the same dependency is used by more than one
dependent package?
Flux will pick the maximum version of the provided minimum
versions.
16. © 2019 InfluxData. All rights reserved. 16
Max of Mins Version Selection
package endpoints
option package = {
version: "1.5.1",
dependencies: [{
package: "alerta",
version: "1.2.1"
}]
}
package alerts
option package = {
version: "0.3.1",
dependencies: [{
package: "alerta",
version: "1.0.0"
}]
}
18. © 2019 InfluxData. All rights reserved. 18
What is a semantic version?
v1.35.8
Major Minor Patch
19. © 2019 InfluxData. All rights reserved. 19
Major Versions
Different major versions of a package will be treated as a
separate package.
package foo
import "nathanielc/downsample"
import d2 "nathanielc/downsample@2"
20. A place to publish and share Flux packages
Flux Package Registry
21. © 2019 InfluxData. All rights reserved. 21
Package Registry
● User Account to authenticate with Registry
● Packages are Immutable
● Namespaced by a user or organization
● Semantically Versioned
22. © 2019 InfluxData. All rights reserved. 22
Influx CLI Utility
$ # Initialize a new package directory tree
$ influx package init
$ # Run all tests in the package directory
$ influx package test
$ # Publish the package to the registry
$ influx package publish