Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into feat/move-obs-p…
Browse files Browse the repository at this point in the history
…lugins-infra
  • Loading branch information
CoenWarmer committed Feb 23, 2024
2 parents 9b3e3cc + 2005cef commit 986ba16
Show file tree
Hide file tree
Showing 69 changed files with 957 additions and 421 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,9 @@ x-pack/test/security_solution_cypress/cypress/tasks/expandable_flyout @elastic/
/x-pack/plugins/stack_connectors/server/connector_types/sentinelone @elastic/security-defend-workflows
/x-pack/plugins/stack_connectors/common/sentinelone @elastic/security-defend-workflows

## Security Solution shared OAS schemas
/x-pack/plugins/security_solution/common/api/model @elastic/security-detection-rule-management @elastic/security-detection-engine

## Security Solution sub teams - Detection Rule Management
/x-pack/plugins/security_solution/common/api/detection_engine/fleet_integrations @elastic/security-detection-rule-management
/x-pack/plugins/security_solution/common/api/detection_engine/model/rule_schema @elastic/security-detection-rule-management @elastic/security-detection-engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { errors } from '@elastic/elasticsearch';
import { loggingSystemMock } from '@kbn/core-logging-server-mocks';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { retryCallCluster, migrationRetryCallCluster } from './retry_call_cluster';

