[Synthetics] chore - synthetics unskip test in mki (#204273)

## Summary

Unskip test that was previously failing in MKI.

These tests have been run against MKI.

Background on the test
--
The test confirms that synthetics integration policies auto update when
the package version is updated. It attempts to install an older version
of the package and then run fleet setup to install a newer version of
the package and trigger auto upgrade

Why it failed
--
The test expected a lower version of the package to be installed, but a
more recent version was already installed. Therefore, when we went to
create synthetics integration policies they were installed with the most
recent version.

How we fixed it
--
Before this test, we now uninstall the Synthetics integration to ensure
we can force install an earlier version.
This commit is contained in:
Dominique Clarke 2025-01-03 11:06:00 -05:00 committed by GitHub
parent c2d20d3b4e
commit b851db3013
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 99 additions and 133 deletions

View file

@ -8,6 +8,7 @@ import moment from 'moment';
import semver from 'semver';
import { v4 as uuidv4 } from 'uuid';
import { RoleCredentials } from '@kbn/ftr-common-functional-services';
import { formatKibanaNamespace } from '@kbn/synthetics-plugin/common/formatters';
import {
ConfigKey,
HTTPFields,
@ -22,21 +23,17 @@ import rawExpect from 'expect';
import { DeploymentAgnosticFtrProviderContext } from '../../../ftr_provider_context';
import { getFixtureJson } from './helpers/get_fixture_json';
import { comparePolicies, getTestSyntheticsPolicy } from './sample_data/test_policy';
import {
INSTALLED_VERSION,
PrivateLocationTestService,
} from '../../../services/synthetics_private_location';
import { PrivateLocationTestService } from '../../../services/synthetics_private_location';
import { addMonitorAPIHelper, keyToOmitList, omitMonitorKeys } from './create_monitor';
import { SyntheticsMonitorTestService } from '../../../services/synthetics_monitor';
export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
describe('PrivateLocationAddMonitor', function () {
// see details: https://github.com/elastic/kibana/issues/204204
this.tags(['failsOnMKI']);
const kibanaServer = getService('kibanaServer');
const supertestAPI = getService('supertestWithoutAuth');
const supertestWithoutAuth = getService('supertestWithoutAuth');
const supertestWithAuth = getService('supertest');
const samlAuth = getService('samlAuth');
const retry = getService('retry');
let testFleetPolicyID: string;
let editorUser: RoleCredentials;
@ -49,7 +46,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const testPrivateLocations = new PrivateLocationTestService(getService);
const addMonitorAPI = async (monitor: any, statusCode = 200) => {
return addMonitorAPIHelper(supertestAPI, monitor, statusCode, editorUser, samlAuth);
return addMonitorAPIHelper(supertestWithoutAuth, monitor, statusCode, editorUser, samlAuth);
};
const deleteMonitor = async (
@ -83,7 +80,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
it('add a test private location', async () => {
privateLocations = await testPrivateLocations.setTestLocations([testFleetPolicyID]);
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.get(SYNTHETICS_API_URLS.SERVICE_LOCATIONS)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -122,7 +119,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
newMonitor.name = invalidName;
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -135,7 +132,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
message: `Invalid locations specified. Private Location(s) 'invalidLocation' not found. Available private locations are '${privateLocations[0].label}'`,
});
const apiGetResponse = await supertestAPI
const apiGetResponse = await supertestWithoutAuth
.get(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + `?query="${invalidName}"`)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -203,7 +200,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
},
});
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + newMonitorId)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -267,7 +264,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
({ id }) => id !== testFleetPolicyID2
);
await supertestAPI
await supertestWithoutAuth
.put(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + newMonitorId + '?internal=true')
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -317,100 +314,70 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
expect(packagePolicy).eql(undefined);
});
// it('handles spaces', async () => {
// const username = 'admin';
// const password = `${username}-password`;
// const roleName = 'uptime-role';
// const SPACE_ID = `test-space-${uuidv4()}`;
// const SPACE_NAME = `test-space-name ${uuidv4()}`;
// let monitorId = '';
// const monitor = {
// ...httpMonitorJson,
// name: `Test monitor ${uuidv4()}`,
// [ConfigKey.NAMESPACE]: 'default',
// locations: [
// {
// id: testFleetPolicyID,
// agentPolicyId: testFleetPolicyID,
// label: 'Test private location 0',
// isServiceManaged: false,
// geo: {
// lat: 0,
// lon: 0,
// },
// },
// ],
// };
it('handles spaces', async () => {
const SPACE_ID = `test-space-${uuidv4()}`;
const SPACE_NAME = `test-space-name ${uuidv4()}`;
const spaceScopedPrivateLocation = await testPrivateLocations.addTestPrivateLocation(
SPACE_ID
);
let monitorId = '';
const monitor = {
...httpMonitorJson,
name: `Test monitor ${uuidv4()}`,
[ConfigKey.NAMESPACE]: 'default',
locations: [spaceScopedPrivateLocation],
};
// try {
// await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
// await security.role.create(roleName, {
// kibana: [
// {
// feature: {
// uptime: ['all'],
// actions: ['all'],
// },
// spaces: ['*'],
// },
// ],
// });
// await security.user.create(username, {
// password,
// roles: [roleName],
// full_name: 'a kibana user',
// });
// const apiResponse = await supertestWithoutAuth
// .post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
// .auth(username, password)
// .set('kbn-xsrf', 'true')
// .send(monitor)
// .expect(200);
await kibanaServer.spaces.create({ id: SPACE_ID, name: SPACE_NAME });
const apiResponse = await supertestWithoutAuth
.post(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
.set('kbn-xsrf', 'true')
.send(monitor);
// const { created_at: createdAt, updated_at: updatedAt } = apiResponse.body;
// expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
const { created_at: createdAt, updated_at: updatedAt } = apiResponse.body;
expect([createdAt, updatedAt].map((d) => moment(d).isValid())).eql([true, true]);
// expect(omit(apiResponse.body, keyToOmitList)).eql(
// omitMonitorKeys({
// ...monitor,
// [ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID),
// url: apiResponse.body.url,
// })
// );
// monitorId = apiResponse.body.id;
expect(omit(apiResponse.body, keyToOmitList)).eql(
omitMonitorKeys({
...monitor,
[ConfigKey.NAMESPACE]: formatKibanaNamespace(SPACE_ID),
url: apiResponse.body.url,
})
);
monitorId = apiResponse.body.id;
// const policyResponse = await supertestWithAuth.get(
// '/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
// );
const policyResponse = await supertestWithAuth.get(
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
);
// const packagePolicy = policyResponse.body.items.find(
// (pkgPolicy: PackagePolicy) =>
// pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-${SPACE_ID}`
// );
const packagePolicy = policyResponse.body.items.find(
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + spaceScopedPrivateLocation.id + `-${SPACE_ID}`
);
// expect(packagePolicy.policy_id).eql(testFleetPolicyID);
// expect(packagePolicy.name).eql(`${monitor.name}-Test private location 0-${SPACE_ID}`);
// comparePolicies(
// packagePolicy,
// getTestSyntheticsPolicy({
// name: monitor.name,
// id: monitorId,
// location: { id: testFleetPolicyID },
// namespace: formatKibanaNamespace(SPACE_ID),
// spaceId: SPACE_ID,
// })
// );
// await supertestWithoutAuth
// .delete(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
// .auth(username, password)
// .set('kbn-xsrf', 'true')
// .send({ ids: [monitorId] })
// .expect(200);
// } finally {
// await security.user.delete(username);
// await security.role.delete(roleName);
// }
// });
expect(packagePolicy.policy_id).eql(spaceScopedPrivateLocation.id);
expect(packagePolicy.name).eql(
`${monitor.name}-${spaceScopedPrivateLocation.label}-${SPACE_ID}`
);
comparePolicies(
packagePolicy,
getTestSyntheticsPolicy({
name: monitor.name,
id: monitorId,
location: { id: spaceScopedPrivateLocation.id, name: spaceScopedPrivateLocation.label },
namespace: formatKibanaNamespace(SPACE_ID),
spaceId: SPACE_ID,
})
);
await supertestWithoutAuth
.delete(`/s/${SPACE_ID}${SYNTHETICS_API_URLS.SYNTHETICS_MONITORS}`)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
.send({ ids: [monitorId] })
.expect(200);
});
it('handles is_tls_enabled true', async () => {
let monitorId = '';
@ -430,7 +397,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
};
try {
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -479,7 +446,7 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
};
try {
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -510,23 +477,21 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
});
it('handles auto upgrading policies', async () => {
// force a lower version
const lowerVersion = '1.1.1';
await testPrivateLocations.installSyntheticsPackage({ version: lowerVersion });
let monitorId = '';
const privateLocation = await testPrivateLocations.addTestPrivateLocation();
const monitor = {
...httpMonitorJson,
name: `Test monitor ${uuidv4()}`,
[ConfigKey.NAMESPACE]: 'default',
locations: [
{
id: testFleetPolicyID,
label: privateLocations[0].label,
isServiceManaged: false,
},
],
locations: [privateLocation],
};
try {
const apiResponse = await supertestAPI
const apiResponse = await supertestWithoutAuth
.post(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS)
.set(editorUser.apiKeyHeader)
.set(samlAuth.getInternalRequestHeader())
@ -540,20 +505,21 @@ export default function ({ getService }: DeploymentAgnosticFtrProviderContext) {
const packagePolicy = policyResponse.body.items.find(
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
pkgPolicy.id === monitorId + '-' + privateLocation.id + `-default`
);
expect(packagePolicy.package.version).eql(INSTALLED_VERSION);
expect(packagePolicy.package.version).eql(lowerVersion);
await supertestWithAuth.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
const policyResponseAfterUpgrade = await supertestWithAuth.get(
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
);
const packagePolicyAfterUpgrade = policyResponseAfterUpgrade.body.items.find(
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);
expect(semver.gte(packagePolicyAfterUpgrade.package.version, INSTALLED_VERSION)).eql(true);
await retry.tryForTime(60 * 1000, async () => {
const policyResponseAfterUpgrade = await supertestWithAuth.get(
'/api/fleet/package_policies?page=1&perPage=2000&kuery=ingest-package-policies.package.name%3A%20synthetics'
);
const packagePolicyAfterUpgrade = policyResponseAfterUpgrade.body.items.find(
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + privateLocation.id + `-default`
);
expect(semver.gt(packagePolicyAfterUpgrade.package.version, lowerVersion)).eql(true);
});
} finally {
await deleteMonitor(monitorId);
}

View file

@ -12,7 +12,7 @@ import { SyntheticsPrivateLocations } from '@kbn/synthetics-plugin/common/runtim
import { KibanaSupertestProvider } from '@kbn/ftr-common-functional-services';
import { DeploymentAgnosticFtrProviderContext } from '../ftr_provider_context';
export const INSTALLED_VERSION = '1.1.1';
export const INSTALLED_VERSION = '1.2.4';
export class PrivateLocationTestService {
private supertestWithAuth: ReturnType<typeof KibanaSupertestProvider>;
@ -23,23 +23,23 @@ export class PrivateLocationTestService {
this.retry = getService('retry');
}
async installSyntheticsPackage() {
async installSyntheticsPackage(
{ version }: { version: string } = { version: INSTALLED_VERSION }
) {
await this.supertestWithAuth
.post('/api/fleet/setup')
.set('kbn-xsrf', 'true')
.send()
.expect(200);
const response = await this.supertestWithAuth
.get(`/api/fleet/epm/packages/synthetics/${INSTALLED_VERSION}`)
// attempt to delete any existing package so we can install specific version
await this.supertestWithAuth
.delete(`/api/fleet/epm/packages/synthetics`)
.set('kbn-xsrf', 'true');
await this.supertestWithAuth
.post(`/api/fleet/epm/packages/synthetics/${version}`)
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
if (response.body.item.status !== 'installed') {
await this.supertestWithAuth
.post(`/api/fleet/epm/packages/synthetics/${INSTALLED_VERSION}`)
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
}
}
async addTestPrivateLocation(spaceId?: string) {