Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into metrics/log_e…
Browse files Browse the repository at this point in the history
…vent_loop_delay
  • Loading branch information
Bamieh committed Jun 29, 2021
2 parents 6ae5bc4 + 2e00e9c commit c6e7e5c
Show file tree
Hide file tree
Showing 73 changed files with 2,014 additions and 329 deletions.
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export type {
CounterRateIndexPatternColumn,
DerivativeIndexPatternColumn,
MovingAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
OverallSumIndexPatternColumn,
} from './indexpattern_datasource/types';
export type { LensEmbeddableInput } from './editor_frame_service/embeddable';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ describe('loader', () => {
label: 'My hist',
operationType: 'date_histogram',
params: {
interval: '1d',
interval: 'm',
},
sourceField: 'timestamp',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,6 @@ describe('date_histogram', () => {
});
expect(column.params.interval).toEqual('auto');
});

it('should create column object with restrictions', () => {
const column = dateHistogramOperation.buildColumn({
layer: { columns: {}, columnOrder: [], indexPatternId: '' },
indexPattern: createMockedIndexPattern(),
field: {
name: 'timestamp',
displayName: 'timestampLabel',
type: 'date',
esTypes: ['date'],
aggregatable: true,
searchable: true,
aggregationRestrictions: {
date_histogram: {
agg: 'date_histogram',
time_zone: 'UTC',
calendar_interval: '1y',
},
},
},
});
expect(column.params.interval).toEqual('1y');
expect(column.params.timeZone).toEqual('UTC');
});
});

