Skip to content

Commit

Permalink
remove calculate_auto
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Nov 20, 2020
1 parent 898a6ae commit 3049392
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-server](./kibana-plugin-plugins-data-server.md) &gt; [calcAutoIntervalLessThan](./kibana-plugin-plugins-data-server.calcautointervallessthan.md)

## calcAutoIntervalLessThan() function

Pick a "pretty" interval that produces no more than the maxBucketCount for the given time range.

<b>Signature:</b>

```typescript
export declare function calcAutoIntervalLessThan(maxBucketCount: number, duration: number): moment.Duration;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| maxBucketCount | <code>number</code> | |
| duration | <code>number</code> | |

<b>Returns:</b>

`moment.Duration`

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

| Function | Description |
| --- | --- |
| [calcAutoIntervalLessThan(maxBucketCount, duration)](./kibana-plugin-plugins-data-server.calcautointervallessthan.md) | Pick a "pretty" interval that produces no more than the maxBucketCount for the given time range. |
| [getCapabilitiesForRollupIndices(indices)](./kibana-plugin-plugins-data-server.getcapabilitiesforrollupindices.md) | |
| [getDefaultSearchParams(uiSettingsClient)](./kibana-plugin-plugins-data-server.getdefaultsearchparams.md) | |
| [getShardTimeout(config)](./kibana-plugin-plugins-data-server.getshardtimeout.md) | |
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/search/aggs/buckets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ export * from './lib/ip_range';
export * from './migrate_include_exclude_format';
export * from './significant_terms';
export * from './terms';
export * from './lib/time_buckets/calc_auto_interval';
1 change: 1 addition & 0 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export {
TabbedAggColumn,
TabbedAggRow,
TabbedTable,
calcAutoIntervalLessThan,
} from '../common';

export {
Expand Down
35 changes: 20 additions & 15 deletions src/plugins/data/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export enum BUCKET_TYPES {
TERMS = "terms"
}

// Warning: (ae-missing-release-tag) "calcAutoIntervalLessThan" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
export function calcAutoIntervalLessThan(maxBucketCount: number, duration: number): moment.Duration;

// Warning: (ae-missing-release-tag) "castEsToKbnFieldTypeName" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down Expand Up @@ -1236,21 +1241,21 @@ export function usageProvider(core: CoreSetup_2): SearchUsage;
// src/plugins/data/server/index.ts:101:26 - (ae-forgotten-export) The symbol "TruncateFormat" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isFilterable" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:127:27 - (ae-forgotten-export) The symbol "isNestedField" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:243:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:258:5 - (ae-forgotten-export) The symbol "getTotalLoaded" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:259:5 - (ae-forgotten-export) The symbol "toSnakeCase" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:263:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:264:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:273:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:279:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:280:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:284:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:287:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "getRequestInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "getResponseInspectorStats" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "tabifyAggResponse" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:244:20 - (ae-forgotten-export) The symbol "tabifyGetColumns" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:259:5 - (ae-forgotten-export) The symbol "getTotalLoaded" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:260:5 - (ae-forgotten-export) The symbol "toSnakeCase" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:264:1 - (ae-forgotten-export) The symbol "CidrMask" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:265:1 - (ae-forgotten-export) The symbol "dateHistogramInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:274:1 - (ae-forgotten-export) The symbol "InvalidEsCalendarIntervalError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:275:1 - (ae-forgotten-export) The symbol "InvalidEsIntervalFormatError" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:276:1 - (ae-forgotten-export) The symbol "Ipv4Address" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:280:1 - (ae-forgotten-export) The symbol "isValidEsInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:281:1 - (ae-forgotten-export) The symbol "isValidInterval" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:285:1 - (ae-forgotten-export) The symbol "propFilter" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index.ts:288:1 - (ae-forgotten-export) The symbol "toAbsoluteDates" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/index_patterns/index_patterns_service.ts:58:14 - (ae-forgotten-export) The symbol "IndexPatternsService" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/plugin.ts:88:66 - (ae-forgotten-export) The symbol "DataEnhancements" needs to be exported by the entry point index.d.ts
// src/plugins/data/server/search/types.ts:104:5 - (ae-forgotten-export) The symbol "ISearchStartSearchSource" needs to be exported by the entry point index.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export const IndexPattern = ({
>
<EuiRange
id={htmlIdGenerator()()}
value={model[maxBarsName]}
value={model[maxBarsName] || ''}
onChange={handleNumberChange(maxBarsName)}
showInput="inputWithPopover"
showLabels={true}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

import { calculateAuto } from './calculate_auto';
import {
getUnitValue,
parseInterval,
convertIntervalToUnit,
ASCENDING_UNIT_ORDER,
} from './unit_to_seconds';
import { getTimerangeDuration } from './get_timerange';
import { getTimerange } from './get_timerange';
import { INTERVAL_STRING_RE, GTE_INTERVAL_RE } from '../../../../common/interval_regexp';
import { calcAutoIntervalLessThan } from '../../../../../data/server';

const calculateBucketData = (timeInterval, capabilities) => {
let intervalString = capabilities
Expand Down Expand Up @@ -66,19 +66,20 @@ const calculateBucketData = (timeInterval, capabilities) => {
};

const calculateBucketSizeForAutoInterval = (req, maxBars) => {
const duration = getTimerangeDuration(req);
const { from, to } = getTimerange(req);
const timerange = to.valueOf() - from.valueOf();

return calculateAuto.near(maxBars, duration).asSeconds();
return calcAutoIntervalLessThan(maxBars, timerange).asSeconds();
};

export const getBucketSize = (req, interval, capabilities, maxBars = 100) => {
export const getBucketSize = (req, interval, capabilities, maxBars) => {
const bucketSize = calculateBucketSizeForAutoInterval(req, maxBars);
let intervalString = `${bucketSize}s`;

const gteAutoMatch = Boolean(interval) && interval.match(GTE_INTERVAL_RE);

if (gteAutoMatch) {
const bucketData = calculateBucketData(gteAutoMatch[1], capabilities, maxBars);
const bucketData = calculateBucketData(gteAutoMatch[1], capabilities);

if (bucketData.bucketSize >= bucketSize) {
return bucketData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,43 @@ describe('getBucketSize', () => {
};

test('returns auto calculated buckets', () => {
const result = getBucketSize(req, 'auto');
const result = getBucketSize(req, 'auto', undefined, 100);

expect(result).toHaveProperty('bucketSize', 30);
expect(result).toHaveProperty('intervalString', '30s');
});

test('returns overridden buckets (1s)', () => {
const result = getBucketSize(req, '1s');
const result = getBucketSize(req, '1s', undefined, 100);

expect(result).toHaveProperty('bucketSize', 1);
expect(result).toHaveProperty('intervalString', '1s');
});

test('returns overridden buckets (10m)', () => {
const result = getBucketSize(req, '10m');
const result = getBucketSize(req, '10m', undefined, 100);

expect(result).toHaveProperty('bucketSize', 600);
expect(result).toHaveProperty('intervalString', '10m');
});

test('returns overridden buckets (1d)', () => {
const result = getBucketSize(req, '1d');
const result = getBucketSize(req, '1d', undefined, 100);

expect(result).toHaveProperty('bucketSize', 86400);
expect(result).toHaveProperty('intervalString', '1d');
});

test('returns overridden buckets (>=2d)', () => {
const result = getBucketSize(req, '>=2d');
const result = getBucketSize(req, '>=2d', undefined, 100);

expect(result).toHaveProperty('bucketSize', 86400 * 2);
expect(result).toHaveProperty('intervalString', '2d');
});

test('returns overridden buckets (>=10s)', () => {
const result = getBucketSize(req, '>=10s');
const result = getBucketSize(req, '>=10s', undefined, 100);

expect(result).toHaveProperty('bucketSize', 30);
expect(result).toHaveProperty('intervalString', '30s');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@
* under the License.
*/

import { getTimerange } from './get_timerange';
import moment from 'moment';
import { getTimerange } from './get_timerange';
import { ReqFacade, VisPayload } from '../../..';

describe('getTimerange(req)', () => {
test('should return a moment object for to and from', () => {
const req = {
const req = ({
payload: {
timerange: {
min: '2017-01-01T00:00:00Z',
max: '2017-01-01T01:00:00Z',
},
},
};
} as unknown) as ReqFacade<VisPayload>;
const { from, to } = getTimerange(req);

expect(moment.isMoment(from)).toEqual(true);
expect(moment.isMoment(to)).toEqual(true);
expect(moment.utc('2017-01-01T00:00:00Z').isSame(from)).toEqual(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@
* under the License.
*/

import moment from 'moment';
import { utc } from 'moment';
import { ReqFacade, VisPayload } from '../../..';

export const getTimerange = (req) => {
export const getTimerange = (req: ReqFacade<VisPayload>) => {
const { min, max } = req.payload.timerange;

return {
from: moment.utc(min),
to: moment.utc(max),
from: utc(min),
to: utc(max),
};
};

export const getTimerangeDuration = (req) => {
const { from, to } = getTimerange(req);

return moment.duration(to.valueOf() - from.valueOf(), 'ms');
};

0 comments on commit 3049392

Please sign in to comment.