kibana/oas_docs/overlays/alerting.overlays.yaml
Jean-Louis Leysens 5e90e557cf
[OAS] Support examples (and more) (#212495)
## Summary

Close https://github.com/elastic/kibana/issues/188926

Adds the ability to merge in an arbitrary OAS operation object (search
[spec](https://swagger.io/specification/) for "operation object") in
code generated OAS.

This enables us to write examples next to the code:

<img width="306" alt="Screenshot 2025-02-26 at 11 24 00"
src="https://github.com/user-attachments/assets/5df92ae9-c8c5-4797-8b7c-764e937e84e9"
/>

```ts
// Inside the router declaration
  router.post(
    {
      path: `${BASE_ALERTING_API_PATH}/rule/{id?}`,
      security: DEFAULT_ALERTING_ROUTE_SECURITY,
      options: {
        access: 'public',
        summary: `Create a rule`,
        tags: ['oas-tag:alerting'],
        // NEW 👇🏻: this file can contain operation-level OAS and will merge/override anything that we auto generate
        oasOperationObject: () => path.join(__dirname, 'create_rule.examples.yaml'),
        // ☝🏻 can also be a TS-checked OpenAPIV3.OperationObject
```

Tested with create rule example overlay
([gist](https://gist.github.com/jloleysens/dc643522a3f58dc2aed3dcef966b42df))
and bump

<img width="1236" alt="Screenshot 2025-02-26 at 11 45 57"
src="https://github.com/user-attachments/assets/c21b466a-ddab-49ce-b4ba-a04fd0e6c1b7"
/>

## Docs

Added developer guide docs to
https://docs.elastic.dev/kibana-dev-docs/genereating-oas-for-http-apis#2-route-definitions

<details>

<summary>images</summary>

<img width="799" alt="Screenshot 2025-03-13 at 13 02 31"
src="https://github.com/user-attachments/assets/e89b2c5a-1984-4672-a40b-b492581e690f"
/>

<img width="819" alt="Screenshot 2025-03-13 at 13 02 39"
src="https://github.com/user-attachments/assets/1375a25a-4d91-46b4-8ce5-42c763657d96"
/>

</details>




### TO DO
- [x] Document the feature in TS
- [x] Document feature in dev docs
- [x] Add tests

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-03-14 14:56:28 +01:00

88 lines
6.3 KiB
YAML

# overlays.yaml
overlay: 1.0.0
info:
title: Overlays for the alerting rule examples and parameters
version: 0.0.1
actions:
# Fix some optional path parameters
- target: "$.paths['/api/alerting/rule/{id}']['post'].parameters[?(@.name=='id')]"
description: Remove optional indicator from path parameter
update:
required: true
# Remove the alerting rule parameters
- target: "$.paths['/api/alerting/rule/{id}']['post'].requestBody.content.*.schema.properties.params"
description: "Remove params type in create rule API"
remove: true
# Add some alerting rule parameters
- target: "$.paths['/api/alerting/rule/{id}']['post']"
description: "Add params to create rule API"
update:
requestBody:
content:
application/json:
schema:
properties:
params:
additionalProperties: {}
default: {}
description: The parameters for the rule.
anyOf:
# APM anomaly rule (apm.anomaly)
- $ref: '../../x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/docs/params_property_apm_anomaly.yaml'
# APM error count rule (apm.error_rate)
- $ref: '../../x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/docs/params_property_apm_error_count.yaml'
# APM transaction duration rule (apm.transaction_duration)
- $ref: '../../x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/docs/params_property_apm_transaction_duration.yaml'
# APM transaction error rate rule (apm.transaction_error_rate)
- $ref: '../../x-pack/solutions/observability/plugins/apm/server/routes/alerts/rule_types/docs/params_property_apm_transaction_error_rate.yaml'
# Elasticsearch DSL query rule (.es-query)
- $ref: '../../x-pack/platform/plugins/shared/alerting/docs/openapi/components/schemas/params_es_query_dsl_rule.yaml'
# Elasticsearch ES|QL query rule (.es-query)
- $ref: '../../x-pack/platform/plugins/shared/alerting/docs/openapi/components/schemas/params_es_query_esql_rule.yaml'
# Elasticsearch KQL query rule (.es-query)
- $ref: '../../x-pack/platform/plugins/shared/alerting/docs/openapi/components/schemas/params_es_query_kql_rule.yaml'
# Index threshold rule ()
- $ref: '../../x-pack/platform/plugins/shared/alerting/docs/openapi/components/schemas/params_index_threshold_rule.yaml'
# Infra inventory rule (metrics.alert.inventory.threshold)
- $ref: '../../x-pack/solutions/observability/plugins/infra/server/lib/alerting/docs/params_property_infra_inventory.yaml'
# Log threshold rule (logs.alert.document.count)
- $ref: '../../x-pack/solutions/observability/plugins/infra/server/lib/alerting/docs/params_property_log_threshold.yaml'
# Infra metric threshold rule (metrics.alert.threshold)
- $ref: '../../x-pack/solutions/observability/plugins/infra/server/lib/alerting/docs/params_property_infra_metric_threshold.yaml'
# SLO burn rate (slo.rules.burnRate)
- $ref: '../../x-pack/solutions/observability/plugins/slo/server/lib/rules/slo_burn_rate/docs/params_property_slo_burn_rate.yaml'
# Synthetics uptime TLS rule (xpack.uptime.alerts.tls)
- $ref: '../../x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/docs/params_property_synthetics_uptime_tls.yaml'
# Uptime monitor status rule (xpack.uptime.alerts.monitorStatus)
- $ref: '../../x-pack/solutions/observability/plugins/uptime/server/legacy_uptime/lib/alerts/docs/params_property_synthetics_monitor_status.yaml'
# TBD
# Anomaly detection alert rule (xpack.ml.anomaly_detection_alert)
# Anomaly detection jobs health rule (xpack.ml.anomaly_detection_jobs_health)
# Tracking containment rule (.geo-containment)
# Infrastructure anomaly rule (metrics.alert.anomaly)
# CCR read exceptions rule (monitoring_ccr_read_exceptions)
# Cluster health rule (monitoring_alert_cluster_health)
# CPU usage rule (monitoring_alert_cpu_usage)
# Custom query rule (siem.queryRule)
# Disk usage rule (monitoring_alert_disk_usage)
# Elasticsearch version mismatch rule (monitoring_alert_elasticsearch_version_mismatch)
# Event correlation rule (siem.eqlRule)
# Indicator match rule (siem.indicatorRule)
# JVM memory usage rule (monitoring_alert_jvm_memory_usage)
# Kibana version mismatch rule ( monitoring_alert_kibana_version_mismatch)
# License expiration rule (monitoring_alert_license_expiration)
# Logstash version mismatch rule (monitoring_alert_logstash_version_mismatch)
# Machine learning rule (siem.mlRule)
# Missing monitoring data rule (monitoring_alert_missing_monitoring_data)
# New terms rule (siem.newTermsRule)
# Nodes changed rule (monitoring_alert_nodes_changed)
# Saved query rule (siem.savedQueryRule)
# Security solution notification (legacy) rule (siem.notifications)
# Shard size rule (monitoring_shard_size)
# Synthetics monitor status rule (xpack.synthetics.alerts.monitorStatus)
# Synthetics uptime duration anomaly rule (xpack.uptime.alerts.durationAnomaly)
# Thread pool search rejections rule (monitoring_alert_thread_pool_search_rejections)
# Thread pool write rejections rule (monitoring_alert_thread_pool_write_rejections)
# Threshold rule (siem.thresholdRule)
# TLS certificate rule (xpack.uptime.alerts.tlsCertificate)
# Transform health (transform_health)