Auto increase fields limit of the alert indices#216719
Auto increase fields limit of the alert indices#216719ersin-erdal merged 33 commits intoelastic:mainfrom
Conversation
…al/kibana into 283-auto-increase-fields-limit
…al/kibana into 283-auto-increase-fields-limit
|
Pinging @elastic/response-ops (Team:ResponseOps) |
ymao1
left a comment
There was a problem hiding this comment.
Verified works as described 🎉 . Left a few comments
| import type { ElasticsearchClient } from '@kbn/core/server'; | ||
| import type { IndicesGetIndexTemplateIndexTemplateItem } from '@elastic/elasticsearch/lib/api/types'; | ||
|
|
||
| export const updateIndexTemplateFiledsLimit = ({ |
There was a problem hiding this comment.
| export const updateIndexTemplateFiledsLimit = ({ | |
| export const updateIndexTemplateFieldsLimit = ({ |
There was a problem hiding this comment.
Can we update the filename as well?
| return; | ||
| } catch (err) { | ||
| try { | ||
| const newLimit = await increaseFiledsLimit({ |
There was a problem hiding this comment.
| const newLimit = await increaseFiledsLimit({ | |
| const newLimit = await increaseFieldsLimit({ |
...ck/platform/plugins/shared/alerting/server/alerts_service/lib/create_concrete_write_index.ts
Show resolved
Hide resolved
| { logger } | ||
| ); | ||
| logger.info( | ||
| `total_fields.limit of ${alias} has been increased form ${exceededLimit} to ${newLimit}` |
There was a problem hiding this comment.
| `total_fields.limit of ${alias} has been increased form ${exceededLimit} to ${newLimit}` | |
| `total_fields.limit of ${alias} has been increased from ${exceededLimit} to ${newLimit}` |
...ck/platform/plugins/shared/alerting/server/alerts_service/lib/create_concrete_write_index.ts
Show resolved
Hide resolved
...ck/platform/plugins/shared/alerting/server/alerts_service/lib/create_concrete_write_index.ts
Show resolved
Hide resolved
| } | ||
| } catch (e) { | ||
| logger.error( | ||
| `An error occured while incresing total_fields.limit of ${alias} - ${e.message}`, |
There was a problem hiding this comment.
| `An error occured while incresing total_fields.limit of ${alias} - ${e.message}`, | |
| `An error occured while increasing total_fields.limit of ${alias} - ${e.message}`, |
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
) # Backport This will backport the following commits from `main` to `9.0`: - [Auto increase fields limit of the alert indices (#216719)](#216719) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-15T07:38:27Z","message":"Auto increase fields limit of the alert indices (#216719)\n\nThis PR adds the auto-increase the fields limit on startup when an\nalerts index reaches its limits because of the dynamic fields.\n\n# To verify:\nTo be able to test this PR we need a rule type that adds dynamic fields.\nI used the custom threshold rule for this:\n\nGo to the custom threshold rule type definition and change its\nalerts.mappings to:\n```\n mappings: {\n // dynamic: true,\n fieldMap: {\n 'kibana.alerting.grouping': {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n ...legacyExperimentalFieldMap,\n ...Array(412)\n .fill(0)\n .reduce((acc, val, i) => {\n acc[`${i + 1}`] = { type: 'keyword', array: false, required: false };\n return acc;\n }, {}),\n },\n dynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n },\n ```\n \n Above changes adds 412 dummy fields to the alerts index to make it close to reach its fields limit (default: 2500).\n And makes everything under `kibana.alert.grouping` path to be added to the index as dynamic fields.\n \n Then apply the below changes to the custom threshold rule executor:\n ```\n const grouping: Record<string, string> = {};\n groups?.forEach((groupObj) => (grouping[groupObj.field] = groupObj.value));\n \n const { uuid, start } = alertsClient.report({\n id: `${group}`,\n actionGroup: actionGroupId,\n payload: {\n [ALERT_REASON]: reason,\n [ALERT_EVALUATION_VALUES]: evaluationValues,\n [ALERT_EVALUATION_THRESHOLD]: threshold,\n [ALERT_GROUP]: groups,\n // @ts-ignore\n ['kibana.alerting.grouping']: grouping,\n ...flattenAdditionalContext(additionalContext),\n ...getEcsGroups(groups),\n },\n }); \n ```\n \nAbove changes add the selected groups under `kibana.alerting.grouping` path.\n \nThen: \n- Run ES with ` path.data=../your-local-data-path` to keep the data for the next start.\n- Run Kibana\n- Create a custom threshold rule that generates an alert and has at least 2 groups.\n- Let the rule run.\n- Go to `Stack Management` > `Index Management` and search for observability threshold index.\n- Check its mappings, it should show the dummy fields you have added to the rule type and the first grouping you have selected while you were creating the rule type.\n- Go to the Dev Tools and find your alert in the `.internal.alerts-observability.threshold.alerts-default-000001` index.\nThe other groups you have selected should be saved under `_ignored` field:\n```\n\"_ignored\": [\n \"kibana.alerting.grouping.host.name\"\n],\n```\n- Stop Kibana\n- increase the number of dummy fields you have added to the rule type definition:\n```\n ...Array(412) <-- make this greater than 412\n .fill(0)\n```\n- Start kibana again.\n- The new fields should be added to the mappings. Check them on `Stack Management` > `Index Management` \n- Check also the index settings: `Stack Management` > `Index Management` > `.internal.alerts-observability.threshold.alerts-default-000001` > settings tab.\n- `\"mapping\" > \"total_fields\" > \"limit\" ` should be greater than 2500\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"f6c30d6b9ad1a46a73cc5c084a5e70051d78a7cb","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:version","v9.1.0","v8.19.0"],"title":"Auto increase fields limit of the alert indices","number":216719,"url":"https://github.com/elastic/kibana/pull/216719","mergeCommit":{"message":"Auto increase fields limit of the alert indices (#216719)\n\nThis PR adds the auto-increase the fields limit on startup when an\nalerts index reaches its limits because of the dynamic fields.\n\n# To verify:\nTo be able to test this PR we need a rule type that adds dynamic fields.\nI used the custom threshold rule for this:\n\nGo to the custom threshold rule type definition and change its\nalerts.mappings to:\n```\n mappings: {\n // dynamic: true,\n fieldMap: {\n 'kibana.alerting.grouping': {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n ...legacyExperimentalFieldMap,\n ...Array(412)\n .fill(0)\n .reduce((acc, val, i) => {\n acc[`${i + 1}`] = { type: 'keyword', array: false, required: false };\n return acc;\n }, {}),\n },\n dynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n },\n ```\n \n Above changes adds 412 dummy fields to the alerts index to make it close to reach its fields limit (default: 2500).\n And makes everything under `kibana.alert.grouping` path to be added to the index as dynamic fields.\n \n Then apply the below changes to the custom threshold rule executor:\n ```\n const grouping: Record<string, string> = {};\n groups?.forEach((groupObj) => (grouping[groupObj.field] = groupObj.value));\n \n const { uuid, start } = alertsClient.report({\n id: `${group}`,\n actionGroup: actionGroupId,\n payload: {\n [ALERT_REASON]: reason,\n [ALERT_EVALUATION_VALUES]: evaluationValues,\n [ALERT_EVALUATION_THRESHOLD]: threshold,\n [ALERT_GROUP]: groups,\n // @ts-ignore\n ['kibana.alerting.grouping']: grouping,\n ...flattenAdditionalContext(additionalContext),\n ...getEcsGroups(groups),\n },\n }); \n ```\n \nAbove changes add the selected groups under `kibana.alerting.grouping` path.\n \nThen: \n- Run ES with ` path.data=../your-local-data-path` to keep the data for the next start.\n- Run Kibana\n- Create a custom threshold rule that generates an alert and has at least 2 groups.\n- Let the rule run.\n- Go to `Stack Management` > `Index Management` and search for observability threshold index.\n- Check its mappings, it should show the dummy fields you have added to the rule type and the first grouping you have selected while you were creating the rule type.\n- Go to the Dev Tools and find your alert in the `.internal.alerts-observability.threshold.alerts-default-000001` index.\nThe other groups you have selected should be saved under `_ignored` field:\n```\n\"_ignored\": [\n \"kibana.alerting.grouping.host.name\"\n],\n```\n- Stop Kibana\n- increase the number of dummy fields you have added to the rule type definition:\n```\n ...Array(412) <-- make this greater than 412\n .fill(0)\n```\n- Start kibana again.\n- The new fields should be added to the mappings. Check them on `Stack Management` > `Index Management` \n- Check also the index settings: `Stack Management` > `Index Management` > `.internal.alerts-observability.threshold.alerts-default-000001` > settings tab.\n- `\"mapping\" > \"total_fields\" > \"limit\" ` should be greater than 2500\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"f6c30d6b9ad1a46a73cc5c084a5e70051d78a7cb"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216719","number":216719,"mergeCommit":{"message":"Auto increase fields limit of the alert indices (#216719)\n\nThis PR adds the auto-increase the fields limit on startup when an\nalerts index reaches its limits because of the dynamic fields.\n\n# To verify:\nTo be able to test this PR we need a rule type that adds dynamic fields.\nI used the custom threshold rule for this:\n\nGo to the custom threshold rule type definition and change its\nalerts.mappings to:\n```\n mappings: {\n // dynamic: true,\n fieldMap: {\n 'kibana.alerting.grouping': {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n ...legacyExperimentalFieldMap,\n ...Array(412)\n .fill(0)\n .reduce((acc, val, i) => {\n acc[`${i + 1}`] = { type: 'keyword', array: false, required: false };\n return acc;\n }, {}),\n },\n dynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n },\n ```\n \n Above changes adds 412 dummy fields to the alerts index to make it close to reach its fields limit (default: 2500).\n And makes everything under `kibana.alert.grouping` path to be added to the index as dynamic fields.\n \n Then apply the below changes to the custom threshold rule executor:\n ```\n const grouping: Record<string, string> = {};\n groups?.forEach((groupObj) => (grouping[groupObj.field] = groupObj.value));\n \n const { uuid, start } = alertsClient.report({\n id: `${group}`,\n actionGroup: actionGroupId,\n payload: {\n [ALERT_REASON]: reason,\n [ALERT_EVALUATION_VALUES]: evaluationValues,\n [ALERT_EVALUATION_THRESHOLD]: threshold,\n [ALERT_GROUP]: groups,\n // @ts-ignore\n ['kibana.alerting.grouping']: grouping,\n ...flattenAdditionalContext(additionalContext),\n ...getEcsGroups(groups),\n },\n }); \n ```\n \nAbove changes add the selected groups under `kibana.alerting.grouping` path.\n \nThen: \n- Run ES with ` path.data=../your-local-data-path` to keep the data for the next start.\n- Run Kibana\n- Create a custom threshold rule that generates an alert and has at least 2 groups.\n- Let the rule run.\n- Go to `Stack Management` > `Index Management` and search for observability threshold index.\n- Check its mappings, it should show the dummy fields you have added to the rule type and the first grouping you have selected while you were creating the rule type.\n- Go to the Dev Tools and find your alert in the `.internal.alerts-observability.threshold.alerts-default-000001` index.\nThe other groups you have selected should be saved under `_ignored` field:\n```\n\"_ignored\": [\n \"kibana.alerting.grouping.host.name\"\n],\n```\n- Stop Kibana\n- increase the number of dummy fields you have added to the rule type definition:\n```\n ...Array(412) <-- make this greater than 412\n .fill(0)\n```\n- Start kibana again.\n- The new fields should be added to the mappings. Check them on `Stack Management` > `Index Management` \n- Check also the index settings: `Stack Management` > `Index Management` > `.internal.alerts-observability.threshold.alerts-default-000001` > settings tab.\n- `\"mapping\" > \"total_fields\" > \"limit\" ` should be greater than 2500\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"f6c30d6b9ad1a46a73cc5c084a5e70051d78a7cb"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
|
Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync. |
|
Note that the backport to |
This PR fixes the bug introduced with: #216719 We didn't pass the dynamic_templates param while creating the component template. The fields were still being added because the fields were marked as `dynamic: true` As the dynamic_template was ignored, the fields were added with an extra mapping like `filedname.keyword` This PR fixes that too. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR fixes the bug introduced with: elastic#216719 We didn't pass the dynamic_templates param while creating the component template. The fields were still being added because the fields were marked as `dynamic: true` As the dynamic_template was ignored, the fields were added with an extra mapping like `filedname.keyword` This PR fixes that too. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 8c6c928)
This PR fixes the bug introduced with: elastic#216719 We didn't pass the dynamic_templates param while creating the component template. The fields were still being added because the fields were marked as `dynamic: true` As the dynamic_template was ignored, the fields were added with an extra mapping like `filedname.keyword` This PR fixes that too. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 8c6c928)
# Backport This will backport the following commits from `main` to `9.0`: - [Fix ignored dynamic templates (#219875)](#219875) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-02T08:28:56Z","message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","backport:version","v9.1.0","v8.19.0","v9.0.1","v9.0.2"],"title":"Fix ignored dynamic templates","number":219875,"url":"https://github.com/elastic/kibana/pull/219875","mergeCommit":{"message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.19"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219875","number":219875,"mergeCommit":{"message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com> Co-authored-by: Ersin Erdal <ersin.erdal@elastic.co>
# Backport This will backport the following commits from `main` to `8.19`: - [Fix ignored dynamic templates (#219875)](#219875) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Ersin Erdal","email":"92688503+ersin-erdal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-05-02T08:28:56Z","message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","v9.0.0","backport:version","v9.1.0","v8.19.0","v9.0.1","v9.0.2"],"title":"Fix ignored dynamic templates","number":219875,"url":"https://github.com/elastic/kibana/pull/219875","mergeCommit":{"message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.19"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219875","number":219875,"mergeCommit":{"message":"Fix ignored dynamic templates (#219875)\n\nThis PR fixes the bug introduced with:\nhttps://github.com//pull/216719\n\nWe didn't pass the dynamic_templates param while creating the component\ntemplate.\nThe fields were still being added because the fields were marked as\n`dynamic: true`\n\nAs the dynamic_template was ignored, the fields were added with an extra\nmapping like `filedname.keyword`\nThis PR fixes that too.\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"8c6c928e7cde2233da4145c6e712785acf54c5f9"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: Ersin Erdal <92688503+ersin-erdal@users.noreply.github.com> Co-authored-by: Ersin Erdal <ersin.erdal@elastic.co>
…19826) Relaetd to #183248 Auto-increasing mapping limit PR: #216719 ## Summary In this PR, we are saving dynamically mapped group by information for the custom threshold rule. This consists of two parts: 1. Adding a dynamic field ``` // kibana.alert.grouping [ALERT_GROUPING]: { type: 'object', dynamic: true, array: false, required: false, }, ``` 2. Adding a dynamic template ``` dynamicTemplates: [ { strings_as_keywords: { path_match: 'kibana.alert.grouping.*', match_mapping_type: 'string', mapping: { type: 'keyword', ignore_above: 1024, }, }, }, ], ``` The result of adding these mappings can be seen below: |Alert|Mapping| |---|---| ||| If the number of mapping limit is exceeded, the fields that are not mapped are going to be added to the `_ignored` field, but the value is available in the doc. <img src="https://github.com/user-attachments/assets/b84bcf03-b757-4f37-a93f-2559aefa5bcf" width=500 />
…ing (#219826) (#221476) # Backport This will backport the following commits from `main` to `8.19`: - [[Custom threshold] Save group by information with dynamic mapping (#219826)](#219826) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maryam Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2025-05-24T13:17:43Z","message":"[Custom threshold] Save group by information with dynamic mapping (#219826)\n\nRelaetd to #183248 \nAuto-increasing mapping limit PR:\nhttps://github.com//pull/216719\n\n## Summary\n\nIn this PR, we are saving dynamically mapped group by information for\nthe custom threshold rule. This consists of two parts:\n\n1. Adding a dynamic field\n```\n// kibana.alert.grouping\n[ALERT_GROUPING]: {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n```\n2. Adding a dynamic template\n```\ndynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n```\n\nThe result of adding these mappings can be seen below:\n|Alert|Mapping|\n|---|---|\n\n|||\n\nIf the number of mapping limit is exceeded, the fields that are not\nmapped are going to be added to the `_ignored` field, but the value is\navailable in the doc.\n\n<img\nsrc=\"https://github.com/user-attachments/assets/b84bcf03-b757-4f37-a93f-2559aefa5bcf\"\nwidth=500 />","sha":"1ec32967f857f6e6e2b9f45f4da5751997254e4e","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:feature","Team:obs-ux-management","backport:version","v9.1.0","v8.19.0","author:obs-ux-management"],"title":"[Custom threshold] Save group by information with dynamic mapping","number":219826,"url":"https://github.com/elastic/kibana/pull/219826","mergeCommit":{"message":"[Custom threshold] Save group by information with dynamic mapping (#219826)\n\nRelaetd to #183248 \nAuto-increasing mapping limit PR:\nhttps://github.com//pull/216719\n\n## Summary\n\nIn this PR, we are saving dynamically mapped group by information for\nthe custom threshold rule. This consists of two parts:\n\n1. Adding a dynamic field\n```\n// kibana.alert.grouping\n[ALERT_GROUPING]: {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n```\n2. Adding a dynamic template\n```\ndynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n```\n\nThe result of adding these mappings can be seen below:\n|Alert|Mapping|\n|---|---|\n\n|||\n\nIf the number of mapping limit is exceeded, the fields that are not\nmapped are going to be added to the `_ignored` field, but the value is\navailable in the doc.\n\n<img\nsrc=\"https://github.com/user-attachments/assets/b84bcf03-b757-4f37-a93f-2559aefa5bcf\"\nwidth=500 />","sha":"1ec32967f857f6e6e2b9f45f4da5751997254e4e"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/219826","number":219826,"mergeCommit":{"message":"[Custom threshold] Save group by information with dynamic mapping (#219826)\n\nRelaetd to #183248 \nAuto-increasing mapping limit PR:\nhttps://github.com//pull/216719\n\n## Summary\n\nIn this PR, we are saving dynamically mapped group by information for\nthe custom threshold rule. This consists of two parts:\n\n1. Adding a dynamic field\n```\n// kibana.alert.grouping\n[ALERT_GROUPING]: {\n type: 'object',\n dynamic: true,\n array: false,\n required: false,\n },\n```\n2. Adding a dynamic template\n```\ndynamicTemplates: [\n {\n strings_as_keywords: {\n path_match: 'kibana.alert.grouping.*',\n match_mapping_type: 'string',\n mapping: {\n type: 'keyword',\n ignore_above: 1024,\n },\n },\n },\n ],\n```\n\nThe result of adding these mappings can be seen below:\n|Alert|Mapping|\n|---|---|\n\n|||\n\nIf the number of mapping limit is exceeded, the fields that are not\nmapped are going to be added to the `_ignored` field, but the value is\navailable in the doc.\n\n<img\nsrc=\"https://github.com/user-attachments/assets/b84bcf03-b757-4f37-a93f-2559aefa5bcf\"\nwidth=500 />","sha":"1ec32967f857f6e6e2b9f45f4da5751997254e4e"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Closes #220815 ## Summary This PR adds telemetry for _ignored fields. The goal is to have an alert based on this field and get notified in case a user hits the mapping limit, but by default, we don't expect this to happen. This PR adds `count_ignored_fields_by_rule_type` field that counts the number of _ignored fields per rule type. In the future, we can extend the telemetry data to also include the actual number of mappings over the limit (there is a [feature request](elastic/elasticsearch#68947) for adding field count information to index API) ### How to test - Add a lot of dynamic fields as mentioned here: #216719 - Create a rule with a custom threshold rule with multiple group by fields to generate an alert with _ignored field - Run the following API and check the value of `count_ignored_fields_by_rule_type` ``` POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2 { "unencrypted": true, "refreshCache": true } ``` <details> <summary> Here is what it looks like:</summary>   </details> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR fixes the bug introduced with: elastic#216719 We didn't pass the dynamic_templates param while creating the component template. The fields were still being added because the fields were marked as `dynamic: true` As the dynamic_template was ignored, the fields were added with an extra mapping like `filedname.keyword` This PR fixes that too. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
…astic#219826) Relaetd to elastic#183248 Auto-increasing mapping limit PR: elastic#216719 ## Summary In this PR, we are saving dynamically mapped group by information for the custom threshold rule. This consists of two parts: 1. Adding a dynamic field ``` // kibana.alert.grouping [ALERT_GROUPING]: { type: 'object', dynamic: true, array: false, required: false, }, ``` 2. Adding a dynamic template ``` dynamicTemplates: [ { strings_as_keywords: { path_match: 'kibana.alert.grouping.*', match_mapping_type: 'string', mapping: { type: 'keyword', ignore_above: 1024, }, }, }, ], ``` The result of adding these mappings can be seen below: |Alert|Mapping| |---|---| ||| If the number of mapping limit is exceeded, the fields that are not mapped are going to be added to the `_ignored` field, but the value is available in the doc. <img src="https://github.com/user-attachments/assets/b84bcf03-b757-4f37-a93f-2559aefa5bcf" width=500 />
Closes elastic#220815 ## Summary This PR adds telemetry for _ignored fields. The goal is to have an alert based on this field and get notified in case a user hits the mapping limit, but by default, we don't expect this to happen. This PR adds `count_ignored_fields_by_rule_type` field that counts the number of _ignored fields per rule type. In the future, we can extend the telemetry data to also include the actual number of mappings over the limit (there is a [feature request](elastic/elasticsearch#68947) for adding field count information to index API) ### How to test - Add a lot of dynamic fields as mentioned here: elastic#216719 - Create a rule with a custom threshold rule with multiple group by fields to generate an alert with _ignored field - Run the following API and check the value of `count_ignored_fields_by_rule_type` ``` POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2 { "unencrypted": true, "refreshCache": true } ``` <details> <summary> Here is what it looks like:</summary>   </details> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Closes elastic#220815 ## Summary This PR adds telemetry for _ignored fields. The goal is to have an alert based on this field and get notified in case a user hits the mapping limit, but by default, we don't expect this to happen. This PR adds `count_ignored_fields_by_rule_type` field that counts the number of _ignored fields per rule type. In the future, we can extend the telemetry data to also include the actual number of mappings over the limit (there is a [feature request](elastic/elasticsearch#68947) for adding field count information to index API) ### How to test - Add a lot of dynamic fields as mentioned here: elastic#216719 - Create a rule with a custom threshold rule with multiple group by fields to generate an alert with _ignored field - Run the following API and check the value of `count_ignored_fields_by_rule_type` ``` POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2 { "unencrypted": true, "refreshCache": true } ``` <details> <summary> Here is what it looks like:</summary>   </details> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit cde7a86) # Conflicts: # x-pack/platform/plugins/shared/alerting/server/usage/lib/get_telemetry_from_alerts.test.ts
#222150) # Backport This will backport the following commits from `main` to `8.19`: - [[Alerting] Add snapshot telemetry for _ignored fields (#221480)](#221480) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Maryam Saeidi","email":"maryam.saeidi@elastic.co"},"sourceCommit":{"committedDate":"2025-05-28T16:02:33Z","message":"[Alerting] Add snapshot telemetry for _ignored fields (#221480)\n\nCloses https://github.com/elastic/kibana/issues/220815\n\n## Summary\n\nThis PR adds telemetry for _ignored fields. The goal is to have an alert\nbased on this field and get notified in case a user hits the mapping\nlimit, but by default, we don't expect this to happen.\n\nThis PR adds `count_ignored_fields_by_rule_type` field that counts the\nnumber of _ignored fields per rule type.\n\nIn the future, we can extend the telemetry data to also include the\nactual number of mappings over the limit (there is a [feature\nrequest](elastic/elasticsearch#68947) for\nadding field count information to index API)\n\n### How to test\n\n- Add a lot of dynamic fields as mentioned here:\nhttps://github.com//pull/216719\n- Create a rule with a custom threshold rule with multiple group by\nfields to generate an alert with _ignored field\n- Run the following API and check the value of\n`count_ignored_fields_by_rule_type`\n ```\n POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2\n {\n \"unencrypted\": true,\n \"refreshCache\": true\n }\n ```\n\n<details>\n<summary> Here is what it looks like:</summary>\n\n\n\n\n\n\n\n\n</details>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"cde7a86287956467fffe4346a14a7fd24b99ff93","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport missing","backport:version","v9.1.0","v8.19.0","author:obs-ux-management"],"title":"[Alerting] Add snapshot telemetry for _ignored fields","number":221480,"url":"https://github.com/elastic/kibana/pull/221480","mergeCommit":{"message":"[Alerting] Add snapshot telemetry for _ignored fields (#221480)\n\nCloses https://github.com/elastic/kibana/issues/220815\n\n## Summary\n\nThis PR adds telemetry for _ignored fields. The goal is to have an alert\nbased on this field and get notified in case a user hits the mapping\nlimit, but by default, we don't expect this to happen.\n\nThis PR adds `count_ignored_fields_by_rule_type` field that counts the\nnumber of _ignored fields per rule type.\n\nIn the future, we can extend the telemetry data to also include the\nactual number of mappings over the limit (there is a [feature\nrequest](elastic/elasticsearch#68947) for\nadding field count information to index API)\n\n### How to test\n\n- Add a lot of dynamic fields as mentioned here:\nhttps://github.com//pull/216719\n- Create a rule with a custom threshold rule with multiple group by\nfields to generate an alert with _ignored field\n- Run the following API and check the value of\n`count_ignored_fields_by_rule_type`\n ```\n POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2\n {\n \"unencrypted\": true,\n \"refreshCache\": true\n }\n ```\n\n<details>\n<summary> Here is what it looks like:</summary>\n\n\n\n\n\n\n\n\n</details>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"cde7a86287956467fffe4346a14a7fd24b99ff93"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/221480","number":221480,"mergeCommit":{"message":"[Alerting] Add snapshot telemetry for _ignored fields (#221480)\n\nCloses https://github.com/elastic/kibana/issues/220815\n\n## Summary\n\nThis PR adds telemetry for _ignored fields. The goal is to have an alert\nbased on this field and get notified in case a user hits the mapping\nlimit, but by default, we don't expect this to happen.\n\nThis PR adds `count_ignored_fields_by_rule_type` field that counts the\nnumber of _ignored fields per rule type.\n\nIn the future, we can extend the telemetry data to also include the\nactual number of mappings over the limit (there is a [feature\nrequest](elastic/elasticsearch#68947) for\nadding field count information to index API)\n\n### How to test\n\n- Add a lot of dynamic fields as mentioned here:\nhttps://github.com//pull/216719\n- Create a rule with a custom threshold rule with multiple group by\nfields to generate an alert with _ignored field\n- Run the following API and check the value of\n`count_ignored_fields_by_rule_type`\n ```\n POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2\n {\n \"unencrypted\": true,\n \"refreshCache\": true\n }\n ```\n\n<details>\n<summary> Here is what it looks like:</summary>\n\n\n\n\n\n\n\n\n</details>\n\n---------\n\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"cde7a86287956467fffe4346a14a7fd24b99ff93"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT-->
This PR fixes the bug introduced with: elastic#216719 We didn't pass the dynamic_templates param while creating the component template. The fields were still being added because the fields were marked as `dynamic: true` As the dynamic_template was ignored, the fields were added with an extra mapping like `filedname.keyword` This PR fixes that too. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Closes elastic#220815 ## Summary This PR adds telemetry for _ignored fields. The goal is to have an alert based on this field and get notified in case a user hits the mapping limit, but by default, we don't expect this to happen. This PR adds `count_ignored_fields_by_rule_type` field that counts the number of _ignored fields per rule type. In the future, we can extend the telemetry data to also include the actual number of mappings over the limit (there is a [feature request](elastic/elasticsearch#68947) for adding field count information to index API) ### How to test - Add a lot of dynamic fields as mentioned here: elastic#216719 - Create a rule with a custom threshold rule with multiple group by fields to generate an alert with _ignored field - Run the following API and check the value of `count_ignored_fields_by_rule_type` ``` POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2 { "unencrypted": true, "refreshCache": true } ``` <details> <summary> Here is what it looks like:</summary>   </details> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Closes elastic#220815 ## Summary This PR adds telemetry for _ignored fields. The goal is to have an alert based on this field and get notified in case a user hits the mapping limit, but by default, we don't expect this to happen. This PR adds `count_ignored_fields_by_rule_type` field that counts the number of _ignored fields per rule type. In the future, we can extend the telemetry data to also include the actual number of mappings over the limit (there is a [feature request](elastic/elasticsearch#68947) for adding field count information to index API) ### How to test - Add a lot of dynamic fields as mentioned here: elastic#216719 - Create a rule with a custom threshold rule with multiple group by fields to generate an alert with _ignored field - Run the following API and check the value of `count_ignored_fields_by_rule_type` ``` POST kbn:/internal/telemetry/clusters/_stats?apiVersion=2 { "unencrypted": true, "refreshCache": true } ``` <details> <summary> Here is what it looks like:</summary>   </details> --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This PR adds the auto-increase the fields limit on startup when an alerts index reaches its limits because of the dynamic fields.
To verify:
To be able to test this PR we need a rule type that adds dynamic fields.
I used the custom threshold rule for this:
Go to the custom threshold rule type definition and change its alerts.mappings to:
Above changes adds 412 dummy fields to the alerts index to make it close to reach its fields limit (default: 2500).
And makes everything under
kibana.alert.groupingpath to be added to the index as dynamic fields.Then apply the below changes to the custom threshold rule executor:
Above changes add the selected groups under
kibana.alerting.groupingpath.Then:
path.data=../your-local-data-pathto keep the data for the next start.Stack Management>Index Managementand search for observability threshold index..internal.alerts-observability.threshold.alerts-default-000001index.The other groups you have selected should be saved under
_ignoredfield:Stack Management>Index ManagementStack Management>Index Management>.internal.alerts-observability.threshold.alerts-default-000001> settings tab."mapping" > "total_fields" > "limit"should be greater than 2500