influxdata / influxdata/docs-v2

Document the concept of "seeding" transformations

Open
#2,213 0 comments 1 reaction 1 assignee Claimed by @sanderson View on GitHub
Flux
Dominant language
JavaScript
Stars
82
Forks
326
Avg merge
1d 1h
Merged PRs (30d)
82

Description

Some flux functions will consume rows when generating graphs. In particular, ones like `derivative()`, `difference()`, and `moving_average()` would consume some number of rows to "seed" the transformation and then produce a row for each new input. This can sometimes cause issues with graphing the data afterwards since you are now missing the first point in the graph.

It is helpful for a user to know that when they are using functions like the above, it might be worth reading more data, running the above transformation, and then refiltering the data to the appropriate time range afterwards using the following pattern.

```
import "experimental"
// the d parameter should be adjusted depending on the frequency for how data is reported.
// you want a value large enough that you'll definitely get at least the number of points needed to seed the transformation,
// but not large enough that it causes a new performance problem.
seed_start = experimental.subDuration(from: time(v: v.timeRangeStart), d: 1m)
from(bucket: "mybucket")
|> range(start: seed_start)
|> difference()
|> range(start: v.timeRangeStart)
|> rest
```

We also might want to caution users that both the second `range()` and the `difference()` method are not presently optimized in flux itself so they may cause performance issues. This is the correct pattern and there's nothing much the user can do about this until we just fix it.

The information about seeding should probably be on its own page, but it should be linked by each of the transformations that require some form of seeding and an example should be included.

Future work is to build out some utility functions that use this pattern so we put less of a mental load on end-users writing queries.

##### Relevant URLs
- https://github.com/influxdata/flux/issues/3507
- https://influxcommunity.slack.com/archives/CH8RGRW4T/p1613166098304300

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.