Skip to content
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

[OAS] Include alerting rule APIs #189962

Merged
merged 11 commits into from
Aug 13, 2024

Conversation

jloleysens
Copy link
Contributor

Summary

Includes alerting rule APIs in our OAS snapshots.

How to test

Using bump CLI you can preview the output:

bump preview ./oas_docs/bundle.json
# or
bump preview ./oas_docs/bundle.serverless.json

@jloleysens jloleysens added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:OAS Work or issues related to Core-provided mechanisms for generating OAS v8.16.0 labels Aug 6, 2024
@jloleysens jloleysens requested a review from lcawl August 6, 2024 10:40
@jloleysens jloleysens self-assigned this Aug 6, 2024
@jloleysens jloleysens requested a review from a team as a code owner August 6, 2024 10:40
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@elasticmachine
Copy link
Contributor

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

@jloleysens
Copy link
Contributor Author

@lcawl previewing this in bump.sh does not render the "Create a rule" operation, any ideas on why that might be 🤔 ?

@lcawl
Copy link
Contributor

lcawl commented Aug 6, 2024

@lcawl previewing this in bump.sh does not render the "Create a rule" operation, any ideas on why that might be 🤔 ?

One of the errors returned by the linter is as follows:

1500:24 warning operation-operationId-valid-in-url operationId must not characters that are invalid when used in URL. paths./api/alerting/rule/{id}.post.operationId
2908:24 warning operation-operationId-valid-in-url operationId must not characters that are invalid when used in URL. paths./api/alerting/rule/{id}.put.operationId
...

Per https://docs.stoplight.io/docs/spectral/4dec24461f3af-open-api-rules#operation-operationid-valid-in-url "Seeing as operationId is often used for unique URLs in documentation systems, it's a good idea to avoid non-URL-safe characters."

