Skip to content

[ResponseOps][MaintenanceWindow] Public maintenance window API#216756

Merged
adcoelho merged 14 commits intomainfrom
mw-public-api
Apr 16, 2025
Merged

[ResponseOps][MaintenanceWindow] Public maintenance window API#216756
adcoelho merged 14 commits intomainfrom
mw-public-api

Conversation

@adcoelho
Copy link
Contributor

@adcoelho adcoelho commented Apr 2, 2025

Closes #198685

Summary

This PR creates a public Maintenance Window API.

The work was done on a feature branch over multiple separate PRs. Here we will merge the feature branch into main.

The documentation PR still needs to be merged.

Release Notes

Publish new public APIs for the Maintenance Window.

adcoelho and others added 5 commits March 13, 2025 17:11
Closes #208882
Closes #208879
Closes #208880

This PR introduces 3 new public APIs for the maintenance window. GET,
POST, and DELETE maintenance window.

**Please consider the following while reviewing the PR:**
- I wanted the first PR to be just `GET` but that wasn't enough to have
functional tests. This is why I also added POST and DELETE.
- **This branch is being merged into a feature branch**. It will allow
for small changes in the schema until all APIs are done.
- The PR has many changes but most relate to the existing internal API,
which was moved to `/internal`. Those files don't need to be reviewed.
- The `schedule` schema is being developed in a separate PR. Some
changes will come **after** this PR. The places that need to be changed
have been tagged with `// TODO schedule schema`.

- Route locations:
    - `alerting/server/routes/maintenance_window/apis/external/get/`
    - `alerting/server/routes/maintenance_window/apis/external/create/`
    - `alerting/server/routes/maintenance_window/apis/external/delete/`
- Transforms:
-
`alerting/server/routes/maintenance_window/apis/external/common/transforms/`
- there are also route-specific transforms inside
`alerting/server/routes/maintenance_window/apis/external/*`
- Schemas:
- `alerting/common/routes/maintenance_window/external/apis/get/schemas/`
-
`alerting/common/routes/maintenance_window/external/apis/create/schemas/`
-
`alerting/common/routes/maintenance_window/external/apis/delete/schemas/`
- `alerting/common/routes/maintenance_window/external/response/schemas/`
- Types:
- `alerting/common/routes/maintenance_window/external/apis/get/types/`
-
`alerting/common/routes/maintenance_window/external/apis/create/types/`
-
`alerting/common/routes/maintenance_window/external/apis/delete/types/`
- `alerting/common/routes/maintenance_window/external/response/types/`
- Functional tests:
-
`x-pack/test/alerting_api_integration/security_and_spaces/group3/tests/maintenance_window/external/`

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Closes #211181

## Summary

