Skip to content

Commit

Permalink
Merge branch '8.10' into backport/8.10/pr-166394
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Sep 27, 2023
2 parents 127a70d + 3ee1d4d commit b396335
Show file tree
Hide file tree
Showing 108 changed files with 1,260 additions and 1,059 deletions.
3 changes: 2 additions & 1 deletion .buildkite/pipelines/pull_request/fleet_cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ steps:
agents:
queue: n2-4-spot
depends_on: build
timeout_in_minutes: 120
timeout_in_minutes: 50
parallelism: 6
retry:
automatic:
- exit_status: '-1'
Expand Down
13 changes: 0 additions & 13 deletions .buildkite/pipelines/pull_request/osquery_cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,3 @@ steps:
artifact_paths:
- "target/kibana-osquery/**/*"

- command: .buildkite/scripts/steps/functional/security_serverless_osquery.sh
label: 'Serverless Osquery Cypress Tests'
agents:
queue: n2-4-spot
depends_on: build
timeout_in_minutes: 50
parallelism: 6
retry:
automatic:
- exit_status: '*'
limit: 1
artifact_paths:
- "target/kibana-osquery/**/*"
10 changes: 6 additions & 4 deletions .buildkite/scripts/steps/functional/fleet_cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
set -euo pipefail

source .buildkite/scripts/steps/functional/common.sh
source .buildkite/scripts/steps/functional/common_cypress.sh

export JOB=kibana-fleet-cypress
export KIBANA_INSTALL_DIR=${KIBANA_BUILD_LOCATION}

echo "--- Fleet Cypress tests"

node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
--config x-pack/test/fleet_cypress/cli_config.ts
cd x-pack/plugins/fleet

set +e
yarn cypress:run:reporter; status=$?; yarn junit:merge || :; exit $status
2 changes: 1 addition & 1 deletion .buildkite/scripts/steps/functional/profiling_cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ echo "--- Profiling Cypress Tests"

cd "$XPACK_DIR"

node plugins/profiling/scripts/test/e2e.js \
NODE_OPTIONS=--openssl-legacy-provider node plugins/profiling/scripts/test/e2e.js \
--kibana-install-dir "$KIBANA_BUILD_LOCATION" \
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@
"del": "^6.1.0",
"elastic-apm-node": "^3.49.1",
"email-addresses": "^5.0.0",
"execa": "^4.0.2",
"execa": "^5.1.1",
"expiry-js": "0.1.7",
"extract-zip": "^2.0.1",
"fast-deep-equal": "^3.1.1",
Expand Down Expand Up @@ -1414,7 +1414,7 @@
"cssnano": "^5.1.12",
"cssnano-preset-default": "^5.2.12",
"csstype": "^3.0.2",
"cypress": "^12.13.0",
"cypress": "^12.17.4",
"cypress-axe": "^1.4.0",
"cypress-file-upload": "^5.0.8",
"cypress-multi-reporters": "^1.6.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,36 @@ describe('DocumentMigrator', () => {
]);
});

it('does not lose namespaces in documents with undefined namespace and defined namespaces property', () => {
const migrator = new DocumentMigrator({
...testOpts(),
typeRegistry: createRegistry(
{ name: 'dog', namespaceType: 'multiple', convertToMultiNamespaceTypeVersion: '1.0.0' }
// no migration transforms are defined, the typeMigrationVersion will be derived from 'convertToMultiNamespaceTypeVersion'
),
});
migrator.prepareMigrations();
const obj = {
id: 'mischievous',
type: 'dog',
attributes: { name: 'Ann' },
coreMigrationVersion: kibanaVersion,
typeMigrationVersion: '0.1.0',
namespaces: ['something'],
} as SavedObjectUnsanitizedDoc;
const actual = migrator.migrateAndConvert(obj);
expect(actual).toEqual([
{
id: 'mischievous',
type: 'dog',
attributes: { name: 'Ann' },
coreMigrationVersion: kibanaVersion,
typeMigrationVersion: '1.0.0',
namespaces: ['something'],
},
]);
});

