[Synthetics] Use monitor query id for project monitors package policies !!#248762
Conversation
x-pack/solutions/observability/plugins/synthetics/server/tasks/clean_up_duplicate_policies.ts
Outdated
Show resolved
Hide resolved
| @@ -57,7 +57,7 @@ export async function cleanUpDuplicatedPackagePolicies( | |||
| const policyId = privateLocationAPI.getPolicyId( | |||
| { | |||
| origin: monitor.attributes.origin, | |||
| id: monitor.id, | |||
| id: monitor.attributes.id, | |||
There was a problem hiding this comment.
@benakansara @fkanout Context for why this change is needed
monitor.id is the ID of the monitor saved object. monitor.attributes.id is the id that is used when the monitor is ingested into the synthetics documents.
These values are often identical, but unfortunately diverge for project monitors. That is because instead of using the monitor saved object id as the ingested data's id, it uses a human readable id that is a combination of the monitor name, project id, and space id.
This code path actually wants the id used in the synthetics data, not the saved object id. We sometimes call it query id. There's a config key called ConfigKey.MONITOR_QUERY_ID that we sometimes use for it. The value of that enum is just id. So monitor.attributes[ConfigKey.MONITOR_QUERY_IDresolves just tomonitor.attributes.id`.
There was a problem hiding this comment.
Thank you for this explanation, @dominiqueclarke, very helpful. Not necessarily an issue for right now but it concerns me that this requires this much explanation to understand ... it would be good to write down some ideas in an issue for the future, about how to simplify this for the sake of reducing these kinds of bug surfaces that I imagine come from people not really understanding the difference between these? (As always, I may misunderstand the root problem here.)
There was a problem hiding this comment.
I agree @jasonrhodes it's not an architectural decision I'm proud of, and it's hard to back out of.
There was a problem hiding this comment.
@jasonrhodes scheduled a meeting to discuss and find ways to back out of this nonsense.
…itor-query-id-for-project-monitors
|
Pinging @elastic/obs-ux-management-team (Team:obs-ux-management) |
💔 Build Failed
Failed CI StepsTest Failures
Metrics [docs]
History
|
|
Tested this with a full migration from 8.19.0 to 8.19.8 (with the change applied). I couldn't test on main/the PR because of saved object migrations on the unreleased development branch. Before you can see that 12500 policies (all from my test project monitors) are being recreated because they were all deleted. After |
|
Starting backport for target branches: 8.19, 9.2, 9.3 |
…es !! (elastic#248762) ## Summary In the Clean up package policies logic, Use monitor query id for project monitors package policies, since for project monitors package policy Id creation, id is used instead of config id of saved object. (cherry picked from commit 02eb244)
…es !! (elastic#248762) ## Summary In the Clean up package policies logic, Use monitor query id for project monitors package policies, since for project monitors package policy Id creation, id is used instead of config id of saved object. (cherry picked from commit 02eb244)
…es !! (elastic#248762) ## Summary In the Clean up package policies logic, Use monitor query id for project monitors package policies, since for project monitors package policy Id creation, id is used instead of config id of saved object. (cherry picked from commit 02eb244)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…policies !! (#248762) (#249159) # Backport This will backport the following commits from `main` to `9.2`: - [[Synthetics] Use monitor query id for project monitors package policies !! (#248762)](#248762) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-01-15T09:46:36Z","message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:version","v9.3.0","v9.4.0","author:actionable-obs","Team:obs-ux-management","v9.2.5","v8.19.11"],"title":"[Synthetics] Use monitor query id for project monitors package policies !!","number":248762,"url":"https://github.com/elastic/kibana/pull/248762","mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},"sourceBranch":"main","suggestedTargetBranches":["9.3","9.2","8.19"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/248762","number":248762,"mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},{"branch":"9.2","label":"v9.2.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.11","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
… policies !! (#248762) (#249158) # Backport This will backport the following commits from `main` to `8.19`: - [[Synthetics] Use monitor query id for project monitors package policies !! (#248762)](#248762) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-01-15T09:46:36Z","message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:version","v9.3.0","v9.4.0","author:actionable-obs","Team:obs-ux-management","v9.2.5","v8.19.11"],"title":"[Synthetics] Use monitor query id for project monitors package policies !!","number":248762,"url":"https://github.com/elastic/kibana/pull/248762","mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},"sourceBranch":"main","suggestedTargetBranches":["9.3","9.2","8.19"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/248762","number":248762,"mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},{"branch":"9.2","label":"v9.2.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.11","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
…policies !! (#248762) (#249160) # Backport This will backport the following commits from `main` to `9.3`: - [[Synthetics] Use monitor query id for project monitors package policies !! (#248762)](#248762) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2026-01-15T09:46:36Z","message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","backport:version","v9.3.0","v9.4.0","author:actionable-obs","Team:obs-ux-management","v9.2.5","v8.19.11"],"title":"[Synthetics] Use monitor query id for project monitors package policies !!","number":248762,"url":"https://github.com/elastic/kibana/pull/248762","mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},"sourceBranch":"main","suggestedTargetBranches":["9.3","9.2","8.19"],"targetPullRequestStates":[{"branch":"9.3","label":"v9.3.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/248762","number":248762,"mergeCommit":{"message":"[Synthetics] Use monitor query id for project monitors package policies !! (#248762)\n\n## Summary\n\nIn the Clean up package policies logic, Use monitor query id for project\nmonitors package policies, since for project monitors package policy Id\ncreation, id is used instead of config id of saved object.","sha":"02eb24406d130f5d877ed0beea987ebf05e4c40b"}},{"branch":"9.2","label":"v9.2.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.11","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com> Co-authored-by: Dominique Clarke <dominique.clarke@elastic.co>

Summary
In the Clean up package policies logic, Use monitor query id for project monitors package policies, since for project monitors package policy Id creation, id is used instead of config id of saved object.
This is causing synthetics clean up task to perform extra work and might cause it to timeout at 10m and cause unnecessary package policy clean up