Skip to content

Commit

Permalink
[Lens] Time shift metrics (#98781)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Jun 2, 2021
1 parent dfd6ec9 commit 8cb3dbc
Show file tree
Hide file tree
Showing 116 changed files with 3,698 additions and 222 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfig](./kibana-plugin-plugins-data-public.aggconfig.md) &gt; [getTimeShift](./kibana-plugin-plugins-data-public.aggconfig.gettimeshift.md)

## AggConfig.getTimeShift() method

<b>Signature:</b>

```typescript
getTimeShift(): undefined | moment.Duration;
```
<b>Returns:</b>

`undefined | moment.Duration`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfig](./kibana-plugin-plugins-data-public.aggconfig.md) &gt; [hasTimeShift](./kibana-plugin-plugins-data-public.aggconfig.hastimeshift.md)

## AggConfig.hasTimeShift() method

<b>Signature:</b>

```typescript
hasTimeShift(): boolean;
```
<b>Returns:</b>

`boolean`

Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ export declare class AggConfig
| [getRequestAggs()](./kibana-plugin-plugins-data-public.aggconfig.getrequestaggs.md) | | |
| [getResponseAggs()](./kibana-plugin-plugins-data-public.aggconfig.getresponseaggs.md) | | |
| [getTimeRange()](./kibana-plugin-plugins-data-public.aggconfig.gettimerange.md) | | |
| [getTimeShift()](./kibana-plugin-plugins-data-public.aggconfig.gettimeshift.md) | | |
| [getValue(bucket)](./kibana-plugin-plugins-data-public.aggconfig.getvalue.md) | | |
| [getValueBucketPath()](./kibana-plugin-plugins-data-public.aggconfig.getvaluebucketpath.md) | | Returns the bucket path containing the main value the agg will produce (e.g. for sum of bytes it will point to the sum, for median it will point to the 50 percentile in the percentile multi value bucket) |
| [hasTimeShift()](./kibana-plugin-plugins-data-public.aggconfig.hastimeshift.md) | | |
| [isFilterable()](./kibana-plugin-plugins-data-public.aggconfig.isfilterable.md) | | |
| [makeLabel(percentageMode)](./kibana-plugin-plugins-data-public.aggconfig.makelabel.md) | | |
| [nextId(list)](./kibana-plugin-plugins-data-public.aggconfig.nextid.md) | <code>static</code> | Calculate the next id based on the ids in this list {<!-- -->array<!-- -->} list - a list of objects with id properties |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [forceNow](./kibana-plugin-plugins-data-public.aggconfigs.forcenow.md)

## AggConfigs.forceNow property

<b>Signature:</b>

```typescript
forceNow?: Date;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [getSearchSourceTimeFilter](./kibana-plugin-plugins-data-public.aggconfigs.getsearchsourcetimefilter.md)

## AggConfigs.getSearchSourceTimeFilter() method

<b>Signature:</b>

```typescript
getSearchSourceTimeFilter(forceNow?: Date): RangeFilter[] | {
meta: {
index: string | undefined;
params: {};
alias: string;
disabled: boolean;
negate: boolean;
};
query: {
bool: {
should: {
bool: {
filter: {
range: {
[x: string]: {
gte: string;
lte: string;
};
};
}[];
};
}[];
minimum_should_match: number;
};
};
}[];
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| forceNow | <code>Date</code> | |

<b>Returns:</b>

`RangeFilter[] | {
meta: {
index: string | undefined;
params: {};
alias: string;
disabled: boolean;
negate: boolean;
};
query: {
bool: {
should: {
bool: {
filter: {
range: {
[x: string]: {
gte: string;
lte: string;
};
};
}[];
};
}[];
minimum_should_match: number;
};
};
}[]`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [getTimeShiftInterval](./kibana-plugin-plugins-data-public.aggconfigs.gettimeshiftinterval.md)

## AggConfigs.getTimeShiftInterval() method

<b>Signature:</b>

```typescript
getTimeShiftInterval(): moment.Duration | undefined;
```
<b>Returns:</b>

`moment.Duration | undefined`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [getTimeShifts](./kibana-plugin-plugins-data-public.aggconfigs.gettimeshifts.md)

## AggConfigs.getTimeShifts() method

<b>Signature:</b>

```typescript
getTimeShifts(): Record<string, moment.Duration>;
```
<b>Returns:</b>