it('does not fail when encountering documents with coreMigrationVersion higher than the latest known', () => {
const migrator = new DocumentMigrator({
...testOpts(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ function convertNamespaceType(doc: SavedObjectUnsanitizedDoc) {
const { namespace, ...otherAttrs } = doc;
const additionalDocs: SavedObjectUnsanitizedDoc[] = [];

if (namespace == null && otherAttrs.namespaces) {
return {
additionalDocs,
transformedDoc: otherAttrs,
};
}

// If this object exists in the default namespace, return it with the appropriate `namespaces` field without changing its ID.
if (namespace === undefined) {
return {
Expand Down
6 changes: 2 additions & 4 deletions test/scripts/jenkins_fleet_cypress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ source test/scripts/jenkins_test_setup_xpack.sh
echo " -> Running fleet cypress tests"
cd "$XPACK_DIR"

node scripts/functional_tests \
--debug --bail \
--kibana-install-dir "$KIBANA_INSTALL_DIR" \
--config test/fleet_cypress/cli_config.ts
cd x-pack/plugins/fleet
yarn --cwd x-pack/plugins/fleet cypress:run

echo ""
echo ""
6 changes: 5 additions & 1 deletion x-pack/plugins/apm/scripts/test/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function runTests() {

return childProcess.spawnSync('node', spawnArgs, {
cwd: e2eDir,
env: { ...process.env, CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs) },
env: {
...process.env,
CYPRESS_CLI_ARGS: JSON.stringify(cypressCliArgs),
NODE_OPTIONS: '--openssl-legacy-provider',
},
encoding: 'utf8',
stdio: 'inherit',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useEffect, useState, ChangeEvent } from 'react';
import { useActions, useValues } from 'kea';

import {
EuiCallOut,
EuiFieldSearch,
EuiFlexGroup,
EuiFlexItem,
Expand Down Expand Up @@ -73,7 +74,7 @@ export const SearchIndexDocuments: React.FC = () => {

const { makeRequest: getDocuments } = useActions(documentLogic);
const { makeRequest: getMappings } = useActions(mappingLogic);
const { data, status } = useValues(documentLogic);
const { data, status, error } = useValues(documentLogic);
const { data: mappingData, status: mappingStatus } = useValues(mappingLogic);

const docs = data?.results?.hits.hits ?? [];
Expand All @@ -83,6 +84,8 @@ export const SearchIndexDocuments: React.FC = () => {

const shouldShowAccessControlSwitcher =
hasDocumentLevelSecurityFeature && productFeatures.hasDocumentLevelSecurityEnabled;
const isAccessControlIndexNotFound =
shouldShowAccessControlSwitcher && error?.body?.statusCode === 404;

useEffect(() => {
getDocuments({
Expand Down Expand Up @@ -140,11 +143,29 @@ export const SearchIndexDocuments: React.FC = () => {
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem>
{docs.length === 0 &&
{isAccessControlIndexNotFound && (
<EuiCallOut
size="m"
title={i18n.translate(
'xpack.enterpriseSearch.content.searchIndex.documents.noIndex.title',
{ defaultMessage: 'Access Control Index not found' }
)}
iconType="iInCircle"
>
<p>
{i18n.translate('xpack.enterpriseSearch.content.searchIndex.documents.noIndex', {
defaultMessage:
"An Access Control Index won't be created until you enable document-level security and run your first access control sync.",
})}
</p>
</EuiCallOut>
)}
{!isAccessControlIndexNotFound &&
docs.length === 0 &&
i18n.translate('xpack.enterpriseSearch.content.searchIndex.documents.noMappings', {
defaultMessage: 'No documents found for index',
})}
{docs.length > 0 && (
{!isAccessControlIndexNotFound && docs.length > 0 && (
<DocumentList
docs={docs}
docsPerPage={pagination.pageSize}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { useEffect, useState } from 'react';
import { useActions, useValues } from 'kea';

import {
EuiCallOut,
EuiCode,
EuiCodeBlock,
EuiFlexGroup,
Expand Down Expand Up @@ -54,9 +55,12 @@ export const SearchIndexIndexMappings: React.FC = () => {
? indexName
: indexName.replace('search-', CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX);
const { makeRequest: makeMappingRequest } = useActions(mappingsWithPropsApiLogic(indexToShow));
const { data: mappingData } = useValues(mappingsWithPropsApiLogic(indexToShow));
const { data: mappingData, error } = useValues(mappingsWithPropsApiLogic(indexToShow));
const shouldShowAccessControlSwitch =
hasDocumentLevelSecurityFeature && productFeatures.hasDocumentLevelSecurityEnabled;
const isAccessControlIndexNotFound =
shouldShowAccessControlSwitch && error?.body?.statusCode === 404;

useEffect(() => {
makeMappingRequest({ indexName: indexToShow });
}, [indexToShow, indexName]);
Expand All @@ -76,9 +80,27 @@ export const SearchIndexIndexMappings: React.FC = () => {
</EuiFlexItem>
)}
<EuiFlexItem grow>
<EuiCodeBlock language="json" isCopyable>
{JSON.stringify(mappingData, null, 2)}
</EuiCodeBlock>
{isAccessControlIndexNotFound ? (
<EuiCallOut
size="m"
title={i18n.translate(
'xpack.enterpriseSearch.content.searchIndex.mappings.noIndex.title',
{ defaultMessage: 'Access Control Index not found' }
)}
iconType="iInCircle"
>
<p>
{i18n.translate('xpack.enterpriseSearch.content.searchIndex.mappings.noIndex', {
defaultMessage:
"An Access Control Index won't be created until you enable document-level security and run your first access control sync.",
})}
</p>
</EuiCallOut>
) : (
<EuiCodeBlock language="json" isCopyable>
{JSON.stringify(mappingData, null, 2)}
</EuiCodeBlock>
)}
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ElasticsearchAssetType, KibanaAssetType } from '../types/models';

export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-packages';
export const ASSETS_SAVED_OBJECT_TYPE = 'epm-packages-assets';
export const MAX_TIME_COMPLETE_INSTALL = 60000;
export const MAX_TIME_COMPLETE_INSTALL = 30 * 60 * 1000; // 30 minutes

export const FLEET_SYSTEM_PACKAGE = 'system';
export const FLEET_ELASTIC_AGENT_PACKAGE = 'elastic_agent';
Expand Down
14 changes: 8 additions & 6 deletions x-pack/plugins/fleet/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ export default defineCypressConfig({
viewportWidth: 1440,
screenshotOnRunFailure: true,

env: {
protocol: 'http',
hostname: 'localhost',
configport: '5601',
},

e2e: {
baseUrl: 'http://localhost:5601',

experimentalRunAllSpecs: true,
experimentalMemoryManagement: true,
numTestsKeptInMemory: 3,

specPattern: './cypress/e2e/**/*.cy.ts',
supportFile: './cypress/support/e2e.ts',

setupNodeEvents(on, config) {
// eslint-disable-next-line @typescript-eslint/no-var-requires, @kbn/imports/no_boundary_crossing
return require('./cypress/plugins')(on, config);
Expand Down
21 changes: 6 additions & 15 deletions x-pack/plugins/fleet/cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ node scripts/build_kibana_platform_plugins

# launch the cypress test runner
cd x-pack/plugins/fleet
yarn cypress:run-as-ci
yarn cypress:run
```

#### FTR + Interactive

This is the preferred mode for developing new tests.
Expand All @@ -67,17 +68,7 @@ node scripts/build_kibana_platform_plugins

# launch the cypress test runner
cd x-pack/plugins/fleet
yarn cypress:open-as-ci
```

Alternatively, kibana test server can be started separately, to pick up changes in UI (e.g. change in data-test-subj selector)

```
# launch kibana test server
node scripts/functional_tests_server --config x-pack/test/fleet_cypress/config.ts
# launch cypress runner
node scripts/functional_test_runner --config x-pack/test/fleet_cypress/visual_config.ts
yarn cypress:open
```

Note that you can select the browser you want to use on the top right side of the interactive runner.
Expand Down Expand Up @@ -108,7 +99,7 @@ Each file inside the screens folder represents a screen in our application.

_Tasks_ are functions that may be reused across tests.

Each file inside the tasks folder represents a screen of our application.
Each file inside the tasks folder represents a screen of our application.

## Test data

Expand Down Expand Up @@ -141,7 +132,7 @@ Note that the command will create the folder if it does not exist.

## Development Best Practices

### Clean up the state
### Clean up the state

Remember to clean up the state of the test after its execution, typically with the `cleanKibana` function. Be mindful of failure scenarios, as well: if your test fails, will it leave the environment in a recoverable state?

Expand All @@ -164,7 +155,7 @@ Remember that minimizing the number of times the web page is loaded, we minimize

The `checkA11y({ skipFailures: false });` call uses [axe-core](https://github.com/dequelabs/axe-core) to perform a full page check for accessibility violations.

See [axe-core](https://github.com/dequelabs/axe-core)'s documentation for details on what is checked for.
See [axe-core](https://github.com/dequelabs/axe-core)'s documentation for details on what is checked for.

## Linting

Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/fleet/cypress/e2e/a11y/home_page.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ import { AGENT_POLICY_NAME_LINK } from '../../screens/integrations';
import { cleanupAgentPolicies, unenrollAgent } from '../../tasks/cleanup';
import { setFleetServerHost } from '../../tasks/fleet_server';

import { login } from '../../tasks/login';
import { request } from '../../tasks/common';

describe('Home page', () => {
before(() => {
setFleetServerHost('https://fleetserver:8220');
});

beforeEach(() => {
login();
});

describe('Agents', () => {
beforeEach(() => {
navigateTo(FLEET);
Expand Down Expand Up @@ -148,7 +155,7 @@ describe('Home page', () => {

describe('Uninstall Tokens', () => {
before(() => {
cy.request({
request({
method: 'POST',
url: '/api/fleet/agent_policies',
body: { name: 'Agent policy for A11y test', namespace: 'default', id: 'agent-policy-a11y' },
Expand All @@ -160,7 +167,7 @@ describe('Home page', () => {
cy.getBySel(UNINSTALL_TOKENS_TAB).click();
});
after(() => {
cy.request({
request({
method: 'POST',
url: '/api/fleet/agent_policies/delete',
body: { agentPolicyId: 'agent-policy-a11y' },
Expand All @@ -180,6 +187,7 @@ describe('Home page', () => {

describe('Data Streams', () => {
before(() => {
login();
navigateTo(FLEET);
cy.getBySel(DATA_STREAMS_TAB, { timeout: 15000 }).should('be.visible');
cy.getBySel(DATA_STREAMS_TAB).click();
Expand Down
Loading

0 comments on commit b396335

Please sign in to comment.