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

Epic: Syncing OAS with Kibana code part I #180056

Open
10 of 16 tasks
jloleysens opened this issue Apr 4, 2024 · 3 comments
Open
10 of 16 tasks

Epic: Syncing OAS with Kibana code part I #180056

jloleysens opened this issue Apr 4, 2024 · 3 comments
Assignees
Labels
Meta Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@jloleysens
Copy link
Contributor

jloleysens commented Apr 4, 2024

Summary

We intend to use this issue to track progress of the work being done to enable Kibana's runtime validation schemas to generate OAS.

The approach

  • Leverage existing runtime validation schemas, specifically @kbn/config-schema. It is possible to support other runtime validation schemas, but to start with we will only support @kbn/config-schema.
  • Based on this PoC

Tasks

  1. Feature:OAS Team:Core
    jloleysens
  2. Feature:OAS Team:Core
  3. Feature:OAS Feature:http Team:Core
  4. Feature:OAS Team:Core
    jloleysens
  5. Feature:OAS Team:Core
  6. Feature:OAS Team:Core
  7. Feature:OAS Team:Core
  8. Feature:OAS Team:Core
  9. Feature:OAS Team:Core
  10. Feature:OAS Team:Core
@jloleysens jloleysens added the Meta label Apr 4, 2024
@jloleysens jloleysens self-assigned this Apr 4, 2024
@botelastic botelastic bot added the needs-team Issues missing a team label label Apr 4, 2024
@jloleysens jloleysens added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Apr 4, 2024
@elasticmachine
Copy link
Contributor

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

@botelastic botelastic bot removed the needs-team Issues missing a team label label Apr 4, 2024
jloleysens added a commit that referenced this issue Apr 9, 2024
## Summary

Introduces a set of meta fields that will be used to track metadata lost
in how we currently use `joi` inside of `@kbn/config-schema`.

## Notes

* Related #180056
* Changes cherry-picked from
#156357
* Changes are not used for anything in this PR, they are intended to
enable our OAS generation scripts
jloleysens added a commit that referenced this issue Apr 11, 2024
@rayafratkina rayafratkina changed the title Syncing OAS with Kibana code Epic: Syncing OAS with Kibana code Apr 15, 2024
@jloleysens
Copy link
Contributor Author

jloleysens commented Apr 22, 2024

Milestone

Teams can start providing response schemas and testing the OAS generated from @kbn/config-schema schemas. Core has started with the /api/status, see here. Note: at the moment it is possible to generate OAS using @kbn/config-schema.

We have added:

jloleysens added a commit that referenced this issue May 2, 2024
## Summary

Related to #180056

Adds the ability to specify a content type for the request / response of
an API. The current approach is to use the `options.accepts` value
already present on the route but to also add the ability to specify a
content type per response, otherwise fallback to `application/json`.

## Notes

* Fixed an issue where we might not be iterating over response codes
correctly (and updated test cases)
* Refactored the `generate_oas.ts` script to be more maintainable
(apologies for the noise)
yuliacech pushed a commit to yuliacech/kibana that referenced this issue May 3, 2024
## Summary

Related to elastic#180056

Adds the ability to specify a content type for the request / response of
an API. The current approach is to use the `options.accepts` value
already present on the route but to also add the ability to specify a
content type per response, otherwise fallback to `application/json`.

## Notes

* Fixed an issue where we might not be iterating over response codes
correctly (and updated test cases)
* Refactored the `generate_oas.ts` script to be more maintainable
(apologies for the noise)
@jloleysens jloleysens changed the title Epic: Syncing OAS with Kibana code Epic: Syncing OAS with Kibana code part I May 6, 2024
jloleysens added a commit that referenced this issue May 7, 2024
## Summary

Part #180056. Adds new response
schemas to the `/api/status` endpoint for the purposes of OAS
generation.

## How to test

1. Start ES
2. Add `server.oas.enabled: true` to `kibana.dev.yml`
3. Start Kibana `yarn start --no-base-path`
4. `curl -s -uelastic:changeme
http://localhost:5601/api/oas\?pathStartsWith\=/api/status | jq`

<details>

<summary>output</summary>

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Kibana HTTP APIs",
    "version": "0.0.0"
  },
  "servers": [
    {
      "url": "http://localhost:5601"
    }
  ],
  "paths": {
    "/api/status": {
      "get": {
        "summary": "Get Kibana's current status.",
        "responses": {
          "200": {
            "description": "Get Kibana's current status.",
            "content": {
              "application/json; Elastic-Api-Version=2023-10-31": {
                "schema": {
                  "description": "Kibana's operational status. A minimal response is sent for unauthorized users.",
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/core.status.response"
                    },
                    {
                      "$ref": "#/components/schemas/core.status.redactedResponse"
                    }
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Get Kibana's current status.",
            "content": {
              "application/json; Elastic-Api-Version=2023-10-31": {
                "schema": {
                  "description": "Kibana's operational status. A minimal response is sent for unauthorized users.",
                  "anyOf": [
                    {
                      "$ref": "#/components/schemas/core.status.response"
                    },
                    {
                      "$ref": "#/components/schemas/core.status.redactedResponse"
                    }
                  ]
                }
              }
            }
          }
        },
        "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"
            }
          },
          {
            "name": "v7format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Set to \"true\" to get the response in v7 format."
          },
          {
            "name": "v8format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Set to \"true\" to get the response in v8 format."
          }
        ],
        "operationId": "/api/status#0"
      }
    }
  },
  "components": {
    "schemas": {
      "core.status.response": {
        "description": "Kibana's operational status as well as a detailed breakdown of plugin statuses indication of various loads (like event loop utilization and network traffic) at time of request.",
        "type": "object",
        "properties": {
          "name": {
            "description": "Kibana instance name.",
            "type": "string"
          },
          "uuid": {
            "description": "Unique, generated Kibana instance UUID. This UUID should persist even if the Kibana process restarts.",
            "type": "string"
          },
          "version": {
            "type": "object",
            "properties": {
              "number": {
                "description": "A semantic version number.",
                "type": "string"
              },
              "build_hash": {
                "description": "A unique hash value representing the git commit of this Kibana build.",
                "type": "string"
              },
              "build_number": {
                "description": "A monotonically increasing number, each subsequent build will have a higher number.",
                "type": "number"
              },
              "build_snapshot": {
                "description": "Whether this build is a snapshot build.",
                "type": "boolean"
              },
              "build_flavor": {
                "description": "The build flavour determines configuration and behavior of Kibana. On premise users will almost always run the \"traditional\" flavour, while other flavours are reserved for Elastic-specific use cases.",
                "anyOf": [
                  {
                    "enum": [
                      "serverless"
                    ],
                    "type": "string"
                  },
                  {
                    "enum": [
                      "traditional"
                    ],
                    "type": "string"
                  }
                ]
              },
              "build_date": {
                "description": "The date and time of this build.",
                "type": "string"
              }
            },
            "additionalProperties": false,
            "required": [
              "number",
              "build_hash",
              "build_number",
              "build_snapshot",
              "build_flavor",
              "build_date"
            ]
          },
          "status": {
            "type": "object",
            "properties": {
              "overall": {
                "type": "object",
                "properties": {
                  "level": {
                    "description": "Service status levels as human and machine readable values.",
                    "anyOf": [
                      {
                        "enum": [
                          "available"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "degraded"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "unavailable"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "critical"
                        ],
                        "type": "string"
                      }
                    ]
                  },
                  "summary": {
                    "description": "A human readable summary of the service status.",
                    "type": "string"
                  },
                  "detail": {
                    "description": "Human readable detail of the service status.",
                    "type": "string"
                  },
                  "documentationUrl": {
                    "description": "A URL to further documentation regarding this service.",
                    "type": "string"
                  },
                  "meta": {
                    "description": "An unstructured set of extra metadata about this service.",
                    "type": "object",
                    "additionalProperties": {}
                  }
                },
                "additionalProperties": false,
                "required": [
                  "level",
                  "summary",
                  "meta"
                ]
              },
              "core": {
                "description": "Statuses of core Kibana services.",
                "type": "object",
                "properties": {
                  "elasticsearch": {
                    "type": "object",
                    "properties": {
                      "level": {
                        "description": "Service status levels as human and machine readable values.",
                        "anyOf": [
                          {
                            "enum": [
                              "available"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "degraded"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "unavailable"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "critical"
                            ],
                            "type": "string"
                          }
                        ]
                      },
                      "summary": {
                        "description": "A human readable summary of the service status.",
                        "type": "string"
                      },
                      "detail": {
                        "description": "Human readable detail of the service status.",
                        "type": "string"
                      },
                      "documentationUrl": {
                        "description": "A URL to further documentation regarding this service.",
                        "type": "string"
                      },
                      "meta": {
                        "description": "An unstructured set of extra metadata about this service.",
                        "type": "object",
                        "additionalProperties": {}
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "level",
                      "summary",
                      "meta"
                    ]
                  },
                  "savedObjects": {
                    "type": "object",
                    "properties": {
                      "level": {
                        "description": "Service status levels as human and machine readable values.",
                        "anyOf": [
                          {
                            "enum": [
                              "available"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "degraded"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "unavailable"
                            ],
                            "type": "string"
                          },
                          {
                            "enum": [
                              "critical"
                            ],
                            "type": "string"
                          }
                        ]
                      },
                      "summary": {
                        "description": "A human readable summary of the service status.",
                        "type": "string"
                      },
                      "detail": {
                        "description": "Human readable detail of the service status.",
                        "type": "string"
                      },
                      "documentationUrl": {
                        "description": "A URL to further documentation regarding this service.",
                        "type": "string"
                      },
                      "meta": {
                        "description": "An unstructured set of extra metadata about this service.",
                        "type": "object",
                        "additionalProperties": {}
                      }
                    },
                    "additionalProperties": false,
                    "required": [
                      "level",
                      "summary",
                      "meta"
                    ]
                  }
                },
                "additionalProperties": false,
                "required": [
                  "elasticsearch",
                  "savedObjects"
                ]
              },
              "plugins": {
                "description": "A dynamic mapping of plugin ID to plugin status.",
                "type": "object",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "level": {
                      "description": "Service status levels as human and machine readable values.",
                      "anyOf": [
                        {
                          "enum": [
                            "available"
                          ],
                          "type": "string"
                        },
                        {
                          "enum": [
                            "degraded"
                          ],
                          "type": "string"
                        },
                        {
                          "enum": [
                            "unavailable"
                          ],
                          "type": "string"
                        },
                        {
                          "enum": [
                            "critical"
                          ],
                          "type": "string"
                        }
                      ]
                    },
                    "summary": {
                      "description": "A human readable summary of the service status.",
                      "type": "string"
                    },
                    "detail": {
                      "description": "Human readable detail of the service status.",
                      "type": "string"
                    },
                    "documentationUrl": {
                      "description": "A URL to further documentation regarding this service.",
                      "type": "string"
                    },
                    "meta": {
                      "description": "An unstructured set of extra metadata about this service.",
                      "type": "object",
                      "additionalProperties": {}
                    }
                  },
                  "additionalProperties": false,
                  "required": [
                    "level",
                    "summary",
                    "meta"
                  ]
                }
              }
            },
            "additionalProperties": false,
            "required": [
              "overall",
              "core",
              "plugins"
            ]
          },
          "metrics": {
            "description": "Metric groups collected by Kibana.",
            "type": "object",
            "properties": {
              "elasticsearch_client": {
                "description": "Current network metrics of Kibana's Elasticsearch client.",
                "type": "object",
                "properties": {
                  "totalActiveSockets": {
                    "description": "Count of network sockets currently in use.",
                    "type": "number"
                  },
                  "totalIdleSockets": {
                    "description": "Count of network sockets currently idle.",
                    "type": "number"
                  },
                  "totalQueuedRequests": {
                    "description": "Count of requests not yet assigned to sockets.",
                    "type": "number"
                  }
                },
                "additionalProperties": false,
                "required": [
                  "totalActiveSockets",
                  "totalIdleSockets",
                  "totalQueuedRequests"
                ]
              },
              "last_updated": {
                "description": "The time metrics were collected.",
                "type": "string"
              },
              "collection_interval_in_millis": {
                "description": "The interval at which metrics should be collected.",
                "type": "number"
              }
            },
            "additionalProperties": false,
            "required": [
              "elasticsearch_client",
              "last_updated",
              "collection_interval_in_millis"
            ]
          }
        },
        "additionalProperties": false,
        "required": [
          "name",
          "uuid",
          "version",
          "status",
          "metrics"
        ]
      },
      "core.status.redactedResponse": {
        "description": "A minimal representation of Kibana's operational status.",
        "type": "object",
        "properties": {
          "status": {
            "type": "object",
            "properties": {
              "overall": {
                "type": "object",
                "properties": {
                  "level": {
                    "description": "Service status levels as human and machine readable values.",
                    "anyOf": [
                      {
                        "enum": [
                          "available"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "degraded"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "unavailable"
                        ],
                        "type": "string"
                      },
                      {
                        "enum": [
                          "critical"
                        ],
                        "type": "string"
                      }
                    ]
                  }
                },
                "additionalProperties": false,
                "required": [
                  "level"
                ]
              }
            },
            "additionalProperties": false,
            "required": [
              "overall"
            ]
          }
        },
        "additionalProperties": false,
        "required": [
          "status"
        ]
      }
    },
    "securitySchemes": {
      "basicAuth": {
        "type": "http",
        "scheme": "basic"
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization"
      }
    }
  },
  "security": [
    {
      "basicAuth": []
    }
  ]
}
```

</details>

Related to #181622

## Notes

* Tip from @lcawl : "If you want to see Bump previews of your files too,
I’ve been doing it via the preview command per
https://docs.bump.sh/help/continuous-integration/cli/#bump-preview-file"
@lcawl
Copy link
Contributor

lcawl commented May 22, 2024

Related to #181240 is there a method to mark an entire endpoint as deprecated? e.g. there are some deprecated endpoints in alerting and cases. Could we add a "deprecated" option in https://github.com/elastic/kibana/blob/main/packages/core/http/core-http-server/src/router/route.ts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Meta Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

No branches or pull requests

3 participants