`Record<string, moment.Duration>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [hasTimeShifts](./kibana-plugin-plugins-data-public.aggconfigs.hastimeshifts.md)

## AggConfigs.hasTimeShifts() method

<b>Signature:</b>

```typescript
hasTimeShifts(): boolean;
```
<b>Returns:</b>

`boolean`

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export declare class AggConfigs
| --- | --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-public.aggconfigs.aggs.md) | | <code>IAggConfig[]</code> | |
| [createAggConfig](./kibana-plugin-plugins-data-public.aggconfigs.createaggconfig.md) | | <code>&lt;T extends AggConfig = AggConfig&gt;(params: CreateAggConfigParams, { addToAggConfigs }?: {</code><br/><code> addToAggConfigs?: boolean &#124; undefined;</code><br/><code> }) =&gt; T</code> | |
| [forceNow](./kibana-plugin-plugins-data-public.aggconfigs.forcenow.md) | | <code>Date</code> | |
| [hierarchical](./kibana-plugin-plugins-data-public.aggconfigs.hierarchical.md) | | <code>boolean</code> | |
| [indexPattern](./kibana-plugin-plugins-data-public.aggconfigs.indexpattern.md) | | <code>IndexPattern</code> | |
| [timeFields](./kibana-plugin-plugins-data-public.aggconfigs.timefields.md) | | <code>string[]</code> | |
Expand All @@ -43,8 +44,14 @@ export declare class AggConfigs
| [getRequestAggs()](./kibana-plugin-plugins-data-public.aggconfigs.getrequestaggs.md) | | |
| [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) | | |
| [getTimeShiftInterval()](./kibana-plugin-plugins-data-public.aggconfigs.gettimeshiftinterval.md) | | |
| [getTimeShifts()](./kibana-plugin-plugins-data-public.aggconfigs.gettimeshifts.md) | | |
| [hasTimeShifts()](./kibana-plugin-plugins-data-public.aggconfigs.hastimeshifts.md) | | |
| [jsonDataEquals(aggConfigs)](./kibana-plugin-plugins-data-public.aggconfigs.jsondataequals.md) | | Data-by-data comparison of this Aggregation Ignores the non-array indexes |
| [onSearchRequestStart(searchSource, options)](./kibana-plugin-plugins-data-public.aggconfigs.onsearchrequeststart.md) | | |
| [postFlightTransform(response)](./kibana-plugin-plugins-data-public.aggconfigs.postflighttransform.md) | | |
| [setForceNow(now)](./kibana-plugin-plugins-data-public.aggconfigs.setforcenow.md) | | |
| [setTimeFields(timeFields)](./kibana-plugin-plugins-data-public.aggconfigs.settimefields.md) | | |
| [setTimeRange(timeRange)](./kibana-plugin-plugins-data-public.aggconfigs.settimerange.md) | | |
| [toDsl()](./kibana-plugin-plugins-data-public.aggconfigs.todsl.md) | | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [postFlightTransform](./kibana-plugin-plugins-data-public.aggconfigs.postflighttransform.md)

## AggConfigs.postFlightTransform() method

<b>Signature:</b>

```typescript
postFlightTransform(response: IEsSearchResponse<any>): IEsSearchResponse<any>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| response | <code>IEsSearchResponse&lt;any&gt;</code> | |

<b>Returns:</b>

`IEsSearchResponse<any>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [AggConfigs](./kibana-plugin-plugins-data-public.aggconfigs.md) &gt; [setForceNow](./kibana-plugin-plugins-data-public.aggconfigs.setforcenow.md)

## AggConfigs.setForceNow() method

<b>Signature:</b>

```typescript
setForceNow(now: Date | undefined): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| now | <code>Date &#124; undefined</code> | |

<b>Returns:</b>

`void`

27 changes: 27 additions & 0 deletions src/plugins/data/common/search/aggs/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import moment from 'moment';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { Assign, Ensure } from '@kbn/utility-types';
Expand All @@ -20,6 +21,7 @@ import {
import { IAggType } from './agg_type';
import { writeParams } from './agg_params';
import { IAggConfigs } from './agg_configs';
import { parseTimeShift } from './utils';

type State = string | number | boolean | null | undefined | SerializableState;

Expand Down Expand Up @@ -172,6 +174,31 @@ export class AggConfig {
return _.get(this.params, key);
}

hasTimeShift(): boolean {
return Boolean(this.getParam('timeShift'));
}

getTimeShift(): undefined | moment.Duration {
const rawTimeShift = this.getParam('timeShift');
if (!rawTimeShift) return undefined;
const parsedTimeShift = parseTimeShift(rawTimeShift);
if (parsedTimeShift === 'invalid') {
throw new Error(`could not parse time shift ${rawTimeShift}`);
}
if (parsedTimeShift === 'previous') {
const timeShiftInterval = this.aggConfigs.getTimeShiftInterval();
if (timeShiftInterval) {
return timeShiftInterval;
} else if (!this.aggConfigs.timeRange) {
return;
}
return moment.duration(
moment(this.aggConfigs.timeRange.to).diff(this.aggConfigs.timeRange.from)
);
}
return parsedTimeShift;
}

write(aggs?: IAggConfigs) {
return writeParams<AggConfig>(this.type.params, this, aggs);
}
Expand Down
Loading

0 comments on commit 8cb3dbc

Please sign in to comment.