Skip to content

Commit 5fcdfd4

Browse files
kibanamachineshahzad31cesco-f
authored
[9.1] [Synthetics] Fix sync params for custom namespace !! (#232211) (#232372)
# Backport This will backport the following commits from `main` to `9.1`: - [[Synthetics] Fix sync params for custom namespace !! (#232211)](#232211) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-08-20T11:14:53Z","message":"[Synthetics] Fix sync params for custom namespace !! (#232211)\n\n## Summary\n\nFix sync params for custom namespace !!\n\n\n### Testing\n\nDefine a custom data stream namespace on monitor and make sure syncing\nof global params works as expected.\n\n<img width=\"1439\" height=\"882\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/aa14ef26-5d71-475c-b236-bf3d70c7d828\"\n/>\n\n---------\n\nCo-authored-by: Francesco Fagnani <[email protected]>\nCo-authored-by: kibanamachine <[email protected]>","sha":"8ab7d90160021ce880587c1086da397b60130672","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:obs-ux-management","backport:version","author:obs-ux-management","v9.2.0","v9.1.1","v8.19.1"],"title":"[Synthetics] Fix sync params for custom namespace !!","number":232211,"url":"https://github.com/elastic/kibana/pull/232211","mergeCommit":{"message":"[Synthetics] Fix sync params for custom namespace !! (#232211)\n\n## Summary\n\nFix sync params for custom namespace !!\n\n\n### Testing\n\nDefine a custom data stream namespace on monitor and make sure syncing\nof global params works as expected.\n\n<img width=\"1439\" height=\"882\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/aa14ef26-5d71-475c-b236-bf3d70c7d828\"\n/>\n\n---------\n\nCo-authored-by: Francesco Fagnani <[email protected]>\nCo-authored-by: kibanamachine <[email protected]>","sha":"8ab7d90160021ce880587c1086da397b60130672"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/232211","number":232211,"mergeCommit":{"message":"[Synthetics] Fix sync params for custom namespace !! (#232211)\n\n## Summary\n\nFix sync params for custom namespace !!\n\n\n### Testing\n\nDefine a custom data stream namespace on monitor and make sure syncing\nof global params works as expected.\n\n<img width=\"1439\" height=\"882\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/aa14ef26-5d71-475c-b236-bf3d70c7d828\"\n/>\n\n---------\n\nCo-authored-by: Francesco Fagnani <[email protected]>\nCo-authored-by: kibanamachine <[email protected]>","sha":"8ab7d90160021ce880587c1086da397b60130672"}},{"branch":"9.1","label":"v9.1.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <[email protected]> Co-authored-by: Francesco Fagnani <[email protected]>
1 parent 9ed9f94 commit 5fcdfd4

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

x-pack/solutions/observability/plugins/synthetics/server/synthetics_service/private_location/synthetics_private_location.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ export class SyntheticsPrivateLocation {
323323
}
324324
}
325325

