From 636c65b025b6a7b340f040023ea293cbe2c91531 Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Tue, 9 Jan 2024 10:48:08 +0200 Subject: [PATCH 1/6] [Cases] Fixes edit assignees flyout flaky tests (#174469) ## Summary Fixes: https://github.com/elastic/kibana/issues/174195, https://github.com/elastic/kibana/issues/174194 Successfully run 3x100 times: https://buildkite.com/elastic/kibana-pull-request/builds?branch=cnasikas%3Afix_assignees_flyout_flaky_test ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../assignees/edit_assignees_flyout.test.tsx | 81 +++++++++---------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/x-pack/plugins/cases/public/components/actions/assignees/edit_assignees_flyout.test.tsx b/x-pack/plugins/cases/public/components/actions/assignees/edit_assignees_flyout.test.tsx index 9001faa12a2a6..15ab25f9db223 100644 --- a/x-pack/plugins/cases/public/components/actions/assignees/edit_assignees_flyout.test.tsx +++ b/x-pack/plugins/cases/public/components/actions/assignees/edit_assignees_flyout.test.tsx @@ -10,22 +10,21 @@ import userEvent from '@testing-library/user-event'; import type { AppMockRenderer } from '../../../common/mock'; import { createAppMockRenderer } from '../../../common/mock'; import { basicCase } from '../../../containers/mock'; -import { waitForComponentToUpdate } from '../../../common/test_utils'; import { EditAssigneesFlyout } from './edit_assignees_flyout'; -import { waitFor } from '@testing-library/react'; +import { screen, waitFor } from '@testing-library/react'; +import { useBulkGetUserProfiles } from '../../../containers/user_profiles/use_bulk_get_user_profiles'; +import { useSuggestUserProfiles } from '../../../containers/user_profiles/use_suggest_user_profiles'; +import { userProfiles, userProfilesMap } from '../../../containers/user_profiles/api.mock'; -jest.mock('../../../containers/user_profiles/api'); +jest.mock('../../../containers/user_profiles/use_bulk_get_user_profiles'); +jest.mock('../../../containers/user_profiles/use_suggest_user_profiles'); -// Failing: See https://github.com/elastic/kibana/issues/174194 -// Failing: See https://github.com/elastic/kibana/issues/174195 -describe.skip('EditAssigneesFlyout', () => { +const useBulkGetUserProfilesMock = useBulkGetUserProfiles as jest.Mock; +const useSuggestUserProfilesMock = useSuggestUserProfiles as jest.Mock; + +describe('EditAssigneesFlyout', () => { let appMock: AppMockRenderer; - /** - * Case one has the following assignees: coke, pepsi, one - * Case two has the following assignees: one, three - * All available assignees are: one, two, three, coke, pepsi - */ const props = { selectedCases: [basicCase], onClose: jest.fn(), @@ -33,63 +32,57 @@ describe.skip('EditAssigneesFlyout', () => { }; beforeEach(() => { - appMock = createAppMockRenderer(); jest.clearAllMocks(); + appMock = createAppMockRenderer(); + + useBulkGetUserProfilesMock.mockReturnValue({ data: userProfilesMap }); + useSuggestUserProfilesMock.mockReturnValue({ data: userProfiles, isLoading: false }); }); it('renders correctly', async () => { - const result = appMock.render(); + appMock.render(); - expect(result.getByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); - expect(result.getByTestId('cases-edit-assignees-flyout-title')).toBeInTheDocument(); - expect(result.getByTestId('cases-edit-assignees-flyout-cancel')).toBeInTheDocument(); - expect(result.getByTestId('cases-edit-assignees-flyout-submit')).toBeInTheDocument(); - - await waitForComponentToUpdate(); + expect(await screen.findByTestId('cases-edit-assignees-flyout')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-edit-assignees-flyout-title')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-edit-assignees-flyout-cancel')).toBeInTheDocument(); + expect(await screen.findByTestId('cases-edit-assignees-flyout-submit')).toBeInTheDocument(); }); it('calls onClose when pressing the cancel button', async () => { - const result = appMock.render(); + appMock.render(); - userEvent.click(result.getByTestId('cases-edit-assignees-flyout-cancel')); - expect(props.onClose).toHaveBeenCalled(); + userEvent.click(await screen.findByTestId('cases-edit-assignees-flyout-cancel')); - await waitForComponentToUpdate(); + await waitFor(() => { + expect(props.onClose).toHaveBeenCalled(); + }); }); it('calls onSaveAssignees when pressing the save selection button', async () => { - const result = appMock.render(); + appMock.render(); - await waitForComponentToUpdate(); + expect(await screen.findByText('Damaged Raccoon')).toBeInTheDocument(); - await waitFor(() => { - expect(result.getByText('Damaged Raccoon')).toBeInTheDocument(); - }); - - userEvent.click(result.getByText('Damaged Raccoon')); - userEvent.click(result.getByTestId('cases-edit-assignees-flyout-submit')); + userEvent.click(await screen.findByText('Damaged Raccoon')); + userEvent.click(await screen.findByTestId('cases-edit-assignees-flyout-submit')); - expect(props.onSaveAssignees).toHaveBeenCalledWith({ - selectedItems: [], - unSelectedItems: ['u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0'], + await waitFor(() => { + expect(props.onSaveAssignees).toHaveBeenCalledWith({ + selectedItems: [], + unSelectedItems: ['u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0'], + }); }); }); it('shows the case title when selecting one case', async () => { - const result = appMock.render(); - - expect(result.getByText(basicCase.title)).toBeInTheDocument(); + appMock.render(); - await waitForComponentToUpdate(); + expect(await screen.findByText(basicCase.title)).toBeInTheDocument(); }); it('shows the number of total selected cases in the title when selecting multiple cases', async () => { - const result = appMock.render( - - ); - - expect(result.getByText('Selected cases: 2')).toBeInTheDocument(); + appMock.render(); - await waitForComponentToUpdate(); + expect(await screen.findByText('Selected cases: 2')).toBeInTheDocument(); }); }); From abc712cdeb4e57259e65f706af00d733b30883e2 Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 9 Jan 2024 10:18:26 +0100 Subject: [PATCH 2/6] [ML] Only enable apply button in anomaly detection datafeed chart if changes have been made (#174425) Fixes https://github.com/elastic/kibana/issues/174406, so that the apply button is only enabled in the anomaly detection datafeed chart flyout if changes have been made. ## Summary Compares current query delay value vs edited value to determine if the apply button should be disabled. https://github.com/elastic/kibana/assets/264922/6c7d3889-271e-4849-9e9d-6246a8757648 ### Checklist - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../datafeed_chart_flyout/edit_query_delay.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/datafeed_chart_flyout/edit_query_delay.tsx b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/datafeed_chart_flyout/edit_query_delay.tsx index ad5703d54d884..0d2cd2fba4070 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/datafeed_chart_flyout/edit_query_delay.tsx +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/datafeed_chart_flyout/edit_query_delay.tsx @@ -34,6 +34,7 @@ export const EditQueryDelay: FC<{ queryDelay: Datafeed['query_delay']; isEnabled: boolean; }> = ({ datafeedId, queryDelay, isEnabled }) => { + const [currentQueryDelay, setCurrentQueryDelay] = useState(queryDelay); const [newQueryDelay, setNewQueryDelay] = useState(); const [isEditing, setIsEditing] = useState(false); const { updateDatafeed } = useMlApiContext(); @@ -45,6 +46,7 @@ export const EditQueryDelay: FC<{ datafeedId, datafeedConfig: { query_delay: newQueryDelay }, }); + setCurrentQueryDelay(newQueryDelay); displaySuccessToast( i18n.translate( 'xpack.ml.jobsList.datafeedChart.editQueryDelay.changesSavedNotificationMessage', @@ -120,7 +122,12 @@ export const EditQueryDelay: FC<{ - + Date: Tue, 9 Jan 2024 11:25:44 +0200 Subject: [PATCH 3/6] [Cases] Fix cases metrics flaky test (#174461) ## Summary Fixes: https://github.com/elastic/kibana/issues/174300 Successfully run 3x100 times: https://buildkite.com/elastic/kibana-pull-request/builds?branch=cnasikas%3Afix_174300. The errors on some runs are related to other tests and not this one. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --- .../all_cases/cases_metrics.test.tsx | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/cases/public/components/all_cases/cases_metrics.test.tsx b/x-pack/plugins/cases/public/components/all_cases/cases_metrics.test.tsx index aeb6d46cd3a33..9105f82476891 100644 --- a/x-pack/plugins/cases/public/components/all_cases/cases_metrics.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/cases_metrics.test.tsx @@ -5,31 +5,57 @@ * 2.0. */ -import { waitFor, within } from '@testing-library/react'; +import { screen, within } from '@testing-library/react'; import React from 'react'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; +import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics'; +import { useGetCasesStatus } from '../../containers/use_get_cases_status'; import { CasesMetrics } from './cases_metrics'; -jest.mock('../../api'); +jest.mock('pretty-ms', () => jest.fn().mockReturnValue('2ms')); +jest.mock('../../containers/use_get_cases_metrics'); +jest.mock('../../containers/use_get_cases_status'); -// Failing: See https://github.com/elastic/kibana/issues/174300 -describe.skip('Cases metrics', () => { +const useGetCasesMetricsMock = useGetCasesMetrics as jest.Mock; +const useGetCasesStatusMock = useGetCasesStatus as jest.Mock; + +describe('Cases metrics', () => { let appMockRenderer: AppMockRenderer; beforeEach(() => { + useGetCasesMetricsMock.mockReturnValue({ isLoading: false, data: { mttr: 2000 } }); + useGetCasesStatusMock.mockReturnValue({ + isLoading: false, + data: { + countOpenCases: 20, + countInProgressCases: 40, + countClosedCases: 130, + }, + }); + appMockRenderer = createAppMockRenderer(); }); it('renders the correct stats', async () => { - const result = appMockRenderer.render(); - - await waitFor(() => { - expect(result.getByTestId('cases-metrics-stats')).toBeTruthy(); - expect(within(result.getByTestId('openStatsHeader')).getByText(20)).toBeTruthy(); - expect(within(result.getByTestId('inProgressStatsHeader')).getByText(40)).toBeTruthy(); - expect(within(result.getByTestId('closedStatsHeader')).getByText(130)).toBeTruthy(); - expect(within(result.getByTestId('mttrStatsHeader')).getByText('12s')).toBeTruthy(); - }); + appMockRenderer.render(); + + expect(await screen.findByTestId('cases-metrics-stats')).toBeInTheDocument(); + + expect( + within(await screen.findByTestId('openStatsHeader')).getByText('20') + ).toBeInTheDocument(); + + expect( + within(await screen.findByTestId('inProgressStatsHeader')).getByText('40') + ).toBeInTheDocument(); + + expect( + within(await screen.findByTestId('closedStatsHeader')).getByText('130') + ).toBeInTheDocument(); + + expect( + within(await screen.findByTestId('mttrStatsHeader')).getByText('2ms') + ).toBeInTheDocument(); }); }); From b15266844b98835714e8aac96235453cf55a23d2 Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Tue, 9 Jan 2024 10:59:30 +0100 Subject: [PATCH 4/6] [Ops] Make unit-test agent agnostic (#174441) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary This is not an error now but will be required for https://github.com/elastic/kibana-operations/issues/15 - this solution should work in both scenarios, so it can be done up-front. Quote from Brian's notes regarding buildkite migration: >The buildkite-agent process is running with a different umask in the new system. Files are being created with slightly different permissions by default. For example, when the kibana repo is checked out, files have 664 permissions instead of 644. This shouldn’t cause any major issues for Kibana, BUT a few tests check the permission flags on files during a copy process. They should probably be changed to check the permissions on the source file rather than just hard-coding them. This is showing up in the unit tests like this: ``` FAIL src/cli_plugin/install/zip.test.js --   | ● kibana cli › zip › checkFilePermission › verify consistency of modes of files   |     | expect(received).toEqual(expected) // deep equality   |     | Expected: "755"   | Received: "775" ``` We can't access the source files inside the zip file, the rights will only be revealed after unzipping. However, the difference in the default access rights is in the RW and not the X, which we're really curious about. So as a solution, I'm only checking if the executable file is indeed executable by all, and the non-executable is not executable by anyone. --- src/cli_plugin/install/zip.test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli_plugin/install/zip.test.js b/src/cli_plugin/install/zip.test.js index cdeb345951731..e651c3fe91284 100644 --- a/src/cli_plugin/install/zip.test.js +++ b/src/cli_plugin/install/zip.test.js @@ -15,7 +15,8 @@ import globby from 'globby'; import { analyzeArchive, extractArchive } from './zip'; -const getMode = (path) => (fs.statSync(path).mode & parseInt('777', 8)).toString(8); +const getExecFlags = (path) => + (fs.statSync(path).mode & parseInt('111', 8)).toString(8).padStart(3, '0'); describe('kibana cli', function () { describe('zip', function () { @@ -83,8 +84,8 @@ describe('kibana cli', function () { ] `); - expect(getMode(path.resolve(tempPath, 'executable'))).toEqual('755'); - expect(getMode(path.resolve(tempPath, 'not-executable'))).toEqual('644'); + expect(getExecFlags(path.resolve(tempPath, 'executable'))).toEqual('111'); + expect(getExecFlags(path.resolve(tempPath, 'not-executable'))).toEqual('000'); }); }); From 72a5f87b2414552d25756a94330e44115d1ce21a Mon Sep 17 00:00:00 2001 From: Alex Szabo Date: Tue, 9 Jan 2024 11:04:02 +0100 Subject: [PATCH 5/6] Deployment investigations (#174345) ## Summary Both cloud and serverless deployments of https://github.com/elastic/kibana/pull/172257 are failing. These are small additions to help investigation, or fix potential errors. --- .buildkite/scripts/steps/cloud/build_and_deploy.sh | 2 +- .buildkite/scripts/steps/serverless/build_and_deploy.sh | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.buildkite/scripts/steps/cloud/build_and_deploy.sh b/.buildkite/scripts/steps/cloud/build_and_deploy.sh index b6c2dcd0968e3..62f92b716b651 100755 --- a/.buildkite/scripts/steps/cloud/build_and_deploy.sh +++ b/.buildkite/scripts/steps/cloud/build_and_deploy.sh @@ -62,7 +62,7 @@ fi echo "--- Create Deployment" CLOUD_DEPLOYMENT_ID=$(ecctl deployment list --output json | jq -r '.deployments[] | select(.name == "'$CLOUD_DEPLOYMENT_NAME'") | .id') -if [ -z "${CLOUD_DEPLOYMENT_ID}" ]; then +if [ -z "${CLOUD_DEPLOYMENT_ID}" ] || [ "${CLOUD_DEPLOYMENT_ID}" = 'null' ]; then jq ' .resources.kibana[0].plan.kibana.docker_image = "'$KIBANA_CLOUD_IMAGE'" | .resources.elasticsearch[0].plan.elasticsearch.docker_image = "'$ELASTICSEARCH_CLOUD_IMAGE'" | diff --git a/.buildkite/scripts/steps/serverless/build_and_deploy.sh b/.buildkite/scripts/steps/serverless/build_and_deploy.sh index a78252e3baec0..3e69f4b4878b7 100644 --- a/.buildkite/scripts/steps/serverless/build_and_deploy.sh +++ b/.buildkite/scripts/steps/serverless/build_and_deploy.sh @@ -59,6 +59,11 @@ deploy() { -XPOST -d "$PROJECT_CREATE_CONFIGURATION" &>> $DEPLOY_LOGS PROJECT_ID=$(jq -r --slurp '.[1].id' $DEPLOY_LOGS) + if [ -z "${PROJECT_ID}" ] || [ "$PROJECT_ID" = 'null' ]; then + echo "Failed to create project. Deploy logs:" + cat $DEPLOY_LOGS + exit 1 + fi echo "Get credentials..." curl -s -XPOST -H "Authorization: ApiKey $PROJECT_API_KEY" \ From 8f9e11d001a53d64d593bf49c4570523d8e48704 Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 9 Jan 2024 11:11:51 +0100 Subject: [PATCH 6/6] [Synthetics] Increase Project monitor payload limit to 50MiB (#174470) ## Summary Follow up to https://github.com/elastic/synthetics/pull/884 Increase Project monitor payload route limit to 50MiB !! --- .../e2e/synthetics/journeys/test_run_details.journey.ts | 8 +++++++- .../server/routes/monitor_cruds/add_monitor_project.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/synthetics/e2e/synthetics/journeys/test_run_details.journey.ts b/x-pack/plugins/synthetics/e2e/synthetics/journeys/test_run_details.journey.ts index 5189db3c4c359..fdd281b40dcc2 100644 --- a/x-pack/plugins/synthetics/e2e/synthetics/journeys/test_run_details.journey.ts +++ b/x-pack/plugins/synthetics/e2e/synthetics/journeys/test_run_details.journey.ts @@ -68,7 +68,13 @@ journey(`TestRunDetailsPage`, async ({ page, params }) => { step('Go to test run page', async () => { await page.click(byTestId('superDatePickerToggleQuickMenuButton')); - await page.click('text=Last 1 year'); + await page.getByTestId('superDatePickerQuickMenu').getByLabel('Time value').fill('10'); + await page + .getByTestId('superDatePickerQuickMenu') + .getByLabel('Time unit') + .selectOption('Years'); + await page.getByTestId('superDatePickerQuickMenu').getByText('Apply').click(); + await page.mouse.wheel(0, 1000); await page.click(byTestId('row-ab240846-8d22-11ed-8fac-52bb19a2321e')); await page.waitForSelector('text=Test run details'); diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts index f878e8bb40c70..1fb924a57a56e 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts @@ -13,7 +13,7 @@ import { ProjectMonitor } from '../../../common/runtime_types'; import { SYNTHETICS_API_URLS } from '../../../common/constants'; import { ProjectMonitorFormatter } from '../../synthetics_service/project_monitor/project_monitor_formatter'; -const MAX_PAYLOAD_SIZE = 1048576 * 20; // 20MiB +const MAX_PAYLOAD_SIZE = 1048576 * 50; // 20MiB export const addSyntheticsProjectMonitorRoute: SyntheticsRestApiRouteFactory = () => ({ method: 'PUT',