-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Fleet] use @kbn/config-schema in Fleet API (Part 1) #192883
Conversation
## Summary Part of elastic#184685 First set of changes, I'm planning to do more prs for the remaining endpoints. Will also look at making sure these schema definitions are included in the final kibana `bundle.json`, related doc: https://elasticco.atlassian.net/wiki/spaces/DOC/pages/450494532/API+reference+docs When all schema definitions are moved to code, the fleet/openapi folder can be deleted. To check the result, add to `kibana.dev.yml`: `server.oas.enabled: true` And then in kibana console, query: ``` GET kbn:/api/oas?pathStartsWith=/api/fleet/setup GET kbn:/api/oas?pathStartsWith=/api/fleet/agents/setup GET kbn:/api/oas?pathStartsWith=/api/fleet/package_policies GET kbn:/api/oas?pathStartsWith=/api/fleet/package_policies/delete GET kbn:/api/oas?pathStartsWith=/api/fleet/settings GET kbn:/api/oas?pathStartsWith=/internal/fleet/settings/enrollment ``` To generate the bundle from code, run: ``` node scripts/capture_oas_snapshot --include-path /api/fleet --no-serverless --update # writes to oas_docs/bundle.json ``` Response: ``` { "openapi": "3.0.0", "info": { "title": "Kibana HTTP APIs", "version": "0.0.0" }, "servers": [ { "url": "http://localhost:5603/julia" } ], "paths": { "/api/fleet/setup": { "post": { "summary": "", "tags": [], "description": "Initiate Fleet setup", "responses": { "200": { "content": { "application/json; Elastic-Api-Version=2023-10-31": { "schema": { "type": "object", "description": "A summary of the result of Fleet's `setup` lifecycle. If `isInitialized` is true, Fleet is ready to accept agent enrollment. `nonFatalErrors` may include useful insight into non-blocking issues with Fleet setup.", "properties": { "isInitialized": { "type": "boolean" }, "nonFatalErrors": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "message": { "type": "string" } }, "additionalProperties": false, "required": [ "name", "message" ] } } }, "additionalProperties": false, "required": [ "isInitialized", "nonFatalErrors" ] } } } }, "400": { "content": { "application/json; Elastic-Api-Version=2023-10-31": { "schema": { "type": "object", "description": "Generic Error", "properties": { "statusCode": { "type": "number" }, "error": { "type": "string" }, "message": { "type": "string" } }, "additionalProperties": false, "required": [ "statusCode", "error", "message" ] } } } }, "500": { "content": { "application/json; Elastic-Api-Version=2023-10-31": { "schema": { "type": "object", "description": "Internal Server Error", "properties": { "message": { "type": "string" } }, "additionalProperties": false, "required": [ "message" ] } } } } }, "parameters": [ { "in": "header", "name": "elastic-api-version", "description": "The version of the API to use", "schema": { "type": "string", "enum": [ "2023-10-31" ], "default": "2023-10-31" } }, { "description": "A required header to protect against CSRF attacks", "in": "header", "name": "kbn-xsrf", "required": true, "schema": { "example": "true", "type": "string" } } ], "operationId": "%2Fapi%2Ffleet%2Fsetup#0" } } }, "components": { "schemas": {}, "securitySchemes": { "basicAuth": { "type": "http", "scheme": "basic" }, "apiKeyAuth": { "type": "apiKey", "in": "header", "name": "Authorization" } } }, "security": [ { "basicAuth": [] } ], "tags": [] } ```
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
}); | ||
|
||
const validationResp = PackagePolicyResponseSchema.validate(responseItem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this way I'm making sure the response schema works, trying to fill all fields in objects, including optional ones
Pinging @elastic/fleet (Team:Fleet) |
@juliaElastic I'm testing this branch locally. The specs are correctly generated from dev tools, but I found some failures on Let me know if you need more info. I'll keep testing other paths. Note: from package_policies I also deleted one integration policy, upgraded one that had older version and ran dryRun and they all worked for me. As of now the only two endpoints that had issues are the above. |
Fixed the issue with the create package policy. |
it happened with an old version of custom logs. I'll pull the latest version and see if I can reproduce it again. |
With your latest changes, I tested the edit of package policies and it works fine now. The dryRun worked in one case but I tried again with custom log:
|
I was going to ask the same thing. Is there any way we can automate this? Do you think that it can happen only with the dryRun handler or also with other ones? We should have some degree of confidence that shipping this change won't break many integrations. |
I could write a script that creates package policies for all packages in EPR, it's only tricky where there are required fields to fill out to create successfully. I suppose errors can happen in any API where the package policy has different fields than defined in the model types. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code LGTM
I tested a bit more and didn't find any obvious error, however I am not sure how we can avoid breakages of the package policies apis.
💛 Build succeeded, but was flaky
Failed CI StepsTest FailuresMetrics [docs]
History
To update your PR or re-run it, just comment with: |
I'm running cypress tests locally to create a package policy for each package and check that it's successful. It takes a while, not seeing any other issues so far. |
## Summary Relates elastic#184685 Readd elastic#192447 with fixes and tests to validate that the response schemas are correct. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios (cherry picked from commit 406f073)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…193296) # Backport This will backport the following commits from `main` to `8.x`: - [[Fleet] use @kbn/config-schema in Fleet API (Part 1) (#192883)](#192883) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia Bardi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-18T13:13:21Z","message":"[Fleet] use @kbn/config-schema in Fleet API (Part 1) (#192883)\n\n## Summary\r\n\r\nRelates https://github.com/elastic/kibana/issues/184685\r\n\r\nReadd #192447 with fixes and tests\r\nto validate that the response schemas are correct.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"406f07386ca6b35f375e8f22e682e44c101b1182","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:prev-minor","v8.16.0"],"title":"[Fleet] use @kbn/config-schema in Fleet API (Part 1)","number":192883,"url":"https://github.com/elastic/kibana/pull/192883","mergeCommit":{"message":"[Fleet] use @kbn/config-schema in Fleet API (Part 1) (#192883)\n\n## Summary\r\n\r\nRelates https://github.com/elastic/kibana/issues/184685\r\n\r\nReadd #192447 with fixes and tests\r\nto validate that the response schemas are correct.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"406f07386ca6b35f375e8f22e682e44c101b1182"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192883","number":192883,"mergeCommit":{"message":"[Fleet] use @kbn/config-schema in Fleet API (Part 1) (#192883)\n\n## Summary\r\n\r\nRelates https://github.com/elastic/kibana/issues/184685\r\n\r\nReadd #192447 with fixes and tests\r\nto validate that the response schemas are correct.\r\n\r\n### Checklist\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios","sha":"406f07386ca6b35f375e8f22e682e44c101b1182"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Julia Bardi <[email protected]>
…lastic#192883) (elastic#193296)" This reverts commit 9672d81.
Summary
Relates #184685
Readd #192447 with fixes and tests to validate that the response schemas are correct.
Checklist