Skip to content

[8.19] New artifacts schema in the rule creation/update/find (#216292)#218920

Merged
mgiota merged 6 commits intoelastic:8.19from
mgiota:backport/8.19/pr-216292
Apr 23, 2025
Merged

[8.19] New artifacts schema in the rule creation/update/find (#216292)#218920
mgiota merged 6 commits intoelastic:8.19from
mgiota:backport/8.19/pr-216292

Conversation

@mgiota
Copy link
Contributor

@mgiota mgiota commented Apr 23, 2025

Backport

This will backport the following commits from main to 8.19:

Questions ?

Please refer to the Backport tool documentation

@mgiota mgiota requested a review from kibanamachine as a code owner April 23, 2025 08:50
@mgiota mgiota added the backport This PR is a backport of another PR label Apr 23, 2025
@mgiota mgiota enabled auto-merge (squash) April 23, 2025 08:50
We want to add a new `root-level` key in the rule called `artifacts`.
The new key will be added to the `create`, `update` and `find` Rule apis
and will contain `dashboards` and `investigation_guide`. This PR handles
only the addition of dashboards.

```
artifacts: {
    dasboards: Array<{ id: string }]>;
}
```

<img width="1265" alt="Screenshot 2025-04-02 at 12 35 00"
src="https://github.com/user-attachments/assets/51783fd5-f63e-4a2e-80b0-7a724675c11c"
/>

This PR includes only backend changes to the Rule APIs. In order to test
you can use Kibana > Dev Tools.

```
POST kbn:/api/alerting/rule
{
  "name": "TEST RULE",
  "params": {
    "criteria": [
      {
        "comparator": ">",
        "metrics": [
          {
            "name": "A",
            "aggType": "count"
          }
        ],
        "threshold": [
          3
        ],
        "timeSize": 1,
        "timeUnit": "m"
      }
    ],
    "alertOnNoData": false,
    "alertOnGroupDisappear": false,
    "searchConfiguration": {
      "query": {
        "query": "",
        "language": "kuery"
      },
      "index": "e7744dbe-a7a4-457b-83aa-539e9c88764c"
    }
  },
  "rule_type_id": "observability.rules.custom_threshold",
  "consumer": "logs",
  "schedule": {
    "interval": "1m"
  },
  "artifacts": {
    "dashboards": [
      { "id":"1" }
    ]
  }
}
```
The artifacts shouldn't be returned in the rule response. The new
dashboard artifacts should be saved in the Rules SO. You can check it
directly under `Kibana > Stack Management > Saved Objects`. You should
verify a new `artifacts` entry is added in the rules SO:

```
"artifacts": {
      "dashboards": [
        {
          "refId": "dashboard_0"
        }
      ]
    },
```

Also the new dashboard should be added into the references array:

```
"references": [
    ..
    {
      "id": "1",
      "name": "dashboard_0",
      "type": "dashboard"
    }
  ],
```

```
PUT kbn:/api/alerting/rule/{RULE_ID}
{
  "name": "TEST RULE",
  "schedule": {
    "interval": "1m"
  },
  "params": {
    "criteria": [
      {
        "comparator": ">",
        "metrics": [
          {
            "name": "A",
            "aggType": "count"
          }
        ],
        "threshold": [
          3
        ],
        "timeSize": 1,
        "timeUnit": "m"
      }
    ],
    "alertOnNoData": false,
    "alertOnGroupDisappear": false,
    "searchConfiguration": {
      "query": {
        "query": "",
        "language": "kuery"
      },
      "index": "e7744dbe-a7a4-457b-83aa-539e9c88764c"
    }
  },
  "artifacts": {
    "dashboards": [{"id": "2"}, {"id": "1"}]
  }
}
```
The artifacts shouldn't be returned in the rule response. The updated
artifacts should be saved in the Rules SO. You can check it directly
under `Kibana > Stack Management > Saved Objects`. You should verify the
updated dashboards list is correct.

```
GET kbn:/api/alerting/rules/_find?search="TEST RULE"

```

The artifacts shouldn't be returned in the rule response. Only the
internal Find API returns the artifacts.

```
POST kbn:/internal/alerting/rules/_find
{
  "search": "TEST RULE"
}
```

- The dashboard IDs should be saved as `references in the Rule SO
- The Rule APIs will not return the artifacts
- Only the `internal Find API` used by the UI will return the artifacts
- Integrations and unit tests should be added

---------

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Justin Kambic <jk@elastic.co>
Co-authored-by: Christos Nasikas <xristosnasikas@gmail.com>
(cherry picked from commit 09740a6)
@mgiota mgiota force-pushed the backport/8.19/pr-216292 branch from debe87b to f203d03 Compare April 23, 2025 09:01
@mgiota mgiota self-assigned this Apr 23, 2025
@cnasikas cnasikas disabled auto-merge April 23, 2025 13:27
@mgiota mgiota force-pushed the backport/8.19/pr-216292 branch from 54001ad to e2aaa36 Compare April 23, 2025 16:35
@mgiota mgiota enabled auto-merge (squash) April 23, 2025 19:19
@mgiota
Copy link
Contributor Author

mgiota commented Apr 23, 2025

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

There are no new commits on the base branch.

@mgiota mgiota added backport This PR is a backport of another PR and removed backport This PR is a backport of another PR labels Apr 23, 2025
@mgiota mgiota merged commit 8331254 into elastic:8.19 Apr 23, 2025
8 checks passed
@elasticmachine
Copy link
Contributor

💚 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/alerting-types 250 255 +5
alerting 854 858 +4
total +9
Unknown metric groups

API count

id before after diff
@kbn/alerting-types 254 259 +5
alerting 888 892 +4
total +9

History

cc @mgiota

@mgiota mgiota deleted the backport/8.19/pr-216292 branch October 1, 2025 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants