Skip to content

Commit

Permalink
Merge branch 'master' into reporting/fix-flaky-test-csv-no-data
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jul 14, 2021
2 parents c5cd404 + 509026d commit 3f1c0f5
Show file tree
Hide file tree
Showing 170 changed files with 2,698 additions and 2,011 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export declare class Execution<Input = unknown, Output = unknown, InspectorAdapt
| [invokeChain(chainArr, input)](./kibana-plugin-plugins-expressions-public.execution.invokechain.md) | | |
| [invokeFunction(fn, input, args)](./kibana-plugin-plugins-expressions-public.execution.invokefunction.md) | | |
| [resolveArgs(fnDef, input, argAsts)](./kibana-plugin-plugins-expressions-public.execution.resolveargs.md) | | |
| [start(input)](./kibana-plugin-plugins-expressions-public.execution.start.md) | | Call this method to start execution.<!-- -->N.B. <code>input</code> is initialized to <code>null</code> rather than <code>undefined</code> for legacy reasons, because in legacy interpreter it was set to <code>null</code> by default. |
| [start(input, isSubExpression)](./kibana-plugin-plugins-expressions-public.execution.start.md) | | Call this method to start execution.<!-- -->N.B. <code>input</code> is initialized to <code>null</code> rather than <code>undefined</code> for legacy reasons, because in legacy interpreter it was set to <code>null</code> by default. |

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ N.B. `input` is initialized to `null` rather than `undefined` for legacy reasons
<b>Signature:</b>

```typescript
start(input?: Input): Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input, isSubExpression?: boolean): Observable<ExecutionResult<Output | ExpressionValueError>>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| input | <code>Input</code> | |
| isSubExpression | <code>boolean</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ export declare class Execution<Input = unknown, Output = unknown, InspectorAdapt
| [invokeChain(chainArr, input)](./kibana-plugin-plugins-expressions-server.execution.invokechain.md) | | |
| [invokeFunction(fn, input, args)](./kibana-plugin-plugins-expressions-server.execution.invokefunction.md) | | |
| [resolveArgs(fnDef, input, argAsts)](./kibana-plugin-plugins-expressions-server.execution.resolveargs.md) | | |
| [start(input)](./kibana-plugin-plugins-expressions-server.execution.start.md) | | Call this method to start execution.<!-- -->N.B. <code>input</code> is initialized to <code>null</code> rather than <code>undefined</code> for legacy reasons, because in legacy interpreter it was set to <code>null</code> by default. |
| [start(input, isSubExpression)](./kibana-plugin-plugins-expressions-server.execution.start.md) | | Call this method to start execution.<!-- -->N.B. <code>input</code> is initialized to <code>null</code> rather than <code>undefined</code> for legacy reasons, because in legacy interpreter it was set to <code>null</code> by default. |

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ N.B. `input` is initialized to `null` rather than `undefined` for legacy reasons
<b>Signature:</b>

```typescript
start(input?: Input): Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input, isSubExpression?: boolean): Observable<ExecutionResult<Output | ExpressionValueError>>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| input | <code>Input</code> | |
| isSubExpression | <code>boolean</code> | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
ListOperatorEnum as OperatorEnum,
ListOperatorTypeEnum as OperatorTypeEnum,
} from '@kbn/securitysolution-io-ts-list-types';

import { OperatorOption } from './types';
import { OperatorOption } from '../types';

