Skip to content

feat: support multi space monitors !! #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 28, 2025
Merged

feat: support multi space monitors !! #1052

merged 9 commits into from
Jul 28, 2025

Conversation

shahzad31
Copy link
Contributor

@shahzad31 shahzad31 commented Jul 18, 2025

To test the PR

You can create a dummy project and point it to the source of the directory like this

"@elastic/synthetics": "file:../../",

then you can specify spaces as an option in config or individula monitors using monitor.use

    monitor: {
      schedule: 10,
      locations: ['us_central'],
      spaces: ['test', 'default'],
    },

spaces in lightweight are also supported

heartbeat.monitors:
  - type: http
    name: Todos Lightweight Test 0
    id: todos-lightweight-test-0
    enabled: true
    urls: 'https://elastic.github.io/synthetics-demo'
    schedule: '@every 60m'
    timeout: 18s
    alert.status.enabled: true
    service.name: todos-lightweight-test
    namespace: food
    spaces:
      - '*'

Notes

  1. Kibana API will throw an error if user is trying to create a monitor in non existent space
  2. Kibana API will throw an error if user doesn't have permission to create monitors in a space
  3. KIbana API will throw error if user is trying to use spaces option before prev 8.19, or 9.1.0 version
  4. Project space Id is always appended, that means monitor is always created in a project space, besides user can also choose other spaces
  5. monitor.use option will take precedent over project.monitor option

shahzad31 added a commit to elastic/kibana that referenced this pull request Jul 21, 2025
## Summary

Follow up to #221568

This  PR allows specifying spaces param in project monitors. 

Following use-cases have been supported

User will be able to supports 

`spaces: ["defautl", "test"]
`

Proper API tests have been added to provide additional coverage for the
use-case.

### Validations

- [ ] The route to which project api is being called should always be
part of spaces if defined.
- [ ] Non existent space will throw error 
- [ ] User must have permission to all specified spaces for CRUDS
- [ ] User can also specify * to create monitors in all spaces


### PR Testing
You can use following project monitors PR to test this PR
elastic/synthetics#1052


First create few project monitors before this branch and then switch and
specify multi spaces as part of the options and verify in UI that
editing , adding and deletion works as expected on push command.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jul 21, 2025
## Summary

Follow up to elastic#221568

This  PR allows specifying spaces param in project monitors.

Following use-cases have been supported

User will be able to supports

`spaces: ["defautl", "test"]
`

Proper API tests have been added to provide additional coverage for the
use-case.

### Validations

- [ ] The route to which project api is being called should always be
part of spaces if defined.
- [ ] Non existent space will throw error
- [ ] User must have permission to all specified spaces for CRUDS
- [ ] User can also specify * to create monitors in all spaces

### PR Testing
You can use following project monitors PR to test this PR
elastic/synthetics#1052

First create few project monitors before this branch and then switch and
specify multi spaces as part of the options and verify in UI that
editing , adding and deletion works as expected on push command.

(cherry picked from commit 39d87d0)
kibanamachine added a commit to elastic/kibana that referenced this pull request Jul 21, 2025
# Backport

