From 28fd3ff0b434442342c67e5e911b28a7153d4511 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Wed, 27 Sep 2023 15:12:03 +0200 Subject: [PATCH 1/7] [cypress] Trim long cypress configs (#167391) ## Summary In cypress tests, when the logs are output in the beginning, some binary buffers are also stringified, so when looking at logs, we have to scroll through thousands of lines of logs, that's annoying and doesn't help debugging. I'd like that to be somewhat more readable, there are a few options: - the replacer should interpret buffers as strings, try to output it like that - not every binary buffer is printable - the replacer should redact the exact fields (certificateAuthority?) - too specific, might need fixing later - trim long arrays after 32 items - I chose this as a solution Other suggestions are welcome. Screenshot 2023-09-27 at 12 49 54 --- .../scripts/run_cypress/parallel.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts b/x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts index d411cdf8e8abd..dad6bd5b9de29 100644 --- a/x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts +++ b/x-pack/plugins/security_solution/scripts/run_cypress/parallel.ts @@ -263,7 +263,17 @@ ${JSON.stringify(cypressConfigFile, null, 2)} Cypress FTR setup for file: ${filePath}: ---------------------------------------------- -${JSON.stringify(config.getAll(), null, 2)} +${JSON.stringify( + config.getAll(), + (key, v) => { + if (Array.isArray(v) && v.length > 32) { + return v.slice(0, 32).concat('... trimmed after 32 items.'); + } else { + return v; + } + }, + 2 +)} ---------------------------------------------- `); From c666e4d29efdc2157d6adbf13bd64eb85f261469 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Wed, 27 Sep 2023 15:19:30 +0200 Subject: [PATCH 2/7] chore(typecheck): clean up unused parameter (#167396) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This unused parameter is causing typescript error in many builds: https://buildkite.com/elastic/kibana-pull-request/builds/162839#018ad64e-f2db-4572-a2df-2a9257777077 ``` proc [tsc] x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx:358:19 - error TS2322: Type '{ frozenDataPreference: FrozenTierPreference; setFrozenDataPreference: (value: FrozenTierPreference \| undefined) => void; dataView: DataView; query: undefined; disabled: false; timefilter: TimefilterContract; hideFrozenDataTierChoice: boolean; }' is not assignable to type 'IntrinsicAttributes & FullTimeRangeSelectorProps & { children?: ReactNode; }'. --   | proc [tsc] Property 'hideFrozenDataTierChoice' does not exist on type 'IntrinsicAttributes & FullTimeRangeSelectorProps & { children?: ReactNode; }'.   | proc [tsc]   | proc [tsc] 358 hideFrozenDataTierChoice={!showNodeInfo} ``` --- .../components/step_define/step_define_form.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index e9326ae195015..246460d11d3ee 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -35,7 +35,6 @@ import { import { useStorage } from '@kbn/ml-local-storage'; import { useUrlState } from '@kbn/ml-url-state'; -import { useEnabledFeatures } from '../../../../serverless_context'; import { PivotAggDict } from '../../../../../../common/types/pivot_aggs'; import { PivotGroupByDict } from '../../../../../../common/types/pivot_group_by'; import { TRANSFORM_FUNCTION } from '../../../../../../common/constants'; @@ -113,7 +112,6 @@ export const StepDefineForm: FC = React.memo((props) => { ); const toastNotifications = useToastNotifications(); const stepDefineForm = useStepDefineForm(props); - const { showNodeInfo } = useEnabledFeatures(); const { advancedEditorConfig } = stepDefineForm.advancedPivotEditor.state; const { @@ -355,7 +353,6 @@ export const StepDefineForm: FC = React.memo((props) => { query={undefined} disabled={false} timefilter={timefilter} - hideFrozenDataTierChoice={!showNodeInfo} /> From 563292f0e089a66b9ecab7d5b72cc9258a21237c Mon Sep 17 00:00:00 2001 From: Brad White Date: Wed, 27 Sep 2023 07:22:34 -0600 Subject: [PATCH 3/7] Fix some type issues in x-pack/test_serverless (#167346) ## Summary We're breaking #166813 up into smaller PRs in the interest of getting PRs through sooner for type fixes. These are the changes for `x-pack/test_serverless`. ## Reviewers There are no code owners for these files, so I'm using the recently edited suggestions --------- Co-authored-by: Alex Szabo Co-authored-by: Thomas Watson Co-authored-by: Alex Szabo Co-authored-by: Thomas Watson Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../api_integration/services/svl_cases/api.ts | 14 +++++++------- .../api_integration/services/svl_cases/omit.ts | 16 ++++++++-------- .../observability/cypress/support/commands.ts | 4 ++-- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/x-pack/test_serverless/api_integration/services/svl_cases/api.ts b/x-pack/test_serverless/api_integration/services/svl_cases/api.ts index 474a92c317e9f..4163fc70291db 100644 --- a/x-pack/test_serverless/api_integration/services/svl_cases/api.ts +++ b/x-pack/test_serverless/api_integration/services/svl_cases/api.ts @@ -14,17 +14,17 @@ import { CasesFindResponse } from '@kbn/cases-plugin/common/types/api'; import { kbnTestConfig, kibanaTestSuperuserServerless } from '@kbn/test'; import { FtrProviderContext } from '../../ftr_provider_context'; +export interface User { + username: string; + password: string; + description?: string; + roles: string[]; +} + export function SvlCasesApiServiceProvider({ getService }: FtrProviderContext) { const kbnServer = getService('kibanaServer'); const supertest = getService('supertest'); - interface User { - username: string; - password: string; - description?: string; - roles: string[]; - } - const superUser: User = { username: 'superuser', password: 'superuser', diff --git a/x-pack/test_serverless/api_integration/services/svl_cases/omit.ts b/x-pack/test_serverless/api_integration/services/svl_cases/omit.ts index 94ce0a479fffc..cb424ed73609c 100644 --- a/x-pack/test_serverless/api_integration/services/svl_cases/omit.ts +++ b/x-pack/test_serverless/api_integration/services/svl_cases/omit.ts @@ -9,15 +9,15 @@ import { Case, Attachment } from '@kbn/cases-plugin/common/types/domain'; import { omit } from 'lodash'; import { FtrProviderContext } from '../../ftr_provider_context'; -export function SvlCasesOmitServiceProvider({}: FtrProviderContext) { - interface CommonSavedObjectAttributes { - id?: string | null; - created_at?: string | null; - updated_at?: string | null; - version?: string | null; - [key: string]: unknown; - } +export interface CommonSavedObjectAttributes { + id?: string | null; + created_at?: string | null; + updated_at?: string | null; + version?: string | null; + [key: string]: unknown; +} +export function SvlCasesOmitServiceProvider({}: FtrProviderContext) { const savedObjectCommonAttributes = ['created_at', 'updated_at', 'version', 'id']; return { diff --git a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts index 42b6801c6ab5b..38279b0c8d636 100644 --- a/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts +++ b/x-pack/test_serverless/functional/test_suites/observability/cypress/support/commands.ts @@ -31,8 +31,8 @@ Cypress.Commands.add('loginAsElasticUser', () => { method: 'POST', url: `${kibanaUrlWithoutAuth}/internal/security/login`, body: { - providerType: basicProvider.type, - providerName: basicProvider.name, + providerType: basicProvider?.type, + providerName: basicProvider?.name, currentURL: `${kibanaUrlWithoutAuth}/login`, params: { username, password }, }, From 07570c6847cbda632d632b2e920abef809ee6256 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Wed, 27 Sep 2023 15:24:36 +0200 Subject: [PATCH 4/7] Fix typescript errors in osquery cypress tsconfig (#167369) ## Summary Supposedly, this is the error that's causing these type of errors:/ ``` Cannot write file '/Users/alex/Git/kibana/x-pack/test/functional/services/random.js' because it would overwrite input file. ``` Separated off from: https://github.com/elastic/kibana/pull/167355 Co-authored-by: Thomas Watson Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- x-pack/plugins/osquery/cypress/tsconfig.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x-pack/plugins/osquery/cypress/tsconfig.json b/x-pack/plugins/osquery/cypress/tsconfig.json index 11f17f033495b..cb468e0fb8893 100644 --- a/x-pack/plugins/osquery/cypress/tsconfig.json +++ b/x-pack/plugins/osquery/cypress/tsconfig.json @@ -19,6 +19,9 @@ "resolveJsonModule": true, }, "kbn_references": [ + { + "path": "../../../test_serverless/tsconfig.json" + }, "@kbn/cypress-config", // cypress projects that are nested inside of other ts project use code // from the parent ts project in ways that can't be automatically deteceted From e801e76643666d5d2b73c42ee0b58f46d3609462 Mon Sep 17 00:00:00 2001 From: Maxim Kholod Date: Wed, 27 Sep 2023 15:44:42 +0200 Subject: [PATCH 5/7] [Cloud Security] add unit tests for createBenchmarkScoreIndex func (#167121) ## Summary a follow-up for https://github.com/elastic/kibana/pull/166966 to add unit tests --- .../create_indices/create_indices.test.ts | 111 ++++++++++++++++++ .../server/create_indices/create_indices.ts | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.test.ts diff --git a/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.test.ts b/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.test.ts new file mode 100644 index 0000000000000..c7f500d891c1b --- /dev/null +++ b/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.test.ts @@ -0,0 +1,111 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; +import { loggingSystemMock } from '@kbn/core/server/mocks'; +import { createBenchmarkScoreIndex } from './create_indices'; +import { + BENCHMARK_SCORE_INDEX_DEFAULT_NS, + BENCHMARK_SCORE_INDEX_PATTERN, + BENCHMARK_SCORE_INDEX_TEMPLATE_NAME, + CSP_INGEST_TIMESTAMP_PIPELINE, +} from '../../common/constants'; +import { IndicesGetIndexTemplateIndexTemplateItem } from '@elastic/elasticsearch/lib/api/types'; + +const mockEsClient = elasticsearchClientMock.createClusterClient().asScoped().asInternalUser; + +describe('createBenchmarkScoreIndex', () => { + let logger: ReturnType; + + beforeEach(() => { + logger = loggingSystemMock.createLogger(); + jest.resetAllMocks(); + }); + + it('should delete old index template from prev verions first', async () => { + mockEsClient.indices.getIndexTemplate.mockResolvedValueOnce({ + index_templates: [{ name: 'foo' } as IndicesGetIndexTemplateIndexTemplateItem], + }); + // @ts-ignore + await createBenchmarkScoreIndex(mockEsClient, { serverless: { enabled: false } }, logger); + expect(mockEsClient.indices.deleteIndexTemplate).toHaveBeenCalledTimes(1); + expect(mockEsClient.indices.deleteIndexTemplate).toHaveBeenCalledWith({ + name: 'cloud_security_posture.scores', + }); + }); + + it('should create index template with the correct index pattern, index name and default ingest pipeline', async () => { + // @ts-ignore + await createBenchmarkScoreIndex(mockEsClient, { serverless: { enabled: false } }, logger); + expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1); + expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + name: BENCHMARK_SCORE_INDEX_TEMPLATE_NAME, + index_patterns: BENCHMARK_SCORE_INDEX_PATTERN, + template: expect.objectContaining({ + settings: { + index: { + default_pipeline: CSP_INGEST_TIMESTAMP_PIPELINE, + }, + lifecycle: { + name: '', + }, + }, + }), + }) + ); + }); + + it('should create index template the correct index patter, index name and default ingest pipeline but without lifecycle in serverless', async () => { + await createBenchmarkScoreIndex( + mockEsClient, + { serverless: { enabled: true }, enabled: true }, + logger + ); + expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledTimes(1); + expect(mockEsClient.indices.putIndexTemplate).toHaveBeenCalledWith( + expect.objectContaining({ + name: BENCHMARK_SCORE_INDEX_TEMPLATE_NAME, + index_patterns: BENCHMARK_SCORE_INDEX_PATTERN, + template: expect.objectContaining({ + settings: expect.not.objectContaining({ + lifecycle: { + name: '', + }, + }), + }), + }) + ); + }); + + it('should create index if does not exist', async () => { + mockEsClient.indices.exists.mockResolvedValueOnce(false); + + await createBenchmarkScoreIndex( + mockEsClient, + { serverless: { enabled: true }, enabled: true }, + logger + ); + expect(mockEsClient.indices.create).toHaveBeenCalledTimes(1); + expect(mockEsClient.indices.create).toHaveBeenCalledWith({ + index: BENCHMARK_SCORE_INDEX_DEFAULT_NS, + }); + expect(mockEsClient.indices.putMapping).toHaveBeenCalledTimes(0); + }); + + it('should updat index mapping if index exists', async () => { + mockEsClient.indices.exists.mockResolvedValueOnce(true); + + await createBenchmarkScoreIndex( + mockEsClient, + { serverless: { enabled: true }, enabled: true }, + logger + ); + expect(mockEsClient.indices.create).toHaveBeenCalledTimes(0); + expect(mockEsClient.indices.putMapping).toHaveBeenCalledTimes(1); + }); +}); diff --git a/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.ts b/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.ts index 03e3b0c804dc0..f8a935f361ff6 100644 --- a/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.ts +++ b/x-pack/plugins/cloud_security_posture/server/create_indices/create_indices.ts @@ -65,7 +65,7 @@ export const initializeCspIndices = async ( } }; -const createBenchmarkScoreIndex = async ( +export const createBenchmarkScoreIndex = async ( esClient: ElasticsearchClient, cloudSecurityPostureConfig: CloudSecurityPostureConfig, logger: Logger From ecd1cb110f2e6f5e691cc938bf31b59458c85936 Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Wed, 27 Sep 2023 08:50:09 -0500 Subject: [PATCH 6/7] skip failing test suite (#156245) --- .../server/integration_tests/fleet_usage_telemetry.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts b/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts index 046ac5dfe9fad..b841c641c3af4 100644 --- a/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts +++ b/x-pack/plugins/fleet/server/integration_tests/fleet_usage_telemetry.test.ts @@ -20,7 +20,8 @@ import { waitForFleetSetup } from './helpers'; const logFilePath = path.join(__dirname, 'logs.log'); -describe('fleet usage telemetry', () => { +// Failing: See https://github.com/elastic/kibana/issues/156245 +describe.skip('fleet usage telemetry', () => { let core: any; let esServer: TestElasticsearchUtils; let kbnServer: TestKibanaUtils; From 7013a9b7506f7f379683a55dc1fe63079cd270ad Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Wed, 27 Sep 2023 10:38:57 -0400 Subject: [PATCH 7/7] skip failing test suite (#167320) --- .../functional/apps/maps/group2/embeddable/add_to_dashboard.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/maps/group2/embeddable/add_to_dashboard.js b/x-pack/test/functional/apps/maps/group2/embeddable/add_to_dashboard.js index fcd3d06115508..dbe4513b1d7ee 100644 --- a/x-pack/test/functional/apps/maps/group2/embeddable/add_to_dashboard.js +++ b/x-pack/test/functional/apps/maps/group2/embeddable/add_to_dashboard.js @@ -21,7 +21,8 @@ export default function ({ getPageObjects, getService }) { const testSubjects = getService('testSubjects'); const security = getService('security'); - describe('maps add-to-dashboard save flow', () => { + // Failing: See https://github.com/elastic/kibana/issues/167320 + describe.skip('maps add-to-dashboard save flow', () => { before(async () => { await security.testUser.setRoles( [