Skip to content

Commit

Permalink
[Synthetics] adjust run_from.id for private locations (#156324)
Browse files Browse the repository at this point in the history
## Summary

Resolves #156320

Adjust the value of the `run_from.id` field.

Before
Both the `run_from.id` and the `run_from.name` were the same value.

After
<img width="543" alt="Screen Shot 2023-05-01 at 7 55 24 PM"
src="https://user-images.githubusercontent.com/11356435/235551964-bb9c419d-2ada-4a39-bd08-ce6f5021747b.png">

### Testing
1. Check out this PR from integrations
elastic/integrations#6047
2. In the integrations repo `cd packages/synthetics`
3. Run `elastic-package clean` then `elastic-package build` (You may
need to upgrade elastic package if you're significantly behind)
4. In your `kibana.dev.yml` file add `xpack.fleet.registryUrl:
https://localhost:8080`
5. Start kibana with
`NODE_EXTRA_CA_CERTS=$HOME/.elastic-package/profiles/default/certs/kibana/ca-cert.pem
yarn start --no-base-path`
6. Create a private location
7. Create a monitor assigned to that private location
8. Inspect the agent policy for that private location, then find the
integration policy for that monitor. Ensure the `run_from.id` is the id
of the location, and the `run_from.name` is the name of the location.

(If you run into problems setting up your local kibana connected to
elastic-package registry, see
https://github.com/elastic/security-team/blob/main/docs/cloud-security-posture-team/kibana/local-setup-using-elastic-package.mdx)

---------

Co-authored-by: shahzad31 <shahzad31comp@gmail.com>
  • Loading branch information
dominiqueclarke and shahzad31 authored May 12, 2023
1 parent 1f99a04 commit f59471b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
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

0 comments on commit f59471b

Please sign in to comment.