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

TSDB support for Lens, TSVB and Timelion #139020

Merged
merged 10 commits into from
Aug 30, 2022

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/kbn-react-field/src/field_icon/field_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface FieldIconProps extends Omit<EuiTokenProps, 'iconType'> {
| 'string'
| string
| 'nested'
| 'gauge'
| 'counter'
| 'version';
label?: string;
scripted?: boolean;
Expand Down Expand Up @@ -56,6 +58,8 @@ export const typeToEuiIconMap: Partial<Record<string, EuiTokenProps>> = {
string: { iconType: 'tokenString' },
text: { iconType: 'tokenString' },
keyword: { iconType: 'tokenKeyword' },
gauge: { iconType: 'tokenMetricGauge' },
counter: { iconType: 'tokenMetricCounter' },
nested: { iconType: 'tokenNested' },
version: { iconType: 'tokenTag' },
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ describe('es', () => {
context: { search: { search: jest.fn().mockReturnValue(of(response)) } },
getIndexPatternsService: () => ({
find: async () => [],
create: async () => ({
getFieldByName: () => {
return;
},
getComputedFields: () => [],
}),
}),
request: {
events: {
Expand Down Expand Up @@ -199,6 +205,30 @@ describe('es', () => {
});
});

describe('createDateAgg for rollup', () => {
let tlConfig;
let config;
let agg;
beforeEach(() => {
tlConfig = tlConfigFn();
config = {
timefield: 'rolled_up_timestamp',
forceFixedInterval: true,
timezone: 'UTC',
interval: '1w',
};
agg = createDateAgg(config, tlConfig);
});

test('sets the timezone', () => {
expect(agg.time_buckets.date_histogram.time_zone).toEqual('UTC');
});

test('sets the interval for fixed_interval correctly', () => {
expect(agg.time_buckets.date_histogram).toHaveProperty('fixed_interval', '7d');
});
});

describe('buildRequest', () => {
const fn = buildRequest;
const emptyScriptFields = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,17 @@ export default new Datasource('es', {
fit: 'nearest',
});
const indexPatternsService = tlConfig.getIndexPatternsService();
const indexPatternSpec = (await indexPatternsService.find(config.index, 1)).find(
(index) => index.title === config.index
);
const indexPatternSpec =
(await indexPatternsService.find(config.index, 1)).find(
(index) => index.title === config.index
) || (await indexPatternsService.create({ title: config.index }));
const timeField = indexPatternSpec && indexPatternSpec.getFieldByName(config.timefield);
if (timeField && timeField.timeZone?.[0]) {
config.timezone = timeField?.timeZone?.[0];
}
if (timeField && timeField.timeZone?.[0]) {
config.forceFixedInterval = Boolean(timeField?.fixedInterval?.[0]);
}

const { scriptFields = {}, runtimeFields = {} } = indexPatternSpec?.getComputedFields() ?? {};
const esShardTimeout = tlConfig.esShardTimeout;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export default function createDateAgg(config, tlConfig, scriptFields) {
meta: { type: 'time_buckets' },
date_histogram: {
field: config.timefield,
time_zone: tlConfig.time.timezone,
time_zone: config.timezone || tlConfig.time.timezone,
extended_bounds: {
min: tlConfig.time.from,
max: tlConfig.time.to,
},
min_doc_count: 0,
...dateHistogramInterval(config.interval),
...dateHistogramInterval(config.interval, config.forceFixedInterval),
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import type { Panel } from '../../../../common/types';

export interface SearchCapabilitiesOptions {
timezone?: string;
forceFixedInterval?: boolean;
maxBucketsLimit: number;
panel?: Panel;
}
Expand All @@ -42,11 +43,13 @@ const convertAggsToRestriction = (allAvailableAggs: string[]) =>
export class DefaultSearchCapabilities {
public timezone: SearchCapabilitiesOptions['timezone'];
public maxBucketsLimit: SearchCapabilitiesOptions['maxBucketsLimit'];
public forceFixedInterval: SearchCapabilitiesOptions['forceFixedInterval'];
public panel?: Panel;

constructor(options: SearchCapabilitiesOptions) {
this.timezone = options.timezone;
this.maxBucketsLimit = options.maxBucketsLimit;
this.forceFixedInterval = options.forceFixedInterval;
this.panel = options.panel;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Side Public License, v 1.
*/

import { FetchedIndexPattern } from '../../../../common/types';
import {
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesVisDataRequest,
Expand All @@ -29,7 +30,10 @@ describe('DefaultSearchStrategy', () => {
beforeEach(() => {
req = {
body: {
panels: [],
panels: [{}],
timerange: {
timezone: 'Europe/Berlin',
},
},
} as unknown as VisTypeTimeseriesVisDataRequest;
defaultSearchStrategy = new DefaultSearchStrategy();
Expand All @@ -42,14 +46,38 @@ describe('DefaultSearchStrategy', () => {
});

test('should check a strategy for viability', async () => {
const value = await defaultSearchStrategy.checkForViability(requestContext, req);
const value = await defaultSearchStrategy.checkForViability(requestContext, req, {
indexPattern: { getFieldByName: () => undefined },
} as unknown as FetchedIndexPattern);

expect(value.isViable).toBe(true);
expect(value.capabilities).toMatchInlineSnapshot(`
DefaultSearchCapabilities {
"forceFixedInterval": false,
"maxBucketsLimit": undefined,
"panel": Object {},
"timezone": "Europe/Berlin",
}
`);
});

test('should check a strategy for viability with timeseries rollup index', async () => {
const value = await defaultSearchStrategy.checkForViability(requestContext, req, {
indexPattern: {
getFieldByName: () => ({
timeZone: ['UTC'],
fixedInterval: ['1h'],
}),
},
} as unknown as FetchedIndexPattern);

expect(value.isViable).toBe(true);
expect(value.capabilities).toMatchInlineSnapshot(`
DefaultSearchCapabilities {
"forceFixedInterval": true,
"maxBucketsLimit": undefined,
"panel": undefined,
"timezone": undefined,
"panel": Object {},
"timezone": "UTC",
}
`);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { DataViewsService } from '@kbn/data-views-plugin/common';
import { AbstractSearchStrategy } from './abstract_search_strategy';
import { DefaultSearchCapabilities } from '../capabilities/default_search_capabilities';

import type { FetchedIndexPattern } from '../../../../common/types';
import type { FetchedIndexPattern, Panel } from '../../../../common/types';
import type {
VisTypeTimeseriesRequestHandlerContext,
VisTypeTimeseriesRequest,
Expand All @@ -20,15 +20,24 @@ import { UI_SETTINGS } from '../../../../common/constants';
export class DefaultSearchStrategy extends AbstractSearchStrategy {
async checkForViability(
requestContext: VisTypeTimeseriesRequestHandlerContext,
req: VisTypeTimeseriesRequest
req: VisTypeTimeseriesRequest,
indexPattern: FetchedIndexPattern
) {
const uiSettings = (await requestContext.core).uiSettings.client;
const panel: Panel | undefined = req.body.panels ? req.body.panels[0] : undefined;
const timeField =
panel &&
indexPattern.indexPattern &&
indexPattern.indexPattern.getFieldByName(
panel.time_field || indexPattern.indexPattern.timeFieldName!
);

return {
isViable: true,
capabilities: new DefaultSearchCapabilities({
panel: req.body.panels ? req.body.panels[0] : null,
timezone: req.body.timerange?.timezone,
panel,
timezone: timeField?.timeZone?.[0] || req.body.timerange?.timezone,
forceFixedInterval: Boolean(timeField?.fixedInterval?.[0]),
maxBucketsLimit: await uiSettings.get(UI_SETTINGS.MAX_BUCKETS_SETTING),
}),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const dateHistogram: AnnotationsRequestProcessorsFunction = ({
barTargetUiSettings
);
const { from, to } = getTimerange(req);
const { timezone } = capabilities;
const { timezone, forceFixedInterval } = capabilities;

overwrite(doc, `aggs.${annotation.id}.date_histogram`, {
field: timeField,
Expand All @@ -58,7 +58,10 @@ export const dateHistogram: AnnotationsRequestProcessorsFunction = ({
min: from.valueOf(),
max: to.valueOf(),
},
...dateHistogramInterval(autoBucketSize < bucketSize ? autoIntervalString : intervalString),
...dateHistogramInterval(
autoBucketSize < bucketSize ? autoIntervalString : intervalString,
forceFixedInterval
),
});
return next(doc);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function dateHistogram(
let bucketInterval;

const overwriteDateHistogramForLastBucketMode = () => {
const { timezone } = capabilities;
const { timezone, forceFixedInterval } = capabilities;

const { intervalString } = getBucketSize(
req,
Expand All @@ -51,7 +51,7 @@ export function dateHistogram(
min: from.valueOf(),
max: to.valueOf(),
},
...dateHistogramInterval(intervalString),
...dateHistogramInterval(intervalString, forceFixedInterval),
});

bucketInterval = intervalString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const dateHistogram: TableRequestProcessorsFunction =

const overwriteDateHistogramForLastBucketMode = () => {
const { intervalString } = getBucketSize(req, interval, capabilities, barTargetUiSettings);
const { timezone } = capabilities;
const { timezone, forceFixedInterval } = capabilities;

panel.series.forEach((column) => {
const aggRoot = calculateAggRoot(doc, column);
Expand All @@ -44,7 +44,7 @@ export const dateHistogram: TableRequestProcessorsFunction =
min: from.valueOf(),
max: to.valueOf(),
},
...dateHistogramInterval(intervalString),
...dateHistogramInterval(intervalString, forceFixedInterval),
});

overwrite(doc, aggRoot.replace(/\.aggs$/, '.meta'), {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@
font-weight: 600;
display: inline;
padding-left: 8px;
}

.lnsFilterButton .euiFilterButton__textShift {
min-width: 0;
}
Loading