Expand Down Expand Up @@ -69,11 +68,9 @@ describe('retryCallCluster', () => {

describe('migrationRetryCallCluster', () => {
let client: ReturnType<typeof elasticsearchClientMock.createElasticsearchClient>;
let logger: ReturnType<typeof loggingSystemMock.createLogger>;

beforeEach(() => {
client = elasticsearchClientMock.createElasticsearchClient();
logger = loggingSystemMock.createLogger();
});

const mockClientPingWithErrorBeforeSuccess = (error: any) => {
Expand All @@ -88,21 +85,21 @@ describe('migrationRetryCallCluster', () => {
new errors.NoLivingConnectionsError('no living connections', {} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

it('retries ES API calls that rejects with `ConnectionError`', async () => {
mockClientPingWithErrorBeforeSuccess(new errors.ConnectionError('connection error', {} as any));

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

it('retries ES API calls that rejects with `TimeoutError`', async () => {
mockClientPingWithErrorBeforeSuccess(new errors.TimeoutError('timeout error', {} as any));

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -113,7 +110,7 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -124,7 +121,7 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -135,7 +132,7 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -146,7 +143,7 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -157,7 +154,7 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

Expand All @@ -173,65 +170,10 @@ describe('migrationRetryCallCluster', () => {
} as any)
);

const result = await migrationRetryCallCluster(() => client.ping(), logger, 1);
const result = await migrationRetryCallCluster(() => client.ping(), 1);
expect(result).toEqual(dummyBody);
});

it('logs only once for each unique error message', async () => {
client.ping
.mockImplementationOnce(() =>
createErrorReturn(
new errors.ResponseError({
statusCode: 503,
} as any)
)
)
.mockImplementationOnce(() =>
createErrorReturn(new errors.ConnectionError('connection error', {} as any))
)
.mockImplementationOnce(() =>
createErrorReturn(
new errors.ResponseError({
statusCode: 503,
} as any)
)
)
.mockImplementationOnce(() =>
createErrorReturn(new errors.ConnectionError('connection error', {} as any))
)
.mockImplementationOnce(() =>
createErrorReturn(
new errors.ResponseError({
statusCode: 500,
body: {
error: {
type: 'snapshot_in_progress_exception',
},
},
} as any)
)
)
.mockImplementationOnce(() =>
elasticsearchClientMock.createSuccessTransportRequestPromise({ ...dummyBody })
);

await migrationRetryCallCluster(() => client.ping(), logger, 1);

expect(loggingSystemMock.collect(logger).warn).toMatchInlineSnapshot(`
Array [
Array [
"Unable to connect to Elasticsearch. Error: Response Error",
],
Array [
"Unable to connect to Elasticsearch. Error: connection error",
],
Array [
"Unable to connect to Elasticsearch. Error: snapshot_in_progress_exception",
],
]
`);
});

it('rejects when ES API calls reject with other errors', async () => {
client.ping
.mockImplementationOnce(() =>
Expand All @@ -250,9 +192,9 @@ describe('migrationRetryCallCluster', () => {
elasticsearchClientMock.createSuccessTransportRequestPromise({ ...dummyBody })
);

await expect(
migrationRetryCallCluster(() => client.ping(), logger, 1)
).rejects.toMatchInlineSnapshot(`[ResponseError: I'm a teapot]`);
await expect(migrationRetryCallCluster(() => client.ping(), 1)).rejects.toMatchInlineSnapshot(
`[ResponseError: I'm a teapot]`
);
});

it('stops retrying when ES API calls reject with other errors', async () => {
Expand All @@ -268,8 +210,8 @@ describe('migrationRetryCallCluster', () => {
elasticsearchClientMock.createSuccessTransportRequestPromise({ ...dummyBody })
);

await expect(
migrationRetryCallCluster(() => client.ping(), logger, 1)
).rejects.toMatchInlineSnapshot(`[Error: unknown error]`);
await expect(migrationRetryCallCluster(() => client.ping(), 1)).rejects.toMatchInlineSnapshot(
`[Error: unknown error]`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { defer, throwError, iif, timer } from 'rxjs';
import { concatMap, retryWhen } from 'rxjs/operators';
import type { Logger } from '@kbn/logging';

const retryResponseStatuses = [
503, // ServiceUnavailable
Expand Down Expand Up @@ -60,7 +59,6 @@ export const retryCallCluster = <T extends Promise<unknown>>(apiCaller: () => T)
*/
export const migrationRetryCallCluster = <T extends Promise<unknown>>(
apiCaller: () => T,
log: Logger,
delay: number = 2500
): T => {
const previousErrors: string[] = [];
Expand All @@ -70,7 +68,6 @@ export const migrationRetryCallCluster = <T extends Promise<unknown>>(
errors.pipe(
concatMap((error) => {
if (!previousErrors.includes(error.message)) {
log.warn(`Unable to connect to Elasticsearch. Error: ${error.message}`);
previousErrors.push(error.message);
}
return iif(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ export async function getCurrentIndexTypesMap({
client.indices.getMapping({
index: mainIndex,
}),
logger,
retryDelay
);

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ export {
getLimitFromESQLQuery,
removeDropCommandsFromESQLQuery,
getIndexForESQLQuery,
getInitialESQLQuery,
TextBasedLanguages,
} from './src';
1 change: 1 addition & 0 deletions packages/kbn-esql-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

export { TextBasedLanguages } from './types';
export { getESQLAdHocDataview, getIndexForESQLQuery } from './utils/get_esql_adhoc_dataview';
export { getInitialESQLQuery } from './utils/get_initial_esql_query';
export {
getIndexPatternFromSQLQuery,
getIndexPatternFromESQLQuery,
Expand Down
15 changes: 15 additions & 0 deletions packages/kbn-esql-utils/src/utils/get_initial_esql_query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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 { getInitialESQLQuery } from './get_initial_esql_query';

describe('getInitialESQLQuery', () => {
it('should work correctly', () => {
expect(getInitialESQLQuery('logs*')).toBe('from logs* | limit 10');
});
});
15 changes: 15 additions & 0 deletions packages/kbn-esql-utils/src/utils/get_initial_esql_query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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.
*/

/**
* Builds an ES|QL query for the provided index or index pattern
* @param indexOrIndexPattern
*/
export function getInitialESQLQuery(indexOrIndexPattern: string): string {
return `from ${indexOrIndexPattern} | limit 10`;
}
33 changes: 19 additions & 14 deletions packages/kbn-unified-data-table/src/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import type { ToastsStart, IUiSettingsClient } from '@kbn/core/public';
import type { Serializable } from '@kbn/utility-types';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import { getShouldShowFieldHandler, DOC_HIDE_TIME_COLUMN_SETTING } from '@kbn/discover-utils';
import { getShouldShowFieldHandler } from '@kbn/discover-utils';
import type { DataViewFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public';
import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public';
import type { ThemeServiceStart } from '@kbn/react-kibana-context-common';
Expand All @@ -63,7 +63,7 @@ import {
getEuiGridColumns,
getLeadControlColumns,
getVisibleColumns,
hasSourceTimeFieldValue,
canPrependTimeFieldColumn,
} from './data_table_columns';
import { UnifiedDataTableContext } from '../table_context';
import { getSchemaDetectors } from './data_table_schema';
Expand Down Expand Up @@ -630,15 +630,23 @@ export const UnifiedDataTable = ({
[dataView, onFieldEdited, services.dataViewFieldEditor]
);

const shouldShowTimeField = useMemo(
() =>
hasSourceTimeFieldValue(displayedColumns, dataView, columnTypes, showTimeCol, isPlainRecord),
[dataView, displayedColumns, isPlainRecord, showTimeCol, columnTypes]
const timeFieldName = dataView.timeFieldName;
const shouldPrependTimeFieldColumn = useCallback(
(activeColumns: string[]) =>
canPrependTimeFieldColumn(
activeColumns,
timeFieldName,
columnTypes,
showTimeCol,
isPlainRecord
),
[timeFieldName, isPlainRecord, showTimeCol, columnTypes]
);

const visibleColumns = useMemo(
() => getVisibleColumns(displayedColumns, dataView, shouldShowTimeField),
[dataView, displayedColumns, shouldShowTimeField]
() =>
getVisibleColumns(displayedColumns, dataView, shouldPrependTimeFieldColumn(displayedColumns)),
[dataView, displayedColumns, shouldPrependTimeFieldColumn]
);

const getCellValue = useCallback<UseDataGridColumnsCellActionsProps['getCellValue']>(
Expand Down Expand Up @@ -741,19 +749,16 @@ export const UnifiedDataTable = ({
]
);

const hideTimeColumn = useMemo(
() => services.uiSettings.get(DOC_HIDE_TIME_COLUMN_SETTING, false),
[services.uiSettings]
);
const schemaDetectors = useMemo(() => getSchemaDetectors(), []);
const columnsVisibility = useMemo(
() => ({
visibleColumns,
setVisibleColumns: (newColumns: string[]) => {
onSetColumns(newColumns, hideTimeColumn);
const dontModifyColumns = !shouldPrependTimeFieldColumn(newColumns);
onSetColumns(newColumns, dontModifyColumns);
},
}),
[visibleColumns, hideTimeColumn, onSetColumns]
[visibleColumns, onSetColumns, shouldPrependTimeFieldColumn]
);

/**
Expand Down
Loading

0 comments on commit 986ba16

Please sign in to comment.