326+
this.server.logger.debug(
327+
`[editingMonitors] Creating ${policiesToCreate.length} policies, updating ${policiesToUpdate.length} policies, and deleting ${policiesToDelete.length} policies`
328+
);
329+
326330
const [_createResponse, failedUpdatesRes, _deleteResponse] = await Promise.all([
327331
this.createPolicyBulk(policiesToCreate),
328332
this.updatePolicyBulk(policiesToUpdate),

x-pack/solutions/observability/plugins/synthetics/server/tasks/sync_private_locations_monitors_task.test.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,19 @@ describe('SyncPrivateLocationMonitorsTask', () => {
171171

172172
const result = await task.runTask({ taskInstance });
173173

174-
expect(mockLogger.debug).toHaveBeenCalledWith(
175-
'Syncing private location monitors because data has changed'
174+
expect(mockLogger.debug).toHaveBeenNthCalledWith(
175+
1,
176+
'[syncGlobalParams] Syncing private location monitors, last total params 1 '
177+
);
178+
expect(mockLogger.debug).toHaveBeenNthCalledWith(
179+
2,
180+
'[syncGlobalParams] Syncing private location monitors because data has changed '
181+
);
182+
expect(mockLogger.debug).toHaveBeenNthCalledWith(
183+
3,
184+
'[syncGlobalParams] Sync of private location monitors succeeded '
176185
);
177186
expect(task.syncGlobalParams).toHaveBeenCalled();
178-
expect(mockLogger.debug).toHaveBeenCalledWith('Sync of private location monitors succeeded');
179187
expect(result.error).toBeUndefined();
180188
expect(result.state).toEqual({
181189
lastStartedAt: taskInstance.startedAt?.toISOString(),
@@ -198,7 +206,9 @@ describe('SyncPrivateLocationMonitorsTask', () => {
198206

199207
expect(getPrivateLocationsModule.getPrivateLocations).toHaveBeenCalled();
200208
expect(task.syncGlobalParams).not.toHaveBeenCalled();
201-
expect(mockLogger.debug).toHaveBeenCalledWith('Sync of private location monitors succeeded');
209+
expect(mockLogger.debug).toHaveBeenLastCalledWith(
210+
'[syncGlobalParams] Sync of private location monitors succeeded '
211+
);
202212
});
203213

204214
it('should handle errors during the run', async () => {

x-pack/solutions/observability/plugins/synthetics/server/tasks/sync_private_locations_monitors_task.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ export class SyncPrivateLocationMonitorsTask {
8787
let lastTotalParams = taskInstance.state.lastTotalParams || 0;
8888
let lastTotalMWs = taskInstance.state.lastTotalMWs || 0;
8989
try {
90-
logger.debug(
91-
`Syncing private location monitors, last total params ${lastTotalParams}, last run ${lastStartedAt}`
92-
);
90+
this.debugLog(`Syncing private location monitors, last total params ${lastTotalParams}`);
9391
const soClient = savedObjects.createInternalRepository([
9492
MAINTENANCE_WINDOW_SAVED_OBJECT_TYPE,
9593
]);
@@ -101,7 +99,7 @@ export class SyncPrivateLocationMonitorsTask {
10199
lastTotalParams = totalParams;
102100
lastTotalMWs = totalMWs;
103101
if (hasDataChanged) {
104-
logger.debug(`Syncing private location monitors because data has changed`);
102+
this.debugLog(`Syncing private location monitors because data has changed`);
105103

106104
if (allPrivateLocations.length > 0) {
107105
await this.syncGlobalParams({
@@ -110,9 +108,9 @@ export class SyncPrivateLocationMonitorsTask {
110108
encryptedSavedObjects,
111109
});
112110
}
113-
logger.debug(`Sync of private location monitors succeeded`);
111+
this.debugLog(`Sync of private location monitors succeeded`);
114112
} else {
115-
logger.debug(
113+
this.debugLog(
116114
`No data has changed since last run ${lastStartedAt}, skipping sync of private location monitors`
117115
);
118116
}
@@ -201,23 +199,30 @@ export class SyncPrivateLocationMonitorsTask {
201199

202200
for (const spaceId of spaceIds) {
203201
const monitors = configsBySpaces[spaceId];
202+
this.debugLog(`Processing spaceId: ${spaceId}, monitors count: ${monitors?.length ?? 0}`);
204203
if (!monitors) {
205204
continue;
206205
}
207206
for (const monitor of monitors) {
208207
const { privateLocations } = this.parseLocations(monitor);
209208

210209
if (privateLocations.length > 0) {
211-
privateConfigs.push({ config: monitor, globalParams: paramsBySpace[monitor.namespace] });
210+
privateConfigs.push({ config: monitor, globalParams: paramsBySpace[spaceId] });
212211
}
213212
}
214213
if (privateConfigs.length > 0) {
214+
this.debugLog(
215+
`Syncing private configs for spaceId: ${spaceId}, privateConfigs count: ${privateConfigs.length}`
216+
);
217+
215218
await privateLocationAPI.editMonitors(
216219
privateConfigs,
217220
allPrivateLocations,
218221
spaceId,
219222
maintenanceWindows
220223
);
224+
} else {
225+
this.debugLog(`No privateConfigs to sync for spaceId: ${spaceId}`);
221226
}
222227
}
223228
}
@@ -381,6 +386,10 @@ export class SyncPrivateLocationMonitorsTask {
381386
totalMWs: noOfMWs,
382387
};
383388
}
389+
390+
debugLog = (message: string) => {
391+
this.serverSetup.logger.debug(`[syncGlobalParams] ${message} `);
392+
};
384393
}
385394

386395
export const runSynPrivateLocationMonitorsTaskSoon = async ({

0 commit comments

Comments
 (0)