This PR introduces a public API for archiving maintenance windows.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…ance Window public APIs (#214747)

Merging into a feature branch.

## Summary

- Add the newly created custom schedule schema to
`createMaintenanceWindowRequestBodySchema` and
`maintenanceWindowResponseSchema`.
- Update `transformInternalMaintenanceWindowToExternal`.
- Update `transformCreateBody`.
- Update tests.

## Testing

The API URL is:
- `https://localhost:5601/api/alerting/maintenance_window`

Here is an example request for creating a maintenance window in Postman:

```
{
    "title": "test-maintenance-window",
    "schedule": {
        "custom": {
            "duration": "1d",
            "start": "1992-01-01T05:00:00.200Z",
            "recurring": {
                "every": "10d",
                "onWeekDay": ["MO", "FR"]
            }
        }
    },
    "scope": {
        "alerting": {
            "query": {
                "kql": "_id: '1234'"
            }
        }
    }
}
```
Closes #208881

## Merging into a feature branch

## Summary

Public PATCH maintenance window API.

- Partial updates.
- `category_id` is not updated.
- The validation in the maintenance window client that requires scoped
queries to be sent with a `category_id`, has been removed.

## Testing

A Maintenance window has first to be created. It can be done via the UI
or the new public API.

The API URL is:
- `https://localhost:5601/api/alerting/maintenance_window`

Here is an example request for **creating** a maintenance window in
Postman:

```
{
    "title": "test-maintenance-window",
    "schedule": {
        "custom": {
            "duration": "1d",
            "start": "1992-01-01T05:00:00.200Z",
            "recurring": {
                "every": "10d",
                "onWeekDay": ["MO", "FR"]
            }
        }
    },
    "scope": {
        "alerting": {
            "query": {
                "kql": "_id: '1234'"
            }
        }
    }
}
```

The maintenance window can now be updated by sending a patch request to
the same URL with the maintenance window ID appended to it.

- PATCH to
`https://localhost:5601/api/alerting/maintenance_window/<MW_ID>`

The request body is the same as for the POST request. The only
difference is every field is now optional.
@adcoelho adcoelho added backport:skip This PR does not require backporting Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// release_note:feature Makes this part of the condensed release notes v9.1.0 labels Apr 2, 2025
@adcoelho adcoelho self-assigned this Apr 2, 2025
@adcoelho adcoelho requested a review from a team as a code owner April 2, 2025 08:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Great work 🚀 ! LGTM! I left some minor comments. Also:

  • The public routes do not have any tag like we have for alerting. Should we add tags: ['oas-tag:maintenance_window']? @lcawl Wdyt? We want a dedicated category, outside of alerting, for the new public Maintenance Window APIs/

  • Some routes are missing the 400 in the response. Should we add it?

  • A disabled MW is shown as running in the UI. Unrelated to the PR. Could you please create an issue and link it to the MW GA meta issue?

  • If I set every more that 1d the onWeekDay (day selection) is not shown in the UI. Unrelated to the PR. Could you please create an issue and link it to the MW GA meta issue?

  • If I create a MW from the UI I can get: "duration": "2.0208333333333335d". Unrelated to the PR. Could you please create an issue to always return an integer (to the first unit that you can do it) and link it to the MW GA meta issue?

  • From the UI I can create a MW with duration > every but from the APIs I cannot. I remember deciding that but could you please remind me why?

@cnasikas cnasikas added backport:version Backport to applied version labels v8.19.0 and removed backport:skip This PR does not require backporting labels Apr 14, 2025
@adcoelho
Copy link
Contributor Author

Thanks for the review @cnasikas 👍

The public routes do not have any tag like we have for alerting. Should we add tags: ['oas-tag:maintenance_window']? @lcawl Wdyt? We want a dedicated category, outside of alerting, for the new public Maintenance Window APIs/

We can wait for lisa's comment but I added the tags anyway for now. It seems like a reasonable suggestion.

Some routes are missing the 400 in the response. Should we add it?

Added.

A disabled MW is shown as running in the UI. Unrelated to the PR. Could you please create an issue and link it to the MW GA meta issue?
If I set every more that 1d the onWeekDay (day selection) is not shown in the UI. Unrelated to the PR. Could you please create an issue and link it to the MW GA meta issue?
If I create a MW from the UI I can get: "duration": "2.0208333333333335d". Unrelated to the PR. Could you please create an issue to always return an integer (to the first unit that you can do it) and link it to the MW GA meta issue?

#218109
#218111
#218113

From the UI I can create a MW with duration > every but from the APIs I cannot. I remember deciding that but could you please remind me why?

Maybe @js-jankisalvi can chip in here? The API validation comes from the custom schedule.

@js-jankisalvi
Copy link
Contributor

From the UI I can create a MW with duration > every but from the APIs I cannot. I remember deciding that but could you please remind me why?

Maybe @js-jankisalvi can chip in here? The API validation comes from the custom schedule.

This is because creating MW from UI still uses internal api x-pack/platform/plugins/shared/alerting/public/services/maintenance_windows_api/create.ts which uses rRuleRequestSchemaV1 instead of scheduleRequestSchemaV1.

Copy link
Contributor

@lcawl lcawl left a comment

Choose a reason for hiding this comment

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

Thanks for adding the oas-tag, it is indeed necessary for that info to show up properly in the docs.

IMO in addition to the operation summary, an operation description will ultimately be necsesary for the "archive" and "unarchive" endpoints, since it's not obvious what that accomplishes.

@adcoelho
Copy link
Contributor Author

/ci

adcoelho and others added 2 commits April 15, 2025 13:48
### Merging into a feature branch

## Summary

I recently added a few public routes for managing maintenance windows. I
will need to generate documentation for these routes for my' on week'
task.

- Updated `capture_oas_snapshot` to include
`/api/alerting/maintenance_window`
- Added `tags` to the maintenance window routes

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
@adcoelho adcoelho requested a review from a team as a code owner April 15, 2025 11:50
@elasticmachine
Copy link
Contributor

elasticmachine commented Apr 15, 2025

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #70 / console app misc console behavior keyboard shortcuts open documentation should open documentation when Ctrl+/ is pressed
  • [job] [logs] FTR Configs #70 / console app misc console behavior keyboard shortcuts open documentation should open documentation when Ctrl+/ is pressed

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
alerting 845 852 +7

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
alerting 24.2KB 24.6KB +428.0B
Unknown metric groups

API count

id before after diff
alerting 879 886 +7

ESLint disabled line counts

id before after diff
@kbn/test-suites-xpack 729 735 +6

Total ESLint disabled count

id before after diff
@kbn/test-suites-xpack 755 761 +6

History

cc @adcoelho

@adcoelho adcoelho merged commit 08d0717 into main Apr 16, 2025
9 checks passed
@adcoelho adcoelho deleted the mw-public-api branch April 16, 2025 09:39
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 216756

Questions ?

Please refer to the Backport tool documentation

@adcoelho
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

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

Questions ?

Please refer to the Backport tool documentation

adcoelho added a commit to adcoelho/kibana that referenced this pull request Apr 17, 2025
…ic#216756)

Closes elastic#198685

## Summary

This PR creates a public Maintenance Window API.

The work was done on a feature branch over multiple separate PRs. Here
we will merge the feature branch into `main`.
- elastic#209734
- elastic#213694
- elastic#214747
- elastic#213771

The [documentation PR](elastic#212377)
still needs to be merged.

## Release Notes

Publish new public APIs for the Maintenance Window.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
(cherry picked from commit 08d0717)

# Conflicts:
#	.buildkite/scripts/steps/checks/capture_oas_snapshot.sh
#	oas_docs/overlays/kibana.overlays.shared.yaml
cnasikas pushed a commit that referenced this pull request Apr 18, 2025
…#216756) (#218532)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[ResponseOps][MaintenanceWindow] Public maintenance window API
(#216756)](#216756)

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

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

<!--BACKPORT
[{"author":{"name":"Antonio","email":"antonio.coelho@elastic.co"},"sourceCommit":{"committedDate":"2025-04-16T09:39:38Z","message":"[ResponseOps][MaintenanceWindow]
Public maintenance window API (#216756)\n\nCloses #198685\n\n##
Summary\n\nThis PR creates a public Maintenance Window API.\n\nThe work
was done on a feature branch over multiple separate PRs. Here\nwe will
merge the feature branch into `main`.\n-
https://github.com/elastic/kibana/pull/209734\n-
https://github.com/elastic/kibana/pull/213694\n-
https://github.com/elastic/kibana/pull/214747\n-
https://github.com/elastic/kibana/pull/213771\n\nThe [documentation
PR](https://github.com/elastic/kibana/pull/212377)\nstill needs to be
merged.\n\n## Release Notes\n\nPublish new public APIs for the
Maintenance Window.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: lcawl
<lcawley@elastic.co>","sha":"08d0717d46dbe2896d13de728c6fdf519a93e4d8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:ResponseOps","release_note:feature","backport:version","v9.1.0","v8.19.0"],"title":"[ResponseOps][MaintenanceWindow]
Public maintenance window
API","number":216756,"url":"https://github.com/elastic/kibana/pull/216756","mergeCommit":{"message":"[ResponseOps][MaintenanceWindow]
Public maintenance window API (#216756)\n\nCloses #198685\n\n##
Summary\n\nThis PR creates a public Maintenance Window API.\n\nThe work
was done on a feature branch over multiple separate PRs. Here\nwe will
merge the feature branch into `main`.\n-
https://github.com/elastic/kibana/pull/209734\n-
https://github.com/elastic/kibana/pull/213694\n-
https://github.com/elastic/kibana/pull/214747\n-
https://github.com/elastic/kibana/pull/213771\n\nThe [documentation
PR](https://github.com/elastic/kibana/pull/212377)\nstill needs to be
merged.\n\n## Release Notes\n\nPublish new public APIs for the
Maintenance Window.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: lcawl
<lcawley@elastic.co>","sha":"08d0717d46dbe2896d13de728c6fdf519a93e4d8"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216756","number":216756,"mergeCommit":{"message":"[ResponseOps][MaintenanceWindow]
Public maintenance window API (#216756)\n\nCloses #198685\n\n##
Summary\n\nThis PR creates a public Maintenance Window API.\n\nThe work
was done on a feature branch over multiple separate PRs. Here\nwe will
merge the feature branch into `main`.\n-
https://github.com/elastic/kibana/pull/209734\n-
https://github.com/elastic/kibana/pull/213694\n-
https://github.com/elastic/kibana/pull/214747\n-
https://github.com/elastic/kibana/pull/213771\n\nThe [documentation
PR](https://github.com/elastic/kibana/pull/212377)\nstill needs to be
merged.\n\n## Release Notes\n\nPublish new public APIs for the
Maintenance Window.\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by: lcawl
<lcawley@elastic.co>","sha":"08d0717d46dbe2896d13de728c6fdf519a93e4d8"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
akowalska622 pushed a commit to akowalska622/kibana that referenced this pull request May 29, 2025
…ic#216756)

Closes elastic#198685

## Summary

This PR creates a public Maintenance Window API.

The work was done on a feature branch over multiple separate PRs. Here
we will merge the feature branch into `main`.
- elastic#209734
- elastic#213694
- elastic#214747
- elastic#213771

The [documentation PR](elastic#212377)
still needs to be merged.

## Release Notes

Publish new public APIs for the Maintenance Window.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:feature Makes this part of the condensed release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.19.0 v9.1.0

7 participants