Skip to content

[Fix] Synthetics monitor health false positives and infinite _health polling#270137

Merged
miguelmartin-elastic merged 2 commits into
elastic:mainfrom
miguelmartin-elastic:fix/synthetics-health-api-project-monitor-policy-id
May 20, 2026
Merged

[Fix] Synthetics monitor health false positives and infinite _health polling#270137
miguelmartin-elastic merged 2 commits into
elastic:mainfrom
miguelmartin-elastic:fix/synthetics-health-api-project-monitor-policy-id

Conversation

@miguelmartin-elastic
Copy link
Copy Markdown
Contributor

@miguelmartin-elastic miguelmartin-elastic commented May 20, 2026

Release notes

Synthetics — Monitor integration health

• Fixed false “missing integration” on project monitors (private locations): Health checks now use the correct monitor identifier, so project monitors show as
healthy when the integration is installed.
• Fixed repeated health checks on monitor overview: The integration-health hook no longer re-fetches on every render when the missing-integration banner is shown.

Summary

Fixes #270125

  • Server: Use MONITOR_QUERY_ID (not the saved object UUID) when resolving Fleet package policy IDs in the monitor integration health API. Fixes false missing_package_policy for project-origin monitors on private locations.
  • Client: Stabilize monitor ID dependencies in useMonitorIntegrationHealth so inline configIds arrays (e.g. on monitor overview) do not retrigger _health fetches on every render. Fixes infinite polling to /internal/synthetics/monitors/_health when the missing-integration banner is shown.

Test plan

  • Run unit tests:
    node scripts/jest x-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts
    node scripts/jest x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts
  • Health API fix: use a project monitor on a private location and call POST /internal/synthetics/monitors/_health — expect healthy when the Fleet package policy exists.
  • Health API regression: use a UI-origin monitor on a private location — expect healthy (UI monitors use MONITOR_QUERY_ID === config_id).
  • Infinite polling fix: open a project monitor overview that shows the missing-integration banner — confirm a single _health request (or one per refresh interval), not a continuous stream in the network tab.

@miguelmartin-elastic miguelmartin-elastic added release_note:fix Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. backport:version Backport to applied version labels v9.3.0 v9.4.0 labels May 20, 2026
@github-actions github-actions Bot added the author:actionable-obs PRs authored by the actionable obs team label May 20, 2026
@miguelmartin-elastic miguelmartin-elastic marked this pull request as ready for review May 20, 2026 10:53
@miguelmartin-elastic miguelmartin-elastic requested a review from a team as a code owner May 20, 2026 10:53
@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

Pinging @elastic/actionable-obs-team (Team:actionable-obs)

Copy link
Copy Markdown
Contributor

@shahzad31 shahzad31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM !!

@miguelmartin-elastic miguelmartin-elastic changed the title [Fix] Use MONITOR_QUERY_ID for monitor integration health checks [Fix] Synthetics monitor health false positives and infinite _health polling May 20, 2026
@kibanamachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
synthetics 1.1MB 1.1MB +225.0B

History

@miguelmartin-elastic miguelmartin-elastic merged commit b92ccae into elastic:main May 20, 2026
32 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 9.4