In the preview, the URL that is derived from the operationId in the OpenAPI document for "get rule details" is "operation-api-alerting-rule-id-0", which seems very likely to be the same as what would be derived from the "create a rule" operationId (/api/alerting/rule/{id?}#0).

Is there some way we can generate a more URL-safe unique operationId for each operation in the document? To ensure that it doesn't change, perhaps the simplest method is to provide it as a value in the code?

@jloleysens jloleysens requested a review from a team as a code owner August 7, 2024 08:27
@jloleysens
Copy link
Contributor Author

Thanks for the pointer at @lcawl , I retested with URL encoded operation IDs (c0473d1) and seems to work as expected now.

@lcawl
Copy link
Contributor

lcawl commented Aug 8, 2024

Yay, I'm glad the operationId solution worked. There are a few other things picked up by the linter that I think are worth mentioning. Not sure if they need to be resolved in the core functionality or if it's just something incorrect in the alerting API details specifically, but here's what I see:

Empty enum list

error oas3-schema "enum" property must not have fewer than 1 items.

For example:

                                  {
                                    "enum": [],
                                    "nullable": true
                                  }

This missing information shows up in the docs like this:

image

Optional path parameters

error oas3-schema "required" property must be equal to constant.

For example:

 {
            "description": "The identifier for the rule.",
            "in": "path",
            "name": "id",
            "required": false,
            "schema": {
              "type": "string"
            }
          }

Per https://spec.openapis.org/oas/v3.0.3#parameter-object "If the parameter location is "path", this [required] property is REQUIRED and its value MUST be true" so I suspect that's the cause of this message. The docs preview doesn't seem to mind this, however:

image

Empty required lists

error oas3-schema "required" property must not have fewer than 1 items.

For example:

                            "required": [],
                            "type": "object"

It looks like this is ignored and non-problematic in the docs, so perhaps it is another case where if we can't omit the empty lists we can just lower the severity of this oas3-schema rule in our linter so it's not considered an error.

@jloleysens
Copy link
Contributor Author

jloleysens commented Aug 9, 2024

Empty enum list

Should be fixed 06bc1a3

Optional path parameters

I'm not entirely sure I understand the lint rule in this case. Are optional path parameters not possible in OAS? Kibana does support optional path parameters so not sure how to reconcile those.

Empty required lists

Should be fixed b776259


More a q for responseops: In bump and in the diff I noticed that certain fields that are nullable are being marked as required:

Screenshot 2024-08-09 at 14 27 59 vs. Screenshot 2024-08-09 at 14 27 48

Could it be that these should both be schema.maybe instead of one them being nullable?


Would you mind taking another look @lcawl ?

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

History

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

cc @jloleysens

@lcawl
Copy link
Contributor

lcawl commented Aug 9, 2024

Optional path parameters

I'm not entirely sure I understand the lint rule in this case. Are optional path parameters not possible in OAS? Kibana does support optional path parameters so not sure how to reconcile those.

Yeah, you basically have to have two copies defined: one with the parameter and one without. Per OAI/OpenAPI-Specification#93 (comment) it seems like this will be fixed in the next OAS version and since Bump.sh doesn't seem to have a problem with it, it's probably not worth "fixing" to align with OAS v3.

Would you mind taking another look @lcawl ?

Those fixes all look great, thanks! There is one more that I must have missed in the previous lint results related to some empty responses, so I've created #190265

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.

IMO this PR can wait for #190265 or I can regenerate the bundles thereafter.

@pmuellr
Copy link
Member

pmuellr commented Aug 12, 2024

Could it be that these should both be schema.maybe instead of one them being nullable? (throttle)

I'm a little surprised to see schema.nullable() used here. We built it specifically for our saved objects, as we can't use maybe because then it's valid to not pass the field, or otherwise call it with undefined. But we need to massage it to null in those cases. We do this as we sometimes do non-full updates, so if the value is undefined, but the persisted value isn't null, that persisted value will stick around even though we wanted it "nulled out".

I would think on an API definition it would basically mean optional, or maybe T | null | undefined. Since I doubt many folks are familiar with schema.nullable(), it would be best to not use it for the APIs ...

@jloleysens
Copy link
Contributor Author

jloleysens commented Aug 13, 2024

T | null | undefined

Yeah, the main concern I wanted to raise is cases where T | null where it should be T | undefined or even T | null | undefined. Thanks for sharing that context about SOs. I get the desire to reuse but agree that it may be the incorrect type for the HTTP APIs. Bad JS design decisions live on 😅

FWIW I don't think this is a blocker, but happy to view it as one if you feel differently @pmuellr

…t --include-path /api/status --include-path /api/alerting/rule/ --include-path /api/alerting/rules --update'
@jloleysens jloleysens merged commit b85b1cb into elastic:main Aug 13, 2024
21 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Aug 13, 2024
@jloleysens jloleysens deleted the oas/capture-alerting-apis branch August 13, 2024 15:21
bryce-b pushed a commit to bryce-b/kibana that referenced this pull request Aug 13, 2024
## Summary

Includes alerting rule APIs in our OAS snapshots.

## How to test

Using bump CLI you can preview the output:

```sh
bump preview ./oas_docs/bundle.json
# or
bump preview ./oas_docs/bundle.serverless.json
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
jbudz added a commit that referenced this pull request Aug 13, 2024
@jbudz jbudz added the reverted label Aug 13, 2024
@jbudz
Copy link
Member

jbudz commented Aug 13, 2024

@lcawl
Copy link
Contributor

lcawl commented Aug 13, 2024

IMO all of those "errors" should be warnings so I've created a PR (#190470) that changes the severity level of those linting rules (though it's cool to see them incorporated into an automated check)!

lcawl pushed a commit to lcawl/kibana that referenced this pull request Aug 15, 2024
## Summary

Includes alerting rule APIs in our OAS snapshots.

## How to test

Using bump CLI you can preview the output:

```sh
bump preview ./oas_docs/bundle.json
# or
bump preview ./oas_docs/bundle.serverless.json
```

---------

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
backport:skip This commit 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 reverted Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants