From 5aee3c4fba328838fcf0be6a3ff2248a4c0120dd Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:58:14 -0400 Subject: [PATCH] [8.10] [Synthetics] Fix project monitor private location editing (#168064) (#168082) # Backport This will backport the following commits from `main` to `8.10`: - [[Synthetics] Fix project monitor private location editing (#168064)](https://github.com/elastic/kibana/pull/168064) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Shahzad --- .../synthetics_private_location.test.ts | 2 ++ .../private_location/synthetics_private_location.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.test.ts b/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.test.ts index 87398936e1543..21dca2b05e0fe 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.test.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.test.ts @@ -19,6 +19,7 @@ import { formatSyntheticsPolicy } from '../formatters/private_formatters/format_ import { savedObjectsServiceMock } from '@kbn/core-saved-objects-server-mocks'; import { SyntheticsServerSetup } from '../../types'; import { PrivateLocationAttributes } from '../../runtime_types/private_locations'; +import { elasticsearchServiceMock } from '@kbn/core/server/mocks'; describe('SyntheticsPrivateLocation', () => { const mockPrivateLocation: PrivateLocationAttributes = { @@ -77,6 +78,7 @@ describe('SyntheticsPrivateLocation', () => { }, coreStart: { savedObjects: savedObjectsServiceMock.createStartContract(), + elasticsearch: elasticsearchServiceMock.createStart(), }, } as unknown as SyntheticsServerSetup; diff --git a/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.ts b/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.ts index 69788a6f10ae0..d4e1a78977e36 100644 --- a/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.ts +++ b/x-pack/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.ts @@ -356,7 +356,7 @@ export class SyntheticsPrivateLocation { async createPolicyBulk(newPolicies: NewPackagePolicyWithId[]) { const soClient = this.server.coreStart.savedObjects.createInternalRepository(); - const esClient = this.server.uptimeEsClient.baseESClient; + const esClient = this.server.coreStart.elasticsearch.client.asInternalUser; if (esClient && newPolicies.length > 0) { return await this.server.fleet.packagePolicyService.bulkCreate( soClient, @@ -368,8 +368,8 @@ export class SyntheticsPrivateLocation { async updatePolicyBulk(policiesToUpdate: NewPackagePolicyWithId[]) { const soClient = this.server.coreStart.savedObjects.createInternalRepository(); - const esClient = this.server.uptimeEsClient.baseESClient; - if (soClient && esClient && policiesToUpdate.length > 0) { + const esClient = this.server.coreStart.elasticsearch.client.asInternalUser; + if (policiesToUpdate.length > 0) { const { failedPolicies } = await this.server.fleet.packagePolicyService.bulkUpdate( soClient, esClient, @@ -384,8 +384,8 @@ export class SyntheticsPrivateLocation { async deletePolicyBulk(policyIdsToDelete: string[]) { const soClient = this.server.coreStart.savedObjects.createInternalRepository(); - const esClient = this.server.uptimeEsClient.baseESClient; - if (soClient && esClient && policyIdsToDelete.length > 0) { + const esClient = this.server.coreStart.elasticsearch.client.asInternalUser; + if (policyIdsToDelete.length > 0) { try { return await this.server.fleet.packagePolicyService.delete( soClient, @@ -403,7 +403,7 @@ export class SyntheticsPrivateLocation { async deleteMonitors(configs: HeartbeatConfig[], spaceId: string) { const soClient = this.server.coreStart.savedObjects.createInternalRepository(); - const esClient = this.server.uptimeEsClient.baseESClient; + const esClient = this.server.coreStart.elasticsearch.client.asInternalUser; const policyIdsToDelete = []; for (const config of configs) {