mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
This commit is contained in:
parent
04ae473c3a
commit
db838743f5
6 changed files with 54 additions and 6 deletions
|
@ -0,0 +1,19 @@
|
|||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) > [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) > [getResolvedTimeRange](./kibana-plugin-plugins-data-public.aggconfigs.getresolvedtimerange.md)
|
||||
|
||||
## AggConfigs.getResolvedTimeRange() method
|
||||
|
||||
Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set)
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
getResolvedTimeRange(): import("../..").TimeRangeBounds | undefined;
|
||||
```
|
||||
<b>Returns:</b>
|
||||
|
||||
`import("../..").TimeRangeBounds | undefined`
|
||||
|
||||
Current time range as resolved date.
|
||||
|
|
@ -42,6 +42,7 @@ export declare class AggConfigs
|
|||
| [getAll()](./kibana-plugin-plugins-data-public.aggconfigs.getall.md) | | |
|
||||
| [getRequestAggById(id)](./kibana-plugin-plugins-data-public.aggconfigs.getrequestaggbyid.md) | | |
|
||||
| [getRequestAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getrequestaggs.md) | | |
|
||||
| [getResolvedTimeRange()](./kibana-plugin-plugins-data-public.aggconfigs.getresolvedtimerange.md) | | Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set) |
|
||||
| [getResponseAggById(id)](./kibana-plugin-plugins-data-public.aggconfigs.getresponseaggbyid.md) | | Find a response agg by it's id. This may be an agg in the aggConfigs, or one created specifically for a response value |
|
||||
| [getResponseAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getresponseaggs.md) | | Gets the AggConfigs (and possibly ResponseAggConfigs) that represent the values that will be produced when all aggs are run.<!-- -->With multi-value metric aggs it is possible for a single agg request to result in multiple agg values, which is why the length of a vis' responseValuesAggs may be different than the vis' aggs {<!-- -->array\[AggConfig\]<!-- -->} |
|
||||
| [getSearchSourceTimeFilter(forceNow)](./kibana-plugin-plugins-data-public.aggconfigs.getsearchsourcetimefilter.md) | | |
|
||||
|
|
|
@ -192,9 +192,8 @@ export class AggConfig {
|
|||
} else if (!this.aggConfigs.timeRange) {
|
||||
return;
|
||||
}
|
||||
return moment.duration(
|
||||
moment(this.aggConfigs.timeRange.to).diff(this.aggConfigs.timeRange.from)
|
||||
);
|
||||
const resolvedBounds = this.aggConfigs.getResolvedTimeRange()!;
|
||||
return moment.duration(moment(resolvedBounds.max).diff(resolvedBounds.min));
|
||||
}
|
||||
return parsedTimeShift;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import { IAggType } from './agg_type';
|
|||
import { AggTypesRegistryStart } from './agg_types_registry';
|
||||
import { AggGroupNames } from './agg_groups';
|
||||
import { IndexPattern } from '../../index_patterns/index_patterns/index_pattern';
|
||||
import { TimeRange, getTime, isRangeFilter } from '../../../common';
|
||||
import { TimeRange, getTime, isRangeFilter, calculateBounds } from '../../../common';
|
||||
import { IBucketAggConfig } from './buckets';
|
||||
import { insertTimeShiftSplit, mergeTimeShifts } from './utils/time_splits';
|
||||
|
||||
|
@ -127,6 +127,19 @@ export class AggConfigs {
|
|||
this.aggs.forEach(updateAggTimeRange);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current time range as moment instance (date math will get resolved using the current "now" value or system time if not set)
|
||||
* @returns Current time range as resolved date.
|
||||
*/
|
||||
getResolvedTimeRange() {
|
||||
return (
|
||||
this.timeRange &&
|
||||
calculateBounds(this.timeRange, {
|
||||
forceNow: this.forceNow,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// clone method will reuse existing AggConfig in the list (will not create new instances)
|
||||
clone({ enabledOnly = true } = {}) {
|
||||
const filterAggs = (agg: AggConfig) => {
|
||||
|
|
|
@ -259,6 +259,7 @@ export class AggConfigs {
|
|||
getRequestAggById(id: string): AggConfig | undefined;
|
||||
// (undocumented)
|
||||
getRequestAggs(): AggConfig[];
|
||||
getResolvedTimeRange(): import("../..").TimeRangeBounds | undefined;
|
||||
getResponseAggById(id: string): AggConfig | undefined;
|
||||
getResponseAggs(): AggConfig[];
|
||||
// (undocumented)
|
||||
|
|
|
@ -71,6 +71,21 @@ export default function ({
|
|||
expect(getCell(result, 0, 2)).to.be(4618);
|
||||
});
|
||||
|
||||
it('shifts multiple metrics with relative time range and previous', async () => {
|
||||
const expression = `
|
||||
kibana_context timeRange={timerange from='${timeRange.from}' to='now'}
|
||||
| esaggs index={indexPatternLoad id='logstash-*'}
|
||||
aggs={aggCount id="1" enabled=true schema="metric"}
|
||||
aggs={aggCount id="2" enabled=true schema="metric" timeShift="previous"}
|
||||
`;
|
||||
const result = await expectExpression(
|
||||
'esaggs_shift_multi_metric_previous',
|
||||
expression
|
||||
).getResponse();
|
||||
expect(getCell(result, 0, 0)).to.be(9247);
|
||||
expect(getCell(result, 0, 1)).to.be(4763);
|
||||
});
|
||||
|
||||
it('shifts single percentile', async () => {
|
||||
const expression = `
|
||||
kibana_context timeRange={timerange from='${timeRange.from}' to='${timeRange.to}'}
|
||||
|
@ -137,7 +152,7 @@ export default function ({
|
|||
customMetric={aggAvg id="3"
|
||||
field="bytes"
|
||||
enabled=true
|
||||
schema="metric"
|
||||
schema="metric"
|
||||
}
|
||||
enabled=true
|
||||
schema="metric"
|
||||
|
@ -154,7 +169,7 @@ export default function ({
|
|||
customMetric={aggAvg id="5"
|
||||
field="bytes"
|
||||
enabled=true
|
||||
schema="metric"
|
||||
schema="metric"
|
||||
}
|
||||
enabled=true
|
||||
schema="metric"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue