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 4 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 @@ -64,6 +64,7 @@ export const httpPolicy = {
'ssl.verification_mode': { value: null, type: 'text' },
'ssl.supported_protocols': { value: null, type: 'yaml' },
location_name: { value: 'A private location', type: 'text' },
location_id: { value: 'A private location', type: 'text' },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this. This does not exist in the current policies. It's a bad fixture.

id: { value: 'ce2f0cc6-b082-4080-9ed3-82f38743a3ed', type: 'text' },
config_id: { value: 'ce2f0cc6-b082-4080-9ed3-82f38743a3ed', type: 'text' },
run_once: { value: false, type: 'bool' },
Expand Down
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 @@ -29,6 +29,8 @@ export const migratePackagePolicyToV880: SavedObjectMigrationFn<PackagePolicy, P
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 +68,12 @@ export const migratePackagePolicyToV880: SavedObjectMigrationFn<PackagePolicy, P
}
}

// set location_id.id to agentPolicyId
if (enabledStream.vars && enabledStream.vars.location_id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This var doesn't yet exist in existing policies, so this condition will never be satisfied. We need to manually add on the new variable.

enabledStream.vars.location_id.value = agentPolicyId;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this var doesn't yet exist, but will in the version of the policy that will be shipped with 8.8.0. Because of that, we may want to also add in the type?

    enabledStream.vars.location_id = {
        type: 'text',
        value: agentPolicyId
    };

I'm not sure if creating a brand new variable that doesn't yet exist causes issues, @kpollich

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