[Synthetics] Create Internal Bulk PATCH API Endpoint for Monitors #268141
Draft
mgiota wants to merge 8 commits into
Draft
[Synthetics] Create Internal Bulk PATCH API Endpoint for Monitors #268141mgiota wants to merge 8 commits into
mgiota wants to merge 8 commits into
Conversation
Internal endpoint at PATCH /internal/synthetics/monitors/_bulk_update. Lands the route surface only — schema validation, route registration, and a 501 placeholder. Behaviour (decrypt -> merge -> re-encrypt -> bulk write via syncEditedMonitorBulk) is wired in subsequent commits. The Synthetics route type system was limited to GET/POST/PUT/DELETE; extended to include PATCH so the new route can register correctly.
|
🤖 Jobs for this PR can be triggered through checkboxes. 🚧
ℹ️ To trigger the CI, please tick the checkbox below 👇
|
mgiota
commented
May 7, 2026
| @@ -0,0 +1,50 @@ | |||
| /* | |||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | |||
Contributor
Author
There was a problem hiding this comment.
I was planning to use edit_monitor_bulk.ts, but there is already such a file. Current edit_monitor_bulk.ts is just a helper file and no actual route implementation. I left it as is and used update_monitor_bulk instead.
AAD-safe per-id pipeline for the bulk PATCH endpoint, mirroring the DeleteMonitorAPI / ResetMonitorAPI pattern: decrypt (one SO round-trip via CONFIG_ID filter) → not_found diff → reject non-'ui' origins → mergeSourceMonitor (keeps prev AAD attrs the patch didn't touch) → validateMonitor (io-ts) → permissions + multi-space + private-location-spaces → bump revision, reset CONFIG_HASH, formatSecrets Output is the MonitorConfigUpdate shape syncEditedMonitorBulk expects. Route handler still returns 501; wiring comes next. Tests cover each per-id error path, mixed batches, the conditional private-locations fetch, and an AAD-preservation regression check.
The handler returns 200 with `{ result, errors? }` where each entry of
`result` reports `{ id, updated, error? }` per requested id, in input
order. Entries are produced by:
UpdateMonitorAPI.execute → { survivors, perIdErrors }
→ fetch private locations for the union of request space and every
survivor's KIBANA_SPACES
→ syncEditedMonitorBulk
→ merge perIdErrors, failedConfigs (Fleet-rolled-back), per-SO
bulkUpdate errors, and successful editedMonitors into one result
array; publicSyncErrors become top-level `errors`
Edge cases:
- empty `attributes` → 400
- no survivors after preprocess → 200 with all-errors result, sync
skipped
- syncEditedMonitorBulk throws → 500 (orchestrator already rolled
back)
- happy path: public location, private location, multi-id batch
- AAD regression: patch `enabled`, re-fetch via GET (decrypt path),
assert secrets and other AAD fields round-trip unchanged. If
mergeSourceMonitor ever drops prev AAD attrs, GET turns into 500.
- per-id errors: mixed valid/missing ids, project-origin rejection,
invalid-schedule validation failure
- input validation: empty attributes → 400, empty ids → 400
…ics-bulk-patch-api
Switch the bulk update endpoint from an internal PATCH route to a public PUT /api/synthetics/monitors/_bulk_update, matching the single-monitor partial-update convention (PUT) and the existing public _bulk_delete route. Drops PATCH from the supported route methods and updates unit + API tests. Co-authored-by: Cursor <cursoragent@cursor.com>
The bulk update preprocessing loop resolved the Elastic-managed-locations capability and the saved-objects bulk_update privilege once per monitor. Both answers are request-scoped, so cache the capability for the whole request and the privilege per unique space set, turning O(N) permission round-trips into O(1) / O(distinct space sets). Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #239579
In progress, description will be updated after every commit to include the new changes
Summary
PATCH /internal/synthetics/monitors/_bulk_updateUpdateMonitorAPIpreprocessing service: AAD-safe decrypt → merge → re-encrypt pipeline producingsyncEditedMonitorBulk-compatible survivors with per-id errors (not_found,invalid_origin,validation_failed,forbidden)UpdateMonitorAPIintosyncEditedMonitorBulkand returns 200 with{ result: [{id, updated, error?}], errors? }in request id order; classifies failedConfigs (Fleet rollback) and per-SO bulkUpdate errors per id; 400 on emptyattributes, 500 on sync exception