Skip to content

[9.4] [Synthetics] Fix monitor health API for monitors in non-default spaces (#270540)#270605

Open
shahzad31 wants to merge 3 commits into
elastic:9.4from
shahzad31:backport/9.4/pr-270540
Open

[9.4] [Synthetics] Fix monitor health API for monitors in non-default spaces (#270540)#270605
shahzad31 wants to merge 3 commits into
elastic:9.4from
shahzad31:backport/9.4/pr-270540

Conversation

@shahzad31
Copy link
Copy Markdown
Contributor

Backport

This is an automatic backport to 9.4 of:

Conflict resolution

The auto-backport failed because of two-file conflicts in monitor_integration_health_api.{ts,test.ts} caused by the agent-status feature (#261367) that lives only on main. Resolved by:

  • Keeping all PR [Synthetics] Fix monitor health API for monitors in non-default spaces #270540 changes (getAcrossSpaces, additionalSpaceIds, PackagePolicyService wrapper, cross-space getExistingAgentPoliciesMap/getExistingPackagePoliciesMap).
  • Dropping the agentStatusMap / getAgentStatusMap / MissingAgents / UnhealthyAgent code paths and corresponding tests, since PrivateLocationHealthStatusValue.MissingAgents and getAgentStatusForAgentPolicy plumbing do not exist on 9.4.

Notes for reviewer

Made with Cursor

elastic#270540)

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.

Closes elastic#270477.

`POST /internal/synthetics/monitors/_health` returned wrong results when
monitors lived outside the request's space — `missing_package_policy`
errors when called from the monitor's space, and 404s when called from
`default`.

Two independent space-scoping bugs:

1. **Package policy lookup ignored space.**
`getExistingPackagePoliciesMap` called Fleet's
`packagePolicyService.getByIDs` with `createInternalRepository()`, which
is scoped to the default namespace. Package policies created for
monitors in another space were therefore invisible.
2. **Monitor saved-object lookup was space-scoped.**
`MonitorConfigRepository.get` used the request-scoped saved-objects
client, restricted to the request's space. Calling `_health` from
`default` for a monitor that lives elsewhere returned a 404.

- **`PackagePolicyService.getByIds`** — accepts a new optional
`additionalSpaceIds`, 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-object `namespaces`
array in one bulkGet entry, plus one entry per namespace for the
`namespaceType: 'single'` legacy type. Accepts an injected `soClient` so
the health API can pass `createInternalRepository()` and bypass the
request's space restriction.
- **`MonitorIntegrationHealthApi`**:
- Computes `allSpaces = { requestSpace, ...allSpacesWithMonitors }`
once, up-front.
- `fetchMonitors` calls `monitorConfigRepository.getAcrossSpaces` with
the internal repository → fixes bug #2.
- `getExistingPackagePoliciesMap` uses the `PackagePolicyService`
wrapper with `additionalSpaceIds` → fixes bug #1.

- [x] `node scripts/jest` on the three affected suites — **77/77
passing** (includes new cross-space coverage and a new `getAcrossSpaces`
test block).
- [x] `node scripts/type_check --project
x-pack/solutions/observability/plugins/synthetics/tsconfig.json` —
clean.
- [x] `node scripts/eslint` on the changed files — clean.
- [ ] Manual: create a monitor with a private location in a non-default
space, then call `POST /internal/synthetics/monitors/_health` both from
that space and from `default`. Verify each call reports the monitor
accurately instead of `missing_package_policy` / 404.

- elastic#270137 — related health API fix (project monitor policy
ID + infinite polling).

Made with [Cursor](https://cursor.com)

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Miguel Martín <miguel.martin@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 4e2f2e6)
@github-actions github-actions Bot added the author:actionable-obs PRs authored by the actionable obs team label May 22, 2026
@shahzad31 shahzad31 marked this pull request as ready for review May 25, 2026 10:46
@shahzad31 shahzad31 requested a review from kibanamachine as a code owner May 25, 2026 10:46
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

PR elastic#270540's monitor_integration_health_api.{ts,test.ts} import
getPrivateLocationsForNamespaces, which was added on main by PR elastic#260642
but does not exist on 9.4 yet — causing 5 type errors in CI.

Port the symbol verbatim from main: add the multi-namespace export and
rewrite getPrivateLocations as a one-line wrapper. The public signature
of getPrivateLocations is preserved, so all existing 9.4 callers are
unaffected.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kibanamachine
Copy link
Copy Markdown
Contributor

kibanamachine commented May 25, 2026

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #61 / integrations When in the Fleet application and on the Endpoint Integration details page should show the Trusted Apps page when link is clicked
  • [job] [logs] FTR Configs #61 / integrations When in the Fleet application and on the Endpoint Integration details page should show the Trusted Apps page when link is clicked

Metrics [docs]

✅ unchanged

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants