Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Synthetics] adjust run_from.id for private locations #156324

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('8.8.0 Synthetics Package Policy migration', () => {
});

describe('throttling migration', () => {
it('handles throtling config for throttling: false', () => {
it('handles throttling config for throttling: false', () => {
const actual = migration(getBrowserPolicy('false'), {} as SavedObjectMigrationContext);
expect(actual.attributes?.inputs[3]?.streams[0]?.vars?.['throttling.config']?.value).toEqual(
'false'
Expand Down Expand Up @@ -164,4 +164,16 @@ describe('8.8.0 Synthetics Package Policy migration', () => {
});
});
});

describe('location id migration', () => {
it('set run from id as agent policy id', () => {
const actual = migration(httpPolicy, {} as SavedObjectMigrationContext);
expect(actual.attributes?.inputs[0]?.streams[0]?.vars?.location_id?.value).toEqual(
'fa2e69b0-dec6-11ed-8746-c5b1a1a12ec1'
);
expect(actual.attributes?.inputs[0]?.streams[0]?.compiled_stream?.location_id).toEqual(
'fa2e69b0-dec6-11ed-8746-c5b1a1a12ec1'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@ export const ALLOWED_SCHEDULES_IN_MINUTES = [
export const migratePackagePolicyToV880: SavedObjectMigrationFn<PackagePolicy, PackagePolicy> = (
packagePolicyDoc
) => {
if (packagePolicyDoc.attributes.package?.name !== 'synthetics') {
if (
packagePolicyDoc.attributes.package?.name !== 'synthetics' ||
!packagePolicyDoc.attributes.is_managed
) {
return packagePolicyDoc;
}

const agentPolicyId = packagePolicyDoc.attributes.policy_id;

const updatedPackagePolicyDoc: SavedObjectUnsanitizedDoc<PackagePolicy> = packagePolicyDoc;

const enabledInput = updatedPackagePolicyDoc.attributes.inputs.find(
Expand Down Expand Up @@ -66,6 +71,12 @@ export const migratePackagePolicyToV880: SavedObjectMigrationFn<PackagePolicy, P
}
}

// set location_id.id to agentPolicyId
if (enabledStream.vars) {
enabledStream.vars.location_id = { value: agentPolicyId, type: 'text' };
enabledStream.compiled_stream.location_id = agentPolicyId;
}

return updatedPackagePolicyDoc;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const formatSyntheticsPolicy = (
config: Partial<
MonitorFields & {
location_name: string;
location_id: string;
'monitor.project.name': string;
'monitor.project.id': string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const ObserverCodec = t.partial({
hostname: t.string,
ip: t.array(t.string),
mac: t.array(t.string),
name: t.union([t.string, t.undefined]),
geo: t.partial({
name: t.string,
continent_name: t.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class SyntheticsPrivateLocation {
...(config as Partial<MonitorFields>),
config_id: config.fields?.config_id,
location_name: privateLocation.label,
location_id: privateLocation.id,
'monitor.project.id': config.fields?.['monitor.project.name'],
'monitor.project.name': config.fields?.['monitor.project.name'],
},
Expand Down