influxdata / influxdata/influxdb

Add a moving_max() function

Open
#20,253 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

### Proposal:
Implement stable max-times, which are useful for highlighting spikes, e.g. `moving_max()`.

### Current behavior:
Without this feature, there are currently three options are available:

1. `moving_average()` (or `kaufmans_adaptive_moving_average()`) which flatten out your spikes, essentially hiding them.
2. Display without filtering. Visually representing spikes with a lot of jitter is suboptimal (for more reasons that I care to explain here).
3. Increase the time period in the GUI. This throws out information, and makes the graph less appealing.

None of the above are satisfactory.

### Desired behavior:
`SELECT moving_max(..., 10) FROM ...` would result in the maximum values including the previous 9 datapoints per each datapoint. This is calculated similarly to a `moving_average()`, except taking the maximum instead of the mean in the moving window.

### Pseudo code:
This is what you'd write in Python/Pandas for a moving window size of 3:
````python
pd.Series([1, 2, 3, 1, 1, 2, 4, 1, 0, 1]).rolling(3).max()
[nan, nan, 3.0, 3.0, 3.0, 2.0, 4.0, 4.0, 4.0, 1.0]
````

### Use case:
Many people would use this to display maximum response times in http and db calls for example, as they frequently vary depending on input parameters. A frequently used function will normally have a bunch of cheap uses, and a few costly ones. This function would really help visualization of the costly ones, while more or less filtering out the cheap ones (depending on the moving window size).

Contributor guide

Open the contributing guide

Research direction

Start by locating the existing moving_average() implementation and its query-language tests, then compare their window semantics with the proposed Pandas example. Define the moving_max() behavior for each window position and add coverage showing the expected maximum values for a window of 3.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
database
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.