-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TSVB] Greater Than or Equal to Interval Pattern (#13872)
* Create new interval pattern for specifying greater than or equal to a bucket size * Updating label to add >=1m example * Adding test case for gteAutoMatch
- Loading branch information
1 parent
60ee437
commit 7178b38
Showing
6 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import dateMath from '@elastic/datemath'; | ||
export const GTE_INTERVAL_RE = new RegExp(`^>=([\\d\\.]*\\s*(${dateMath.units.join('|')}))$`); | ||
export const INTERVAL_STRING_RE = new RegExp('^([0-9\\.]*)\\s*(' + dateMath.units.join('|') + ')$'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { parseInterval } from 'ui/utils/parse_interval'; | ||
import { GTE_INTERVAL_RE } from '../../common/interval_regexp'; | ||
export function validateInterval(timefilter, panel, maxBuckets) { | ||
const { interval } = panel; | ||
const { min, max } = timefilter.getBounds(); | ||
// No need to check auto it will return around 100 | ||
if (!interval) return; | ||
if (interval === 'auto') return; | ||
const greaterThanMatch = interval.match(GTE_INTERVAL_RE); | ||
if (greaterThanMatch) return; | ||
const duration = parseInterval(interval); | ||
if (!duration) { | ||
throw new Error(`Invalid interval: ${interval} is not a valid interval`); | ||
} | ||
const span = max.valueOf() - min.valueOf(); | ||
const buckets = Math.floor(span / duration.asMilliseconds()); | ||
if (buckets > maxBuckets) { | ||
throw new Error(`Max buckets exceeded: ${buckets} is greater than ${maxBuckets}, try a larger time interval in the panel options.`); | ||
if (duration) { | ||
const span = max.valueOf() - min.valueOf(); | ||
const buckets = Math.floor(span / duration.asMilliseconds()); | ||
if (buckets > maxBuckets) { | ||
throw new Error(`Max buckets exceeded: ${buckets} is greater than ${maxBuckets}, try a larger time interval in the panel options.`); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters