Skip to content

Commit

Permalink
[Synthetics] Update package to 1.0.7 (#166822)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Sep 20, 2023
1 parent a31cc1f commit 010f585
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 62 deletions.
Expand Up @@ -17,7 +17,10 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { getFixtureJson } from './helper/get_fixture_json';
import { comparePolicies, getTestSyntheticsPolicy } from './sample_data/test_policy';
import { PrivateLocationTestService } from './services/private_location_test_service';
import {
INSTALLED_VERSION,
PrivateLocationTestService,
} from './services/private_location_test_service';

export default function ({ getService }: FtrProviderContext) {
describe('PrivateLocationAddMonitor', function () {
Expand Down Expand Up @@ -537,7 +540,7 @@ export default function ({ getService }: FtrProviderContext) {
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);

expect(packagePolicy.package.version).eql('1.0.4');
expect(packagePolicy.package.version).eql(INSTALLED_VERSION);

await supertestAPI.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
const policyResponseAfterUpgrade = await supertestAPI.get(
Expand All @@ -547,7 +550,7 @@ export default function ({ getService }: FtrProviderContext) {
(pkgPolicy: PackagePolicy) =>
pkgPolicy.id === monitorId + '-' + testFleetPolicyID + `-default`
);
expect(semver.gte(packagePolicyAfterUpgrade.package.version, '1.0.4')).eql(true);
expect(semver.gte(packagePolicyAfterUpgrade.package.version, INSTALLED_VERSION)).eql(true);
} finally {
await supertestAPI
.delete(SYNTHETICS_API_URLS.SYNTHETICS_MONITORS + '/' + monitorId)
Expand Down
Expand Up @@ -201,6 +201,7 @@ export default function ({ getService }: FtrProviderContext) {
schedule: '@every 5m',
timeout: '3ms',
max_redirects: 3,
max_attempts: 2,
proxy_url: 'http://proxy.com',
tags: ['tag1', 'tag2'],
username: 'test-username',
Expand Down
Expand Up @@ -8,6 +8,8 @@
import { omit, sortBy } from 'lodash';
import expect from '@kbn/expect';
import { PackagePolicy, PackagePolicyConfigRecord } from '@kbn/fleet-plugin/common';
import { INSTALLED_VERSION } from '../services/private_location_test_service';
import { commonVars } from './test_project_monitor_policy';

interface PolicyProps {
name?: string;
Expand All @@ -29,7 +31,7 @@ export const getTestSyntheticsPolicy = (props: PolicyProps): PackagePolicy => {
version: 'WzE2MjYsMV0=',
name: 'test-monitor-name-Test private location 0-default',
namespace: namespace ?? 'testnamespace',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.4' },
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '5347cd10-0368-11ed-8df7-a7424c6f5167',
inputs: [
Expand Down Expand Up @@ -166,6 +168,7 @@ export const getHttpInput = ({
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand Down Expand Up @@ -241,6 +244,7 @@ export const getHttpInput = ({
value: JSON.stringify(location.name) ?? '"Test private location 0"',
type: 'text',
},
...commonVars,
id: { value: JSON.stringify(id), type: 'text' },
origin: { value: projectId ? 'project' : 'ui', type: 'text' },
ipv4: { type: 'bool', value: true },
Expand All @@ -261,6 +265,7 @@ export const getHttpInput = ({
schedule: '@every 5m',
timeout: '3ms',
max_redirects: 3,
max_attempts: 2,
proxy_url: proxyUrl ?? 'http://proxy.com',
tags: ['tag1', 'tag2'],
username: 'test-username',
Expand Down Expand Up @@ -471,46 +476,22 @@ export const getBrowserInput = ({ id, params, isBrowser, projectId }: PolicyProp
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser'),
vars: browserVars,
id: 'synthetics/browser-browser-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: compiledBrowser,
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.network',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser.network'),
id: 'synthetics/browser-browser.network-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.screenshot',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser.screenshot'),
id: 'synthetics/browser-browser.screenshot-2bfd7da0-22ed-11ed-8c6b-09a2d21dfbc3-27337270-22ed-11ed-8c6b-09a2d21dfbc3-default',
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
Expand All @@ -520,6 +501,16 @@ export const getBrowserInput = ({ id, params, isBrowser, projectId }: PolicyProp
};
};

export const getDataStream = (dataset: string) => ({
dataset,
type: 'synthetics',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
});

export const omitIds = (policy: PackagePolicy) => {
policy.inputs = sortBy(policy.inputs, 'type');

Expand Down
Expand Up @@ -6,6 +6,15 @@
*/

import { PackagePolicy } from '@kbn/fleet-plugin/common';
import { INSTALLED_VERSION } from '../services/private_location_test_service';
import { getDataStream } from './test_policy';

export const commonVars = {
max_attempts: {
type: 'integer',
value: 2,
},
};

export const getTestProjectSyntheticsPolicyLightweight = (
{
Expand Down Expand Up @@ -37,7 +46,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`,
namespace: 'default',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.4' },
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
inputs: [
Expand Down Expand Up @@ -122,6 +131,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
type: 'integer',
value: '0',
},
...commonVars,
mode: {
type: 'text',
value: 'any',
Expand Down Expand Up @@ -240,6 +250,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
schedule: '@every 60m',
timeout: '80s',
max_redirects: 0,
max_attempts: 2,
tags: ['tag2', 'tag2'],
proxy_url: 'testGlobalParamOverwrite',
'run_from.geo.name': locationName ?? 'Test private location 0',
Expand Down Expand Up @@ -314,6 +325,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand Down Expand Up @@ -348,6 +360,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
tags: { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand Down Expand Up @@ -416,6 +429,7 @@ export const getTestProjectSyntheticsPolicyLightweight = (
'source.zip_url.proxy_url': { type: 'text' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
...inputs,
Expand Down Expand Up @@ -520,7 +534,7 @@ export const getTestProjectSyntheticsPolicy = (
version: 'WzEzMDksMV0=',
name: `4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-Test private location 0`,
namespace: 'default',
package: { name: 'synthetics', title: 'Elastic Synthetics', version: '1.0.4' },
package: { name: 'synthetics', title: 'Elastic Synthetics', version: INSTALLED_VERSION },
enabled: true,
policy_id: '46034710-0ba6-11ed-ba04-5f123b9faa8b',
inputs: [
Expand Down Expand Up @@ -570,6 +584,7 @@ export const getTestProjectSyntheticsPolicy = (
'ssl.supported_protocols': { type: 'yaml' },
location_id: { value: 'fleet_managed', type: 'text' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand Down Expand Up @@ -612,6 +627,7 @@ export const getTestProjectSyntheticsPolicy = (
'ssl.verification_mode': { type: 'text' },
'ssl.supported_protocols': { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
...commonVars,
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand Down Expand Up @@ -645,6 +661,10 @@ export const getTestProjectSyntheticsPolicy = (
timeout: { type: 'text' },
tags: { type: 'yaml' },
location_name: { value: 'Fleet managed', type: 'text' },
max_attempts: {
type: 'integer',
value: 2,
},
id: { type: 'text' },
origin: { type: 'text' },
ipv4: { type: 'bool', value: true },
Expand All @@ -662,15 +682,7 @@ export const getTestProjectSyntheticsPolicy = (
streams: [
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser'),
vars: {
__ui: {
value: '{"script_source":{"is_generated_script":false,"file_name":""}}',
Expand Down Expand Up @@ -719,6 +731,7 @@ export const getTestProjectSyntheticsPolicy = (
'source.zip_url.ssl.supported_protocols': { type: 'yaml' },
'source.zip_url.proxy_url': { type: 'text' },
location_name: { value: 'Test private location 0', type: 'text' },
...commonVars,
location_id: { value: 'fleet_managed', type: 'text' },
id: { value: id, type: 'text' },
origin: { value: 'project', type: 'text' },
Expand Down Expand Up @@ -756,31 +769,15 @@ export const getTestProjectSyntheticsPolicy = (
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.network',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser.network'),
id: `synthetics/browser-browser.network-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`,
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
},
},
{
enabled: true,
data_stream: {
type: 'synthetics',
dataset: 'browser.screenshot',
elasticsearch: {
privileges: {
indices: ['auto_configure', 'create_doc', 'read'],
},
},
},
data_stream: getDataStream('browser.screenshot'),
id: `synthetics/browser-browser.screenshot-4b6abc6c-118b-4d93-a489-1135500d09f1-${projectId}-default-d70a46e0-22ea-11ed-8c6b-09a2d21dfbc3`,
compiled_stream: {
processors: [{ add_fields: { target: '', fields: { 'monitor.fleet_managed': true } } }],
Expand Down
Expand Up @@ -10,6 +10,8 @@ import { privateLocationsSavedObjectId } from '@kbn/synthetics-plugin/server/sav
import { FtrProviderContext } from '../../../ftr_provider_context';
import { KibanaSupertestProvider } from '../../../../../../test/api_integration/services/supertest';

export const INSTALLED_VERSION = '1.0.7';

export class PrivateLocationTestService {
private supertest: ReturnType<typeof KibanaSupertestProvider>;
private readonly getService: FtrProviderContext['getService'];
Expand All @@ -22,12 +24,12 @@ export class PrivateLocationTestService {
async installSyntheticsPackage() {
await this.supertest.post('/api/fleet/setup').set('kbn-xsrf', 'true').send().expect(200);
const response = await this.supertest
.get('/api/fleet/epm/packages/synthetics/1.0.4')
.get(`/api/fleet/epm/packages/synthetics/${INSTALLED_VERSION}`)
.set('kbn-xsrf', 'true')
.expect(200);
if (response.body.item.status !== 'installed') {
await this.supertest
.post('/api/fleet/epm/packages/synthetics/1.0.4')
.post(`/api/fleet/epm/packages/synthetics/${INSTALLED_VERSION}`)
.set('kbn-xsrf', 'true')
.send({ force: true })
.expect(200);
Expand Down

0 comments on commit 010f585

Please sign in to comment.