diff --git a/.buildkite/pipelines/flaky_tests/groups.json b/.buildkite/pipelines/flaky_tests/groups.json
index aa061af00bd6c..0a5d0d488cd5d 100644
--- a/.buildkite/pipelines/flaky_tests/groups.json
+++ b/.buildkite/pipelines/flaky_tests/groups.json
@@ -25,6 +25,10 @@
"key": "xpack/cypress/fleet_cypress",
"name": "Fleet - Cypress"
},
+ {
+ "key": "xpack/cypress/apm_cypress",
+ "name": "APM - Cypress"
+ },
{
"key": "xpack/cigroup",
"name": "Default CI Group",
@@ -43,4 +47,4 @@
"name": "Default Accessibility"
}
]
-}
+}
\ No newline at end of file
diff --git a/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/integration_settings/integration_policy.spec.ts b/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/integration_settings/integration_policy.spec.ts
new file mode 100644
index 0000000000000..5cdf21d7ca9de
--- /dev/null
+++ b/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/integration_settings/integration_policy.spec.ts
@@ -0,0 +1,138 @@
+/*
+ * 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.
+ */
+
+const integrationsPoliciesPath = '/app/integrations/detail/apm/policies';
+const policyName = 'apm-integration';
+const description = 'integration description';
+const host = 'myhost:8200';
+const url = 'http://myhost:8200';
+
+const policyFormFields = [
+ {
+ selector: 'packagePolicyNameInput',
+ value: 'apm-integration',
+ required: true,
+ },
+ {
+ selector: 'packagePolicyDescriptionInput',
+ value: 'apm policy descrtiption',
+ required: false,
+ },
+ {
+ selector: 'packagePolicyHostInput',
+ value: 'myhost:8200',
+ required: true,
+ },
+ {
+ selector: 'packagePolicyUrlInput',
+ value: 'http://myhost:8200',
+ required: true,
+ },
+];
+
+const apisToIntercept = [
+ {
+ endpoint: 'api/fleet/agent_policies*',
+ name: 'fleetAgentPolicies',
+ method: 'POST',
+ },
+ {
+ endpoint: 'api/fleet/agent_status*',
+ name: 'fleetAgentStatus',
+ method: 'GET',
+ },
+ {
+ endpoint: 'api/fleet/package_policies',
+ name: 'fleetPackagePolicies',
+ method: 'POST',
+ },
+];
+
+describe('when navigating to integration page', () => {
+ beforeEach(() => {
+ const integrationsPath = '/app/integrations/browse';
+
+ cy.loginAsPowerUser();
+ cy.visit(integrationsPath);
+
+ // open integration policy form
+ cy.get('[data-test-subj="integration-card:epr:apm:featured').click();
+ cy.contains('Elastic APM in Fleet').click();
+ cy.contains('a', 'APM integration').click();
+ cy.get('[data-test-subj="addIntegrationPolicyButton"]').click();
+ });
+
+ it('checks validators for required fields', () => {
+ const requiredFields = policyFormFields.filter((field) => field.required);
+
+ requiredFields.map((field) => {
+ cy.get(`[data-test-subj="${field.selector}"`).clear();
+ cy.get('[data-test-subj="createPackagePolicySaveButton"').should(
+ 'be.disabled'
+ );
+ cy.get(`[data-test-subj="${field.selector}"`).type(field.value);
+ });
+ });
+
+ it('adds a new policy without agent', () => {
+ apisToIntercept.map(({ endpoint, method, name }) => {
+ cy.intercept(method, endpoint).as(name);
+ });
+
+ cy.url().should('include', 'app/fleet/integrations/apm/add-integration');
+ policyFormFields.map((field) => {
+ cy.get(`[data-test-subj="${field.selector}"`).clear().type(field.value);
+ });
+ cy.contains('Save and continue').click();
+ cy.wait('@fleetAgentPolicies');
+ cy.wait('@fleetAgentStatus');
+ cy.wait('@fleetPackagePolicies');
+
+ cy.get('[data-test-subj="confirmModalCancelButton').click();
+
+ cy.url().should('include', '/app/integrations/detail/apm/policies');
+ cy.contains(policyName);
+ });
+
+ it('updates an existing policy', () => {
+ apisToIntercept.map(({ endpoint, method, name }) => {
+ cy.intercept(method, endpoint).as(name);
+ });
+
+ policyFormFields.map((field) => {
+ cy.get(`[data-test-subj="${field.selector}"`)
+ .clear()
+ .type(`${field.value}-new`);
+ });
+
+ cy.contains('Save and continue').click();
+ cy.wait('@fleetAgentPolicies');
+ cy.wait('@fleetAgentStatus');
+ cy.wait('@fleetPackagePolicies');
+
+ cy.get('[data-test-subj="confirmModalCancelButton').click();
+ cy.contains(`${policyName}-new`).click();
+
+ policyFormFields.map((field) => {
+ cy.get(`[data-test-subj="${field.selector}"`)
+ .clear()
+ .type(`${field.value}-updated`);
+ });
+ cy.contains('Save integration').click();
+ cy.contains(`${policyName}-updated`);
+ });
+
+ it('should display Tail-based section on latest version', () => {
+ cy.visit('/app/fleet/integrations/apm/add-integration');
+ cy.contains('Tail-based sampling').should('exist');
+ });
+
+ it('should hide Tail-based section for 8.0.0 apm package', () => {
+ cy.visit('/app/fleet/integrations/apm-8.0.0/add-integration');
+ cy.contains('Tail-based sampling').should('not.exist');
+ });
+});
diff --git a/x-pack/plugins/apm/ftr_e2e/cypress/integration/read_only_user/integration_settings/apm_server_not_installed.ts b/x-pack/plugins/apm/ftr_e2e/cypress/integration/read_only_user/integration_settings/apm_server_not_installed.ts
deleted file mode 100644
index 354ffa5e42e18..0000000000000
--- a/x-pack/plugins/apm/ftr_e2e/cypress/integration/read_only_user/integration_settings/apm_server_not_installed.ts
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.
- */
-
-const integrationsPath = '/app/integrations/browse';
-
-describe('when navigating to the integrations browse page', () => {
- beforeEach(() => {
- cy.loginAsReadOnlyUser();
- cy.visit(integrationsPath);
- });
-
- it('should display Elastic APM integration option', () => {
- cy.get('[data-test-subj="integration-card:epr:apm:featured').should(
- 'exist'
- );
- cy.contains('Elastic APM');
- });
-
- describe('when clicking on the Elastic APM option but Fleet is not installed', () => {
- it('should display Elastic APM in Fleet tab', () => {
- cy.get('[data-test-subj="integration-card:epr:apm:featured').click();
- cy.get('[aria-selected="true"]').contains('Elastic APM in Fleet');
- cy.contains('Elastic APM now available in Fleet!');
- cy.contains('APM integration');
- });
-
- it('should display no APM server detected when checking the apm server status', () => {
- cy.intercept('POST', '/api/home/hits_status', {
- count: 0,
- }).as('hitsStatus');
-
- cy.get('[data-test-subj="integration-card:epr:apm:featured').click();
- cy.contains('Check APM Server status').click();
- cy.wait('@hitsStatus');
- cy.contains(
- 'No APM Server detected. Please make sure it is running and you have updated to 7.0 or higher.'
- );
- });
- });
-});
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_definition/apm_settings.ts b/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_definition/apm_settings.ts
index 03032a6160502..09fb0d03528ae 100644
--- a/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_definition/apm_settings.ts
+++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_definition/apm_settings.ts
@@ -31,7 +31,7 @@ export function getApmSettings(): SettingsRow[] {
'Host defines the host and port the server is listening on. URL is the unchangeable, publicly reachable server URL for deployments on Elastic Cloud or ECK.',
}
),
-
+ dataTestSubj: 'packagePolicyHostInput',
required: true,
},
{
@@ -44,6 +44,7 @@ export function getApmSettings(): SettingsRow[] {
defaultMessage: 'URL',
}
),
+ dataTestSubj: 'packagePolicyUrlInput',
required: true,
},
{
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
index 56ba3c6d47eb5..7a5e073fed337 100644
--- a/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
+++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_policy_form/settings_form/form_row_setting.tsx
@@ -45,6 +45,7 @@ export function FormRowSetting({ row, value, onChange, isDisabled }: Props) {
case 'boolean': {
return (
: undefined}
@@ -70,6 +72,7 @@ export function FormRowSetting({ row, value, onChange, isDisabled }: Props) {
case 'area': {
return (
{
@@ -82,6 +85,7 @@ export function FormRowSetting({ row, value, onChange, isDisabled }: Props) {
case 'integer': {
return (
{
@@ -96,6 +100,7 @@ export function FormRowSetting({ row, value, onChange, isDisabled }: Props) {
: [];
return (