describe('toEsAggsFn', () => {
Expand All @@ -223,7 +199,7 @@ describe('date_histogram', () => {
);
});

it('should not use normalized es interval for rollups', () => {
it('should use restricted time zone and omit use normalized es interval for rollups', () => {
const esAggsFn = dateHistogramOperation.toEsAggsFn(
layer.columns.col1 as DateHistogramIndexPatternColumn,
'col1',
Expand Down Expand Up @@ -271,6 +247,7 @@ describe('date_histogram', () => {
arguments: expect.objectContaining({
interval: ['42w'],
field: ['timestamp'],
time_zone: ['UTC'],
useNormalizedEsInterval: [false],
}),
})
Expand Down Expand Up @@ -320,114 +297,6 @@ describe('date_histogram', () => {
});
});

describe('transfer', () => {
it('should adjust interval and time zone params if that is necessary due to restrictions', () => {
const transferedColumn = dateHistogramOperation.transfer!(
{
dataType: 'date',
isBucketed: true,
label: '',
operationType: 'date_histogram',
sourceField: 'dateField',
params: {
interval: 'd',
},
},
{
title: '',
id: '',
hasRestrictions: true,
fields: [
{
name: 'dateField',
displayName: 'dateField',
type: 'date',
aggregatable: true,
searchable: true,
aggregationRestrictions: {
date_histogram: {
agg: 'date_histogram',
time_zone: 'CET',
calendar_interval: 'w',
},
},
},
],
getFieldByName: getFieldByNameFactory([
{
name: 'dateField',
displayName: 'dateField',
type: 'date',
aggregatable: true,
searchable: true,
aggregationRestrictions: {
date_histogram: {
agg: 'date_histogram',
time_zone: 'CET',
calendar_interval: 'w',
},
},
},
]),
}
);
expect(transferedColumn).toEqual(
expect.objectContaining({
params: {
interval: 'w',
timeZone: 'CET',
},
})
);
});

it('should retain interval', () => {
const transferedColumn = dateHistogramOperation.transfer!(
{
dataType: 'date',
isBucketed: true,
label: '',
operationType: 'date_histogram',
sourceField: 'dateField',
params: {
interval: '20s',
},
},
{
title: '',
id: '',
hasRestrictions: false,
fields: [
{
name: 'dateField',
displayName: 'dateField',
type: 'date',
aggregatable: true,
searchable: true,
},
],
getFieldByName: getFieldByNameFactory([
{
name: 'dateField',
displayName: 'dateField',
type: 'date',
aggregatable: true,
searchable: true,
},
]),
}
);
expect(transferedColumn).toEqual(
expect.objectContaining({
params: {
interval: '20s',
timeZone: undefined,
},
})
);
});
});

describe('param editor', () => {
it('should render current value', () => {
const updateLayerSpy = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export interface DateHistogramIndexPatternColumn extends FieldBasedIndexPatternC
operationType: 'date_histogram';
params: {
interval: string;
timeZone?: string;
};
}

Expand Down Expand Up @@ -106,12 +105,6 @@ export const dateHistogramOperation: OperationDefinition<
},
getDefaultLabel: (column, indexPattern) => getSafeName(column.sourceField, indexPattern),
buildColumn({ field }, columnParams) {
let interval = columnParams?.interval ?? autoInterval;
let timeZone: string | undefined;
if (field.aggregationRestrictions && field.aggregationRestrictions.date_histogram) {
interval = restrictedInterval(field.aggregationRestrictions) as string;
timeZone = field.aggregationRestrictions.date_histogram.time_zone;
}
return {
label: field.displayName,
dataType: 'date',
Expand All @@ -120,8 +113,7 @@ export const dateHistogramOperation: OperationDefinition<
isBucketed: true,
scale: 'interval',
params: {
interval,
timeZone,
interval: columnParams?.interval ?? autoInterval,
},
};
},
Expand All @@ -135,28 +127,6 @@ export const dateHistogramOperation: OperationDefinition<
(!newField.aggregationRestrictions || newField.aggregationRestrictions.date_histogram)
);
},
transfer: (column, newIndexPattern) => {
const newField = newIndexPattern.getFieldByName(column.sourceField);

if (newField?.aggregationRestrictions?.date_histogram) {
const restrictions = newField.aggregationRestrictions.date_histogram;

return {
...column,
params: {
...column.params,
timeZone: restrictions.time_zone,
// TODO this rewrite logic is simplified - if the current interval is a multiple of
// the restricted interval, we could carry it over directly. However as the current
// UI does not allow to select multiples of an interval anyway, this is not included yet.
// If the UI allows to pick more complicated intervals, this should be re-visited.
interval: restrictedInterval(newField.aggregationRestrictions) as string,
},
};
}

return column;
},
onFieldChange: (oldColumn, field) => {
return {
...oldColumn,
Expand All @@ -166,14 +136,24 @@ export const dateHistogramOperation: OperationDefinition<
},
toEsAggsFn: (column, columnId, indexPattern) => {
const usedField = indexPattern.getFieldByName(column.sourceField);
let timeZone: string | undefined;
let interval = column.params?.interval ?? autoInterval;
if (
usedField &&
usedField.aggregationRestrictions &&
usedField.aggregationRestrictions.date_histogram
) {
interval = restrictedInterval(usedField.aggregationRestrictions) as string;
timeZone = usedField.aggregationRestrictions.date_histogram.time_zone;
}
return buildExpressionFunction<AggFunctionsMapping['aggDateHistogram']>('aggDateHistogram', {
id: columnId,
enabled: true,
schema: 'segment',
field: column.sourceField,
time_zone: column.params.timeZone,
time_zone: timeZone,
useNormalizedEsInterval: !usedField?.aggregationRestrictions?.date_histogram,
interval: column.params.interval,
interval,
drop_partials: false,
min_doc_count: 0,
extended_bounds: JSON.stringify({}),
Expand Down Expand Up @@ -244,7 +224,7 @@ export const dateHistogramOperation: OperationDefinition<
id="xpack.lens.indexPattern.dateHistogram.restrictedInterval"
defaultMessage="Interval fixed to {intervalValue} due to aggregation restrictions."
values={{
intervalValue: currentColumn.params.interval,
intervalValue: restrictedInterval(field!.aggregationRestrictions),
}}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { monaco } from '@kbn/monaco';
import classNames from 'classnames';
import { CodeEditor } from '../../../../../../../../../src/plugins/kibana_react/public';
import type { CodeEditorProps } from '../../../../../../../../../src/plugins/kibana_react/public';
import { useDebounceWithOptions } from '../../../../../shared_components';
import { TooltipWrapper, useDebounceWithOptions } from '../../../../../shared_components';
import { ParamEditorProps } from '../../index';
import { getManagedColumnsFrom } from '../../../layer_helpers';
import { ErrorWrapper, runASTValidation, tryToParse } from '../validation';
Expand Down Expand Up @@ -729,11 +729,16 @@ export function FormulaEditor({
</EuiLink>
</EuiToolTip>
) : (
<EuiToolTip
content={i18n.translate('xpack.lens.formula.editorHelpOverlayToolTip', {
defaultMessage: 'Function reference',
})}
<TooltipWrapper
tooltipContent={i18n.translate(
'xpack.lens.formula.editorHelpOverlayToolTip',
{
defaultMessage: 'Function reference',
}
)}
condition={!isHelpOpen}
position="top"
delay="regular"
>
<EuiPopover
panelClassName="lnsFormula__docs lnsFormula__docs--overlay"
Expand All @@ -745,7 +750,12 @@ export function FormulaEditor({
button={
<EuiButtonIcon
className="lnsFormula__editorHelp lnsFormula__editorHelp--overlay"
onClick={() => setIsHelpOpen(!isHelpOpen)}
onClick={() => {
if (!isHelpOpen) {
trackUiEvent('open_formula_popover');
}
setIsHelpOpen(!isHelpOpen);
}}
iconType="documentation"
color="text"
size="s"
Expand All @@ -764,7 +774,7 @@ export function FormulaEditor({
operationDefinitionMap={visibleOperationsMap}
/>
</EuiPopover>
</EuiToolTip>
</TooltipWrapper>
)}
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export {
export { CountIndexPatternColumn } from './count';
export { LastValueIndexPatternColumn } from './last_value';
export { RangeIndexPatternColumn } from './ranges';
export { FormulaIndexPatternColumn, MathIndexPatternColumn } from './formula';

// List of all operation definitions registered to this data source.
// If you want to implement a new operation, add the definition to this array and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ export {
OverallMinIndexPatternColumn,
OverallMaxIndexPatternColumn,
OverallAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
} from './definitions';
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { documentField } from '../document_field';
import { getFieldByNameFactory } from '../pure_helpers';
import { generateId } from '../../id_generator';
import { createMockedFullReference, createMockedManagedReference } from './mocks';
import { IndexPatternColumn, OperationDefinition } from './definitions';
import { TinymathAST } from 'packages/kbn-tinymath';

jest.mock('../operations');
Expand Down Expand Up @@ -2642,7 +2643,15 @@ describe('state_helpers', () => {
});
});

// no operation currently requires this check, faking a transfer function to check whether the generic logic works
it('should rewrite column params if that is necessary due to restrictions', () => {
operationDefinitionMap.date_histogram.transfer = ((oldColumn) => ({
...oldColumn,
params: {
...oldColumn.params,
interval: 'w',
},
})) as OperationDefinition<IndexPatternColumn, 'field'>['transfer'];
const layer: IndexPatternLayer = {
columnOrder: ['col1', 'col2'],
columns: {
Expand All @@ -2666,10 +2675,10 @@ describe('state_helpers', () => {
...layer.columns.col1,
params: {
interval: 'w',
timeZone: 'CET',
},
},
});
delete operationDefinitionMap.date_histogram.transfer;
});

it('should remove operations referencing fields with wrong field types', () => {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export {
CounterRateIndexPatternColumn,
DerivativeIndexPatternColumn,
MovingAverageIndexPatternColumn,
FormulaIndexPatternColumn,
MathIndexPatternColumn,
OverallSumIndexPatternColumn,
} from './operations';

export type DraggedField = DragDropIdentifier & {
Expand Down
Loading

0 comments on commit c6e7e5c

Please sign in to comment.