Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Time shift metrics #98781

Merged
merged 53 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
db10c1b
make basic time offset work
flash1293 Apr 28, 2021
e79d607
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 Apr 29, 2021
4c4ad72
stabilize response merging and start building UI
flash1293 Apr 29, 2021
4d8c9b8
continue building time shift
flash1293 Apr 30, 2021
fa12d2e
add better error handling
flash1293 Apr 30, 2021
64e208a
add better error handling
flash1293 May 3, 2021
5b389ce
fix broken metric time shift
flash1293 May 3, 2021
20940a7
experimental fix action
flash1293 May 5, 2021
f0c65ec
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 5, 2021
5603bb9
cleanup
flash1293 May 5, 2021
8f6b95c
remove current runtime error thingy
flash1293 May 5, 2021
0d2621e
remove leftover runtime error stuff
flash1293 May 5, 2021
b318efd
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 6, 2021
3439d35
fix some casest push
flash1293 May 6, 2021
557d6d5
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 11, 2021
abeed2c
add tests and fix some bugs
flash1293 May 11, 2021
89dd546
add back session snapshots
flash1293 May 11, 2021
bcc0cd1
fix some bugs
flash1293 May 12, 2021
e6f112d
fix terms sorting
flash1293 May 12, 2021
e866d6d
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 17, 2021
34a2208
fix bug and add tests
flash1293 May 17, 2021
f91d72f
address comments
flash1293 May 17, 2021
50844cd
fix test
flash1293 May 17, 2021
fc5f171
fix types and docs
flash1293 May 17, 2021
2bc3872
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 18, 2021
7c4d2f2
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 18, 2021
16b5ee2
increase accepted span for percentiles
flash1293 May 18, 2021
1593bad
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 19, 2021
ef024fe
add warnings
flash1293 May 19, 2021
dc686f0
Merge branch 'master' into lens/splitted-time-offset
kibanamachine May 19, 2021
e2134e2
Merge branch 'master' into lens/splitted-time-offset
kibanamachine May 19, 2021
047d99f
improve warning
flash1293 May 20, 2021
d2ebab5
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 20, 2021
f0d3b44
Merge branch 'lens/splitted-time-offset' of github.com:flash1293/kiba…
flash1293 May 20, 2021
b4a988d
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 25, 2021
f6620ff
review comments
flash1293 May 25, 2021
eaa0819
adjust wording
flash1293 May 25, 2021
b066335
fix test
flash1293 May 25, 2021
e5287a3
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 25, 2021
81c1676
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 26, 2021
9c045a7
fix previous time shift error checks
flash1293 May 26, 2021
64fbd5a
Merge branch 'master' into lens/splitted-time-offset
kibanamachine May 27, 2021
47d0bae
Merge branch 'master' into lens/splitted-time-offset
kibanamachine May 27, 2021
026371f
add label suffix for cumulative sum
flash1293 May 27, 2021
6891e8b
review comments
flash1293 May 27, 2021
f4db9ec
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 27, 2021
8e9f724
fix functional test
flash1293 May 28, 2021
ab828a3
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 28, 2021
bc1633b
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 28, 2021
f0b137d
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 May 31, 2021
3849b04
review comments
flash1293 May 31, 2021
77139a1
Merge remote-tracking branch 'upstream/master' into lens/splitted-tim…
flash1293 Jun 2, 2021
e9b556f
fix tests
flash1293 Jun 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in this logic seems to be taking the absolute value of the time shift, so negative values are ignored. For example -60m is the same as 1h based on what I was seeing. I like this behavior- makes it impossible to make a mistake- but it was a little surprising. Can you add a test for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happened on accident - what do you think about treating this as an invalid interval?

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