https://github.com/elastic/kibana/actions/runs/26173225448

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
9.4

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request May 20, 2026
…ealth polling (#270137) (#270243)

# Backport

This will backport the following commits from `main` to `9.4`:
- [[Fix] Synthetics monitor health false positives and infinite _health
polling (#270137)](#270137)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Miguel
Martín","email":"miguel.martin@elastic.co"},"sourceCommit":{"committedDate":"2026-05-20T15:39:44Z","message":"[Fix]
Synthetics monitor health false positives and infinite _health polling
(#270137)\n\n## Summary\n\nFixes #270125\n\n- **Server:** Use
`MONITOR_QUERY_ID` (not the saved object UUID) when\nresolving Fleet
package policy IDs in the monitor integration health\nAPI. Fixes false
`missing_package_policy` for project-origin monitors on\nprivate
locations.\n- **Client:** Stabilize monitor ID dependencies
in\n`useMonitorIntegrationHealth` so inline `configIds` arrays (e.g.
on\nmonitor overview) do not retrigger `_health` fetches on every
render.\nFixes infinite polling to
`/internal/synthetics/monitors/_health` when\nthe missing-integration
banner is shown.\n\n## Test plan\n\n- [ ] Run unit tests:\n
```bash\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts\n
```\n- [ ] **Health API fix:** use a project monitor on a private
location\nand call `POST /internal/synthetics/monitors/_health` — expect
`healthy`\nwhen the Fleet package policy exists.\n- [ ] **Health API
regression:** use a UI-origin monitor on a private\nlocation — expect
`healthy` (UI monitors use `MONITOR_QUERY_ID ===\nconfig_id`).\n- [ ]
**Infinite polling fix:** open a project monitor overview that\nshows
the missing-integration banner — confirm a single `_health`\nrequest (or
one per refresh interval), not a continuous stream in the\nnetwork
tab.","sha":"b92ccaecd5c1518ec7b7fe855f9857225bdb31b8","branchLabelMapping":{"^v9.5.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:actionable-obs","backport:version","v9.4.0","author:actionable-obs","v9.5.0"],"title":"[Fix]
Synthetics monitor health false positives and infinite _health
polling","number":270137,"url":"https://github.com/elastic/kibana/pull/270137","mergeCommit":{"message":"[Fix]
Synthetics monitor health false positives and infinite _health polling
(#270137)\n\n## Summary\n\nFixes #270125\n\n- **Server:** Use
`MONITOR_QUERY_ID` (not the saved object UUID) when\nresolving Fleet
package policy IDs in the monitor integration health\nAPI. Fixes false
`missing_package_policy` for project-origin monitors on\nprivate
locations.\n- **Client:** Stabilize monitor ID dependencies
in\n`useMonitorIntegrationHealth` so inline `configIds` arrays (e.g.
on\nmonitor overview) do not retrigger `_health` fetches on every
render.\nFixes infinite polling to
`/internal/synthetics/monitors/_health` when\nthe missing-integration
banner is shown.\n\n## Test plan\n\n- [ ] Run unit tests:\n
```bash\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts\n
```\n- [ ] **Health API fix:** use a project monitor on a private
location\nand call `POST /internal/synthetics/monitors/_health` — expect
`healthy`\nwhen the Fleet package policy exists.\n- [ ] **Health API
regression:** use a UI-origin monitor on a private\nlocation — expect
`healthy` (UI monitors use `MONITOR_QUERY_ID ===\nconfig_id`).\n- [ ]
**Infinite polling fix:** open a project monitor overview that\nshows
the missing-integration banner — confirm a single `_health`\nrequest (or
one per refresh interval), not a continuous stream in the\nnetwork
tab.","sha":"b92ccaecd5c1518ec7b7fe855f9857225bdb31b8"}},"sourceBranch":"main","suggestedTargetBranches":["9.4"],"targetPullRequestStates":[{"branch":"9.4","label":"v9.4.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.5.0","branchLabelMappingKey":"^v9.5.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/270137","number":270137,"mergeCommit":{"message":"[Fix]
Synthetics monitor health false positives and infinite _health polling
(#270137)\n\n## Summary\n\nFixes #270125\n\n- **Server:** Use
`MONITOR_QUERY_ID` (not the saved object UUID) when\nresolving Fleet
package policy IDs in the monitor integration health\nAPI. Fixes false
`missing_package_policy` for project-origin monitors on\nprivate
locations.\n- **Client:** Stabilize monitor ID dependencies
in\n`useMonitorIntegrationHealth` so inline `configIds` arrays (e.g.
on\nmonitor overview) do not retrigger `_health` fetches on every
render.\nFixes infinite polling to
`/internal/synthetics/monitors/_health` when\nthe missing-integration
banner is shown.\n\n## Test plan\n\n- [ ] Run unit tests:\n
```bash\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts\nnode
scripts/jest\nx-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts\n
```\n- [ ] **Health API fix:** use a project monitor on a private
location\nand call `POST /internal/synthetics/monitors/_health` — expect
`healthy`\nwhen the Fleet package policy exists.\n- [ ] **Health API
regression:** use a UI-origin monitor on a private\nlocation — expect
`healthy` (UI monitors use `MONITOR_QUERY_ID ===\nconfig_id`).\n- [ ]
**Infinite polling fix:** open a project monitor overview that\nshows
the missing-integration banner — confirm a single `_health`\nrequest (or
one per refresh interval), not a continuous stream in the\nnetwork
tab.","sha":"b92ccaecd5c1518ec7b7fe855f9857225bdb31b8"}}]}] BACKPORT-->

Co-authored-by: Miguel Martín <miguel.martin@elastic.co>
paulinashakirova pushed a commit to paulinashakirova/kibana that referenced this pull request May 22, 2026
…polling (elastic#270137)

## Summary

Fixes elastic#270125

- **Server:** Use `MONITOR_QUERY_ID` (not the saved object UUID) when
resolving Fleet package policy IDs in the monitor integration health
API. Fixes false `missing_package_policy` for project-origin monitors on
private locations.
- **Client:** Stabilize monitor ID dependencies in
`useMonitorIntegrationHealth` so inline `configIds` arrays (e.g. on
monitor overview) do not retrigger `_health` fetches on every render.
Fixes infinite polling to `/internal/synthetics/monitors/_health` when
the missing-integration banner is shown.

## Test plan

- [ ] Run unit tests:
  ```bash
node scripts/jest
x-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts
node scripts/jest
x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts
  ```
- [ ] **Health API fix:** use a project monitor on a private location
and call `POST /internal/synthetics/monitors/_health` — expect `healthy`
when the Fleet package policy exists.
- [ ] **Health API regression:** use a UI-origin monitor on a private
location — expect `healthy` (UI monitors use `MONITOR_QUERY_ID ===
config_id`).
- [ ] **Infinite polling fix:** open a project monitor overview that
shows the missing-integration banner — confirm a single `_health`
request (or one per refresh interval), not a continuous stream in the
network tab.
shahzad31 added a commit that referenced this pull request May 22, 2026
#270540)

## 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/_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.

## What changed

- **`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.

## Test plan

- [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.

## Related

- #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>
jcger pushed a commit that referenced this pull request May 26, 2026
…polling (#270137)

## Summary

Fixes #270125

- **Server:** Use `MONITOR_QUERY_ID` (not the saved object UUID) when
resolving Fleet package policy IDs in the monitor integration health
API. Fixes false `missing_package_policy` for project-origin monitors on
private locations.
- **Client:** Stabilize monitor ID dependencies in
`useMonitorIntegrationHealth` so inline `configIds` arrays (e.g. on
monitor overview) do not retrigger `_health` fetches on every render.
Fixes infinite polling to `/internal/synthetics/monitors/_health` when
the missing-integration banner is shown.

## Test plan

- [ ] Run unit tests:
  ```bash
node scripts/jest
x-pack/solutions/observability/plugins/synthetics/server/services/monitor_integration_health_api.test.ts
node scripts/jest
x-pack/solutions/observability/plugins/synthetics/public/apps/synthetics/components/common/hooks/use_monitor_integration_health.test.ts
  ```
- [ ] **Health API fix:** use a project monitor on a private location
and call `POST /internal/synthetics/monitors/_health` — expect `healthy`
when the Fleet package policy exists.
- [ ] **Health API regression:** use a UI-origin monitor on a private
location — expect `healthy` (UI monitors use `MONITOR_QUERY_ID ===
config_id`).
- [ ] **Infinite polling fix:** open a project monitor overview that
shows the missing-integration banner — confirm a single `_health`
request (or one per refresh interval), not a continuous stream in the
network tab.
jcger pushed a commit that referenced this pull request May 26, 2026
#270540)

## 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/_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.

## What changed

- **`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.

## Test plan

- [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.

## Related

- #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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:actionable-obs PRs authored by the actionable obs team backport:version Backport to applied version labels release_note:fix Team:actionable-obs Formerly "obs-ux-management", responsible for SLO, o11y alerting, significant events, & synthetics. v9.4.0 v9.4.2 v9.5.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Synthetics] Monitor integration health reports false missing_package_policy for project-origin private location monitors

3 participants