Skip to content

Commit

Permalink
[8.10] [Synthetics] Fix project monitor private location editing (#16…
Browse files Browse the repository at this point in the history
…8064) (#168082)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Synthetics] Fix project monitor private location editing
(#168064)](#168064)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2023-10-05T10:40:40Z","message":"[Synthetics]
Fix project monitor private location editing
(#168064)","sha":"15a62fe5460230c46d6a61aecac2059b86692c9f","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:uptime","v8.11.0","v8.10.3","v8.12.0"],"number":168064,"url":"#168064
Fix project monitor private location editing
(#168064)","sha":"15a62fe5460230c46d6a61aecac2059b86692c9f"}},"sourceBranch":"main","suggestedTargetBranches":["8.11","8.10"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.10","label":"v8.10.3","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"#168064
Fix project monitor private location editing
(#168064)","sha":"15a62fe5460230c46d6a61aecac2059b86692c9f"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <shahzad31comp@gmail.com>
  • Loading branch information
kibanamachine and shahzad31 committed Oct 5, 2023
1 parent f22c74b commit 5aee3c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('SyntheticsPrivateLocation', () => {
},
coreStart: {
savedObjects: savedObjectsServiceMock.createStartContract(),
elasticsearch: elasticsearchServiceMock.createStart(),
},
} as unknown as SyntheticsServerSetup;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 5aee3c4

Please sign in to comment.