export const isOperator: OperatorOption = {
message: i18n.translate('lists.exceptions.isOperatorLabel', {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
isOneOfOperator,
isOperator,
} from '../autocomplete_operators';
import { OperatorOption } from '../autocomplete_operators/types';

import {
BuilderEntry,
Expand All @@ -52,6 +51,7 @@ import {
EmptyNestedEntry,
ExceptionsBuilderExceptionItem,
FormattedBuilderEntry,
OperatorOption,
} from '../types';

export const isEntryNested = (item: BuilderEntry): item is EntryNested => {
Expand Down
7 changes: 6 additions & 1 deletion packages/kbn-securitysolution-list-utils/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import {
EXCEPTION_LIST_NAMESPACE_AGNOSTIC,
} from '@kbn/securitysolution-list-constants';

import type { OperatorOption } from '../autocomplete_operators/types';
export interface OperatorOption {
message: string;
value: string;
operator: OperatorEnum;
type: OperatorTypeEnum;
}

/**
* @deprecated Use the one from core once it is in its own package which will be from:
Expand Down
7 changes: 4 additions & 3 deletions src/core/server/core_app/bundle_routes/file_hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const mockedCache = (): jest.Mocked<IFileHashCache> => ({
set: jest.fn(),
});

// FLAKY: https://github.com/elastic/kibana/issues/105174
describe.skip('getFileHash', () => {
describe('getFileHash', () => {
const sampleFilePath = resolve(__dirname, 'foo.js');
const fd = 42;
const stats: Stats = { ino: 42, size: 9000 } as any;
Expand Down Expand Up @@ -68,6 +67,8 @@ describe.skip('getFileHash', () => {
await getFileHash(cache, sampleFilePath, stats, fd);

expect(cache.set).toHaveBeenCalledTimes(1);
expect(cache.set).toHaveBeenCalledWith(`${sampleFilePath}-${stats.ino}`, computedHashPromise);
expect(cache.set).toHaveBeenCalledWith(`${sampleFilePath}-${stats.ino}`, expect.any(Promise));
const promiseValue = await cache.set.mock.calls[0][1];
expect(promiseValue).toEqual('computed-hash');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ export const handleRequest = async ({
requestSearchSource.setField('filter', filters);
requestSearchSource.setField('query', query);

inspectorAdapters.requests?.reset();

const { rawResponse: response } = await requestSearchSource
.fetch$({
abortSignal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,21 @@ export const useSavedSearch = ({
).pipe(debounceTime(100));

const subscription = fetch$.subscribe((val) => {
fetchAll(val === 'reset');
try {
fetchAll(val === 'reset');
} catch (error) {
data$.next({
state: FetchStatus.ERROR,
fetchError: error,
});
}
});

return () => {
subscription.unsubscribe();
};
}, [
data$,
data.query.queryString,
filterManager,
refetch$,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,33 @@ describe('DocViewTable at Discover Doc with Fields API', () => {
},
},
},
{
name: 'city',
displayName: 'city',
type: 'keyword',
isMapped: true,
readFromDocValues: true,
searchable: true,
shortDotsEnable: false,
scripted: false,
filterable: false,
},
{
name: 'city.raw',
displayName: 'city.raw',
type: 'string',
isMapped: true,
spec: {
subType: {
multi: {
parent: 'city',
},
},
},
shortDotsEnable: false,
scripted: false,
filterable: false,
},
],
},
metaFields: ['_index', '_type', '_score', '_id'],
Expand Down Expand Up @@ -380,6 +407,7 @@ describe('DocViewTable at Discover Doc with Fields API', () => {
customer_first_name: 'Betty',
'customer_first_name.keyword': 'Betty',
'customer_first_name.nickname': 'Betsy',
'city.raw': 'Los Angeles',
},
};
const props = {
Expand Down Expand Up @@ -417,6 +445,8 @@ describe('DocViewTable at Discover Doc with Fields API', () => {
findTestSubject(component, 'tableDocViewRow-customer_first_name.nickname-multifieldBadge')
.length
).toBe(1);

expect(findTestSubject(component, 'tableDocViewRow-city.raw').length).toBe(1);
});

it('does not render multifield rows if showMultiFields flag is not set', () => {
Expand Down Expand Up @@ -449,5 +479,7 @@ describe('DocViewTable at Discover Doc with Fields API', () => {
findTestSubject(component, 'tableDocViewRow-customer_first_name.nickname-multifieldBadge')
.length
).toBe(0);

expect(findTestSubject(component, 'tableDocViewRow-city.raw').length).toBe(1);
});
});
16 changes: 14 additions & 2 deletions src/plugins/discover/public/application/components/table/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useMemo, useState } from 'react';
import { EuiInMemoryTable } from '@elastic/eui';
import { IndexPattern, IndexPatternField } from '../../../../../data/public';
import { SHOW_MULTIFIELDS } from '../../../../common';
Expand Down Expand Up @@ -60,6 +60,8 @@ export const DocViewerTable = ({
indexPattern?.fields,
]);

const [childParentFieldsMap] = useState({} as Record<string, string>);

const formattedHit = useMemo(() => indexPattern?.formatHit(hit, 'html'), [hit, indexPattern]);

const tableColumns = useMemo(() => {
Expand Down Expand Up @@ -92,11 +94,21 @@ export const DocViewerTable = ({
}

const flattened = indexPattern.flattenHit(hit);
Object.keys(flattened).forEach((key) => {
const field = mapping(key);
if (field && field.spec?.subType?.multi?.parent) {
childParentFieldsMap[field.name] = field.spec.subType.multi.parent;
}
});
const items: FieldRecord[] = Object.keys(flattened)
.filter((fieldName) => {
const fieldMapping = mapping(fieldName);
const isMultiField = !!fieldMapping?.spec?.subType?.multi;
return isMultiField ? showMultiFields : true;
if (!isMultiField) {
return true;
}
const parent = childParentFieldsMap[fieldName];
return showMultiFields || (parent && !flattened.hasOwnProperty(parent));
})
.sort((fieldA, fieldB) => {
const mappingA = mapping(fieldA);
Expand Down
8 changes: 8 additions & 0 deletions src/plugins/expressions/common/execution/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ describe('Execution', () => {
});
expect(execution.inspectorAdapters).toBe(inspectorAdapters);
});

test('it should reset the request adapter only on startup', async () => {
const inspectorAdapters = { requests: { reset: jest.fn() } };
await run('add val={add 5 | access "value"}', {
inspectorAdapters,
});
expect(inspectorAdapters.requests.reset).toHaveBeenCalledTimes(1);
});
});

describe('expression abortion', () => {
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/expressions/common/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,18 @@ export class Execution<
* because in legacy interpreter it was set to `null` by default.
*/
public start(
input: Input = null as any
input: Input = null as any,
isSubExpression?: boolean
): Observable<ExecutionResult<Output | ExpressionValueError>> {
if (this.hasStarted) throw new Error('Execution already started.');
this.hasStarted = true;
this.input = input;
this.state.transitions.start();

if (!isSubExpression) {
this.context.inspectorAdapters.requests?.reset();
}

if (isObservable<Input>(input)) {
input.subscribe(this.input$);
} else if (isPromise(input)) {
Expand Down Expand Up @@ -534,7 +539,7 @@ export class Execution<
);
this.childExecutions.push(execution);

return execution.start(input);
return execution.start(input, true);
case 'string':
case 'number':
case 'null':
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Execution<Input = unknown, Output = unknown, InspectorAdapters exte
// (undocumented)
resolveArgs(fnDef: ExpressionFunction, input: unknown, argAsts: any): Observable<any>;
readonly result: Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input): Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input, isSubExpression?: boolean): Observable<ExecutionResult<Output | ExpressionValueError>>;
// Warning: (ae-forgotten-export) The symbol "ExecutionResult" needs to be exported by the entry point index.d.ts
readonly state: ExecutionContainer<ExecutionResult<Output | ExpressionValueError>>;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class Execution<Input = unknown, Output = unknown, InspectorAdapters exte
// (undocumented)
resolveArgs(fnDef: ExpressionFunction, input: unknown, argAsts: any): Observable<any>;
readonly result: Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input): Observable<ExecutionResult<Output | ExpressionValueError>>;
start(input?: Input, isSubExpression?: boolean): Observable<ExecutionResult<Output | ExpressionValueError>>;
// Warning: (ae-forgotten-export) The symbol "ExecutionResult" needs to be exported by the entry point index.d.ts
readonly state: ExecutionContainer<ExecutionResult<Output | ExpressionValueError>>;
}
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ const indexPattern = ({
const rollupIndexPattern = ({
type: IndexPatternType.ROLLUP,
typeMeta: {
'rollup-index': 'rollup',
params: {
'rollup-index': 'rollup',
},
aggs: {
date_histogram: {
timestamp: {
Expand Down
35 changes: 35 additions & 0 deletions test/functional/apps/discover/_date_nested.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'timePicker', 'discover']);
const security = getService('security');

describe('timefield is a date in a nested field', function () {
before(async function () {
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/date_nested');
await security.testUser.setRoles(['kibana_admin', 'kibana_date_nested']);
await PageObjects.common.navigateToApp('discover');
});

after(async function unloadMakelogs() {
await security.testUser.restoreDefaults();
await esArchiver.unload('test/functional/fixtures/es_archiver/date_nested');
});

it('should show an error message', async function () {
await PageObjects.discover.selectIndexPattern('date-nested');
await PageObjects.discover.waitUntilSearchingHasFinished();
await testSubjects.existOrFail('discoverNoResultsError');
});
});
}
1 change: 1 addition & 0 deletions test/functional/apps/discover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export default function ({ getService, loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./_indexpattern_with_unmapped_fields'));
loadTestFile(require.resolve('./_runtime_fields_editor'));
loadTestFile(require.resolve('./_huge_fields'));
loadTestFile(require.resolve('./_date_nested'));
});
}
Loading

0 comments on commit 3f1c0f5

Please sign in to comment.