This will backport the following commits from `main` to `9.1`:
- [[Synthetics] Support projects multi spaces !!
(#227674)](#227674)

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

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

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-07-21T07:52:26Z","message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:feature","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0","author:obs-ux-management","v9.2.0"],"title":"[Synthetics]
Support projects multi spaces
!!","number":227674,"url":"https://github.com/elastic/kibana/pull/227674","mergeCommit":{"message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227674","number":227674,"mergeCommit":{"message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <[email protected]>
@shahzad31 shahzad31 marked this pull request as ready for review July 21, 2025 12:15
Copy link
Member

@vigneshshanmugam vigneshshanmugam left a comment

Choose a reason for hiding this comment

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

I am bit confused as we use space specific URL format when pushing the monitors to Kibana -

return `${url}/s/${options.space}/api/synthetics/project/${options.id}/monitors`;

But now, with this change how its a bit awkward, What happens to the URL format- would it be pushed to /default/ kibana endpoint?

@@ -466,6 +467,9 @@ export default class Runner implements RunnerInfo {
(journey.cb ?? journey.callback)({ params: options.params } as any);
const monitor = journey.monitor ?? journey?._getMonitor();
monitor.update(this.#monitor?.config);
monitor.setSpaces(
Copy link
Member

Choose a reason for hiding this comment

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

This should not be required as the .update call should handle the changes from the config. Please check once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will refactor

shahzad31 added a commit to elastic/kibana that referenced this pull request Jul 22, 2025
# Backport

This will backport the following commits from `main` to `8.19`:
- [[Synthetics] Support projects multi spaces !!
(#227674)](#227674)

<!--- Backport version: 10.0.1 -->

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

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-07-21T07:52:26Z","message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:feature","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0","author:obs-ux-management","v9.2.0"],"title":"[Synthetics]
Support projects multi spaces
!!","number":227674,"url":"https://github.com/elastic/kibana/pull/227674","mergeCommit":{"message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/228725","number":228725,"state":"OPEN"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/227674","number":227674,"mergeCommit":{"message":"[Synthetics]
Support projects multi spaces !! (#227674)\n\n## Summary\n\nFollow up to
https://github.com/elastic/kibana/pull/221568\n\nThis PR allows
specifying spaces param in project monitors. \n\nFollowing use-cases
have been supported\n\nUser will be able to supports \n\n`spaces:
[\"defautl\", \"test\"]\n`\n\nProper API tests have been added to
provide additional coverage for the\nuse-case.\n\n### Validations\n\n- [
] The route to which project api is being called should always be\npart
of spaces if defined.\n- [ ] Non existent space will throw error \n- [ ]
User must have permission to all specified spaces for CRUDS\n- [ ] User
can also specify * to create monitors in all spaces\n\n\n### PR
Testing\nYou can use following project monitors PR to test this
PR\nhttps://github.com/elastic/synthetics/pull/1052\n\n\nFirst create
few project monitors before this branch and then switch and\nspecify
multi spaces as part of the options and verify in UI that\nediting ,
adding and deletion works as expected on push
command.","sha":"39d87d0f908f0d1bbe7e1a29c588f3d8ea045da1"}}]}]
BACKPORT-->

---------

Co-authored-by: Copilot <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Bluefinger pushed a commit to Bluefinger/kibana that referenced this pull request Jul 22, 2025
## Summary

Follow up to elastic#221568

This  PR allows specifying spaces param in project monitors. 

Following use-cases have been supported

User will be able to supports 

`spaces: ["defautl", "test"]
`

Proper API tests have been added to provide additional coverage for the
use-case.

### Validations

- [ ] The route to which project api is being called should always be
part of spaces if defined.
- [ ] Non existent space will throw error 
- [ ] User must have permission to all specified spaces for CRUDS
- [ ] User can also specify * to create monitors in all spaces


### PR Testing
You can use following project monitors PR to test this PR
elastic/synthetics#1052


First create few project monitors before this branch and then switch and
specify multi spaces as part of the options and verify in UI that
editing , adding and deletion works as expected on push command.
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
## Summary

Follow up to elastic#221568

This  PR allows specifying spaces param in project monitors. 

Following use-cases have been supported

User will be able to supports 

`spaces: ["defautl", "test"]
`

Proper API tests have been added to provide additional coverage for the
use-case.

### Validations

- [ ] The route to which project api is being called should always be
part of spaces if defined.
- [ ] Non existent space will throw error 
- [ ] User must have permission to all specified spaces for CRUDS
- [ ] User can also specify * to create monitors in all spaces


### PR Testing
You can use following project monitors PR to test this PR
elastic/synthetics#1052


First create few project monitors before this branch and then switch and
specify multi spaces as part of the options and verify in UI that
editing , adding and deletion works as expected on push command.
crespocarlos pushed a commit to crespocarlos/kibana that referenced this pull request Jul 25, 2025
## Summary

Follow up to elastic#221568

This  PR allows specifying spaces param in project monitors. 

Following use-cases have been supported

User will be able to supports 

`spaces: ["defautl", "test"]
`

Proper API tests have been added to provide additional coverage for the
use-case.

### Validations

- [ ] The route to which project api is being called should always be
part of spaces if defined.
- [ ] Non existent space will throw error 
- [ ] User must have permission to all specified spaces for CRUDS
- [ ] User can also specify * to create monitors in all spaces


### PR Testing
You can use following project monitors PR to test this PR
elastic/synthetics#1052


First create few project monitors before this branch and then switch and
specify multi spaces as part of the options and verify in UI that
editing , adding and deletion works as expected on push command.
@shahzad31 shahzad31 merged commit 9f7f6fc into main Jul 28, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants