Skip to content

[HTTP/OAS] Commit OAS snapshot#183338

Merged
jloleysens merged 44 commits intoelastic:mainfrom
jloleysens:oas/write-bundled-file-to-disk
May 30, 2024
Merged

[HTTP/OAS] Commit OAS snapshot#183338
jloleysens merged 44 commits intoelastic:mainfrom
jloleysens:oas/write-bundled-file-to-disk

Conversation

@jloleysens
Copy link
Copy Markdown
Contributor

@jloleysens jloleysens commented May 13, 2024

Close #181992

Summary

First iteration of a CLI to capture an OAS snapshot.

How to test

Run node ./scripts/capture_oas_snapshot.js --update --include-path /api/status and see result in oas_docs/bundle.json.

If you have the bump CLI installed you can preview the hosted output with bump preview ./oas_docs/bundle.json

Notes

  • Added ability to filter by version, access (public/internal) and excluding paths explicitly to the OAS generation lib
  • Follows the same general pattern as our other "capture" CLIs like packages/kbn-check-mappings-update-cli
  • Result includes only /api/status for now, waiting for other paths to add missing parts

expect(result.status).toBe(200);
expect(result.body).toMatchObject(includes);
expect(result.body).not.toMatchObject(excludes);
excludes.forEach((exclude) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So... this test was not working as expected 🙈

title: 'Kibana HTTP APIs',
version: '0.0.0', // TODO get a better version here
pathStartsWith,
filters: { pathStartsWith, excludePathsMatching, access, version },
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a few more filtering options. Most notably: excludePathsMatching, access and version

* (dodges issues with open handles), and so that we can harvest logs and feed them into
* the logger when debugging.
*/
export function kibana(log: SomeDevLog) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Mostly copy-pasta from packages/kbn-check-mappings-update-cli/src/compatibility/extract_mappings_from_plugins.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh yeah, that whole forking the process logic again 🙈.

Note blocker in any way, but shall we try to factorize the process forking / worker code at some point (do we know how many time that code got duplicated)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just this time again to my knowledge, I guess we could factorize some parts of it. Do you think they could live in something like @kbn/dev-utils?

const getRouterDefaults = () => ({
isVersioned: false,
path: '/foo/{id}',
path: '/foo/{id}/{path*}',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Test special * syntax

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

❯ jq ".paths | length" ./oas_docs/bundle.json
141

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Might want to consider starting smaller...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If size becomes an issue, we could always consider storing it in a different repo as long as we could also figure out the cadence for publishing it

Copy link
Copy Markdown
Contributor Author

@jloleysens jloleysens May 21, 2024

Choose a reason for hiding this comment

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

I just meant it's a lot of paths that need to be audited/quality controlled 😅 . Pretty sure there is a lot of room to grow here. For a start we can just include the paths that are ready for docs.

@lcawl
Copy link
Copy Markdown
Member

lcawl commented May 21, 2024

When I run linters on the bundled.json file, I get some errors that I think are noteworthy. For example:

  1. Missing description in responses

[79] bundle.json:36327:11 at #/paths/1api1uptime~1settings/put/responses/200
The field description must be present on this level.

This relates to the required field described in https://spec.openapis.org/oas/v3.0.3#response-object

  1. Nullable fields

[77] bundle.json:35842:39 at #/paths/1api1telemetry1v21config/get/responses/200/content/application~1json; Elastic-Api-Version=2023-10-31/schema/properties/optIn/anyOf/1/nullable
The type field must be defined when the nullable field is used.

I think is just related to the placement of the nullable:true qualifiers.

  1. Undefined parameters

[72] bundle.json:34683:9 at > #/paths/1api1osquery1saved_queries1{id}/delete/parameters
The operation does not define the path parameter {id} expected by path /api/osquery/saved_queries/{id}.

These seem to have missing definitions.

@jloleysens
Copy link
Copy Markdown
Contributor Author

/ci

@jloleysens
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM, a few remarks and questions

const schemas = handler ? extractValidationSchemaFromVersionedHandler(handler) : undefined;
let version: undefined | string;
let handler: undefined | VersionedRouterRoute['handlers'][0];
let versions: string[] = route.handlers.map(({ options: { version: v } }) => v).sort();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if relevant, but for internal versions, I think just using sort() may be too naive? E.g [1, 2, ...., 10].sort() => 1, 10, 2, 3...

And it seems we're then using that sorting for slicing L47

      const versionIdx = versions.indexOf(filters.version);
      if (versionIdx === -1) return { paths };
      versions = versions.slice(0, versionIdx + 1);

(but are we even generating for internal APIs?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yea, you found a bug in the logic, will fix!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See 8861024 and 407b3de

packages/kbn-calculate-auto @elastic/obs-ux-management-team
packages/kbn-calculate-width-from-char-count @elastic/kibana-visualizations
x-pack/plugins/canvas @elastic/kibana-presentation
packages/kbn-capture-oas-snapshot-cli @elastic/kibana-core
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hum, this is strange, the files under that new packages aren't considered as owned by Core for the PR review 🤔. I had to remove the code owner filtering.... IIRC it used to work.

* (dodges issues with open handles), and so that we can harvest logs and feed them into
* the logger when debugging.
*/
export function kibana(log: SomeDevLog) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh yeah, that whole forking the process logic again 🙈.

Note blocker in any way, but shall we try to factorize the process forking / worker code at some point (do we know how many time that code got duplicated)?

* @example Given 'internal' versions ["1", "10", "2"] it will return ["1", "2", "10]
* @example Given 'public' versions ["2023-01-01", "2002-10-10", "2005-01-01"] it will return ["2002-10-10", "2005-01-01", "2023-01-01"]
*/
export const sort = (versions: string[], access: 'public' | 'internal') => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sort of related to this PR, @pgayvallet found a bug in this logic that was not treating internal versions correctly. Updated and tried to preserve existing APIs as far as possible.

* Provide a TS file as the src of a NodeJS Worker with some built-in handling
* of std streams and debugging.
*/
export function startTSWorker<Message>({ log, src, cwd = REPO_ROOT }: StartTSWorkerArgs) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

New utility that does all the RX piping and starting of a node js worker for us.

@jloleysens jloleysens enabled auto-merge (squash) May 30, 2024 11:32
@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

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
@kbn/core-http-router-server-internal 48 54 +6
@kbn/dev-utils 32 33 +1
total +7
Unknown metric groups

API count

id before after diff
@kbn/core-http-router-server-internal 48 54 +6
@kbn/dev-utils 36 38 +2
total +8

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jloleysens jloleysens merged commit 975eeed into elastic:main May 30, 2024
@kibanamachine kibanamachine added the backport:skip This PR does not require backporting label May 30, 2024
@jloleysens jloleysens deleted the oas/write-bundled-file-to-disk branch May 30, 2024 13:37
tylersmalley added a commit that referenced this pull request Feb 14, 2026
It's not an actual dependency of downstream steps, but was added more to
provide as a cost cutting gate. However, there are times it delays
downstream steps without any added value.

Here's the provenance for `check_oas_snapshot` in the pull-request
pipeline.

### 1. OAS snapshot capture first added to CI (inside "Checks")

- [PR #183338](#183338) / commit
[`975eeed255d0`](975eeed255d0)
(May 30, 2024) —
 "[HTTP/OAS] Commit OAS snapshot"
- Added `.buildkite/scripts/steps/capture_oas_snapshot.sh` and wired it
into `.buildkite/scripts/steps/checks.sh` (so it ran as part of the
Checks step, not a
standalone pipeline step yet).

### 2. Standalone "Check OAS Snapshot" step added to PR pipeline

- [PR #196534](#196534) / commit
[`2fbc843e0d69`](2fbc843e0d69)
(Oct 17, 2024) —
 "[ci] Extract OAS check + add retry"
- Motivation (from the PR summary): the capture step was flaky and was
breaking Checks; they extracted it into its own heavy step (starts
ES+Kibana) and added
retries.
- This is where it gets added as its own step in
`.buildkite/pipelines/pull_request/base.yml`, running
`.buildkite/scripts/steps/checks/capture_oas_snapshot.sh`.

### 3. `depends_on: check_oas_snapshot` added across PR test suite
pipelines

- [PR #198452](#198452) / commit
[`cbb211abe0cd`](cbb211abe0cd)
(Nov 4, 2024) —
"[ci] Run checks before tests"
- This commit added `key: check_oas_snapshot` in
`.buildkite/pipelines/pull_request/base.yml` and updated many PR suite
pipeline YAMLs to depend on it (and on
`checks`) before running.
- Example change: `.buildkite/pipelines/pull_request/response_ops.yml`
adds `- check_oas_snapshot` under `depends_on` in that commit.

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
patrykkopycinski pushed a commit to patrykkopycinski/kibana that referenced this pull request Feb 19, 2026
It's not an actual dependency of downstream steps, but was added more to
provide as a cost cutting gate. However, there are times it delays
downstream steps without any added value.

Here's the provenance for `check_oas_snapshot` in the pull-request
pipeline.

### 1. OAS snapshot capture first added to CI (inside "Checks")

- [PR elastic#183338](elastic#183338) / commit
[`975eeed255d0`](elastic@975eeed255d0)
(May 30, 2024) —
 "[HTTP/OAS] Commit OAS snapshot"
- Added `.buildkite/scripts/steps/capture_oas_snapshot.sh` and wired it
into `.buildkite/scripts/steps/checks.sh` (so it ran as part of the
Checks step, not a
standalone pipeline step yet).

### 2. Standalone "Check OAS Snapshot" step added to PR pipeline

- [PR elastic#196534](elastic#196534) / commit
[`2fbc843e0d69`](elastic@2fbc843e0d69)
(Oct 17, 2024) —
 "[ci] Extract OAS check + add retry"
- Motivation (from the PR summary): the capture step was flaky and was
breaking Checks; they extracted it into its own heavy step (starts
ES+Kibana) and added
retries.
- This is where it gets added as its own step in
`.buildkite/pipelines/pull_request/base.yml`, running
`.buildkite/scripts/steps/checks/capture_oas_snapshot.sh`.

### 3. `depends_on: check_oas_snapshot` added across PR test suite
pipelines

- [PR elastic#198452](elastic#198452) / commit
[`cbb211abe0cd`](elastic@cbb211abe0cd)
(Nov 4, 2024) —
"[ci] Run checks before tests"
- This commit added `key: check_oas_snapshot` in
`.buildkite/pipelines/pull_request/base.yml` and updated many PR suite
pipeline YAMLs to depend on it (and on
`checks`) before running.
- Example change: `.buildkite/pipelines/pull_request/response_ops.yml`
adds `- check_oas_snapshot` under `depends_on` in that commit.

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
ersin-erdal pushed a commit to ersin-erdal/kibana that referenced this pull request Feb 19, 2026
It's not an actual dependency of downstream steps, but was added more to
provide as a cost cutting gate. However, there are times it delays
downstream steps without any added value.

Here's the provenance for `check_oas_snapshot` in the pull-request
pipeline.

### 1. OAS snapshot capture first added to CI (inside "Checks")

- [PR elastic#183338](elastic#183338) / commit
[`975eeed255d0`](elastic@975eeed255d0)
(May 30, 2024) —
 "[HTTP/OAS] Commit OAS snapshot"
- Added `.buildkite/scripts/steps/capture_oas_snapshot.sh` and wired it
into `.buildkite/scripts/steps/checks.sh` (so it ran as part of the
Checks step, not a
standalone pipeline step yet).

### 2. Standalone "Check OAS Snapshot" step added to PR pipeline

- [PR elastic#196534](elastic#196534) / commit
[`2fbc843e0d69`](elastic@2fbc843e0d69)
(Oct 17, 2024) —
 "[ci] Extract OAS check + add retry"
- Motivation (from the PR summary): the capture step was flaky and was
breaking Checks; they extracted it into its own heavy step (starts
ES+Kibana) and added
retries.
- This is where it gets added as its own step in
`.buildkite/pipelines/pull_request/base.yml`, running
`.buildkite/scripts/steps/checks/capture_oas_snapshot.sh`.

### 3. `depends_on: check_oas_snapshot` added across PR test suite
pipelines

- [PR elastic#198452](elastic#198452) / commit
[`cbb211abe0cd`](elastic@cbb211abe0cd)
(Nov 4, 2024) —
"[ci] Run checks before tests"
- This commit added `key: check_oas_snapshot` in
`.buildkite/pipelines/pull_request/base.yml` and updated many PR suite
pipeline YAMLs to depend on it (and on
`checks`) before running.
- Example change: `.buildkite/pipelines/pull_request/response_ops.yml`
adds `- check_oas_snapshot` under `depends_on` in that commit.

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:OAS Work or issues related to Core-provided mechanisms for generating OAS release_note:skip Skip the PR/issue when compiling release notes Team:Core Platform Core services: plugins, logging, config, saved objects, http, ES client, i18n, etc t// v8.15.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[OAS] Create and commit OAS bundle

7 participants