[Synthetics] Fix monitor health API for monitors in non-default spaces#270540
Merged
shahzad31 merged 5 commits intoMay 22, 2026
Conversation
`POST /internal/synthetics/monitors/_health` returned wrong results when monitors lived outside the request's space: - Package policy lookup used `createInternalRepository()` scoped to the default namespace, so policies created for monitors in another space were invisible — surfaced as `missing_package_policy` even when the Fleet policy existed. - Monitor saved-object lookup used the request-scoped SO client, so calling `_health` from `default` for monitors that live in another space returned 404s. Fixes: - Route the package-policy lookup through `PackagePolicyService.getByIds` with `additionalSpaceIds = allSpacesWithMonitors`, so namespace-scoped SO clients are built per space and results deduplicated. - Add `MonitorConfigRepository.getAcrossSpaces`, which uses an internal SO repository with per-object `namespaces` (multi-space type) and a one-entry-per-space lookup for the legacy single-namespace type. Closes elastic#270477 Co-authored-by: Cursor <cursoragent@cursor.com>
| // per space and de-duplicates the results, so package policies created | ||
| // for monitors in any space are visible regardless of the caller's space. | ||
| const packagePolicyService = new PackagePolicyService(this.server); | ||
| const additionalSpaceIds = [...allSpaces].filter((space) => space !== this.spaceId); |
Contributor
There was a problem hiding this comment.
Is this really needed? spaceId is added to the set in x-pack/solutions/observability/plugins/synthetics/server/synthetics_service/private_location/package_policy_service.ts:72 anyway
Contributor
… spaces can be found
…rivate locations scoped to non deault namespaces can be found
…thetics-health-cross-space
miguelmartin-elastic
approved these changes
May 22, 2026
Contributor
💚 Build Succeeded
Metrics [docs]
History
|
Contributor
|
Starting backport for target branches: 9.4 https://github.com/elastic/kibana/actions/runs/26288622513 |
Contributor
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
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.


Release note
When using Kibana Spaces, the Synthetics monitor health endpoint could incorrectly report monitors as unhealthy — showing errors such as "missing location", "missing agent policy", or "missing package policy" — even when everything was properly configured. This happened because the health check was only looking for monitors, private locations, and Fleet policies in the current space, missing resources that existed in other spaces.
These issues are now fixed: the health check correctly resolves monitors, private locations, package policies, and agent policies across all relevant spaces, giving an accurate health status regardless of how resources are distributed across your Kibana Spaces.
Summary
Closes #270477.
POST /internal/synthetics/monitors/_healthreturned wrong results when monitors lived outside the request's space —missing_package_policyerrors when called from the monitor's space, and 404s when called fromdefault.Two independent space-scoping bugs:
getExistingPackagePoliciesMapcalled Fleet'spackagePolicyService.getByIDswithcreateInternalRepository(), which is scoped to the default namespace. Package policies created for monitors in another space were therefore invisible.MonitorConfigRepository.getused the request-scoped saved-objects client, restricted to the request's space. Calling_healthfromdefaultfor a monitor that lives elsewhere returned a 404.What changed
PackagePolicyService.getByIds— accepts a new optionaladditionalSpaceIds, so the wrapper's per-space scoped-client fan-out can broaden beyond[spaceId, default]. Existing callers keep their old behavior.MonitorConfigRepository.getAcrossSpaces(id, namespaces, soClient?)— new method that resolves a monitor across an arbitrary list of spaces. Uses the multi-space type's per-objectnamespacesarray in one bulkGet entry, plus one entry per namespace for thenamespaceType: 'single'legacy type. Accepts an injectedsoClientso the health API can passcreateInternalRepository()and bypass the request's space restriction.MonitorIntegrationHealthApi:allSpaces = { requestSpace, ...allSpacesWithMonitors }once, up-front.fetchMonitorscallsmonitorConfigRepository.getAcrossSpaceswith the internal repository → fixes bug Change of links to styles and js #2.getExistingPackagePoliciesMapuses thePackagePolicyServicewrapper withadditionalSpaceIds→ fixes bug links to styles and js #1.Test plan
node scripts/jeston the three affected suites — 77/77 passing (includes new cross-space coverage and a newgetAcrossSpacestest block).node scripts/type_check --project x-pack/solutions/observability/plugins/synthetics/tsconfig.json— clean.node scripts/eslinton the changed files — clean.POST /internal/synthetics/monitors/_healthboth from that space and fromdefault. Verify each call reports the monitor accurately instead ofmissing_package_policy/ 404.Related
Made with Cursor