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

[Entity Analytics] API changes for right placement of deleting the old component template #199734

Conversation

abhishekbhatia1710
Copy link
Contributor

@abhishekbhatia1710 abhishekbhatia1710 commented Nov 12, 2024

Summary

  • Delete the old component template after the index template has referenced to the new component template
  • Test cases for the same flow
# Let's assume this is 8.15.3
# Create the component template when Risk Score engine is initialised
# Create the index template which references the created component template

PUT /_component_template/.risk-score-mappings
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

# The deployment is updated to 8.16
# User tries to enable the Entity store which init's the Risk Score engine (again!!) 
# Fails, but creates the component template and cannot update the index template to reference the new component template due to the error

PUT /_component_template/.risk-score-mappings-default
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

GET /_component_template?filter_path=component_templates.name&name=.risk-score-mappings*


DELETE /_component_template/.risk-score-mappings

# Fails 

# changed flow
PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings-default"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

DELETE /_component_template/.risk-score-mappings

# Succeeds

#########

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@abhishekbhatia1710 abhishekbhatia1710 added bug Fixes for quality problems that affect the customer experience Team:Entity Analytics Security Entity Analytics Team backport:version Backport to applied version labels v8.16.1 labels Nov 12, 2024
@abhishekbhatia1710 abhishekbhatia1710 self-assigned this Nov 12, 2024
@abhishekbhatia1710 abhishekbhatia1710 requested a review from a team as a code owner November 12, 2024 09:00
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-entity-analytics (Team:Entity Analytics)

@abhishekbhatia1710
Copy link
Contributor Author

abhishekbhatia1710 commented Nov 12, 2024

Question:

Should we really modify the UI modal to avoid calling the init Risk Engine API if it's already initialised?

In my opinion, the init Risk Score Engine API updates the component and index templates as needed, ensuring they remain updated with the correct space name in any flow (upgrade or standard)

@jaredburgettelastic @hop-dev

@abhishekbhatia1710 abhishekbhatia1710 changed the title API changes for right placement of deleting the old component template [Entity Analytics] API changes for right placement of deleting the old component template Nov 12, 2024
@machadoum
Copy link
Member

machadoum commented Nov 14, 2024

@abhishekbhatia1710 This PR looks good to me. But let's address your suggestion.

Should we really modify the UI modal to avoid calling the init Risk Engine API if it's already initialised?

I agree 100% with this. But I thought we already had this check in place.
@tiansivive Is moving the enablement to BE. So we should make sure it is disabled before calling init.

Copy link
Member

@machadoum machadoum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM!

I don't have time today to desk test it.

Are you going to address this comment before merging the PR?
#199734 (comment)

@abhishekbhatia1710
Copy link
Contributor Author

The code LGTM!
I don't have time today to desk test it.
Are you going to address this comment before merging the PR?
#199734 (comment)

No, this scenario is already handled. Joe mentioned it in his comment (https://elastic.slack.com/archives/C05V9NE6X4K/p1731615750750869). The toggle button is disabled if the risk engine is already installed, preventing the user from enabling it through the UI.

@abhishekbhatia1710 abhishekbhatia1710 enabled auto-merge (squash) November 18, 2024 14:19
@abhishekbhatia1710 abhishekbhatia1710 merged commit 771c139 into elastic:main Nov 18, 2024
56 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.16, 8.x

https://github.com/elastic/kibana/actions/runs/11895247426

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @abhishekbhatia1710

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.16 Backport failed because of merge conflicts
8.x Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 199734

Questions ?

Please refer to the Backport tool documentation

@abhishekbhatia1710
Copy link
Contributor Author

💔 Some backports could not be created

Status Branch Result
8.x An unhandled error occurred. Please see the logs for details
8.16

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 199734

Questions ?

Please refer to the Backport tool documentation

jesuswr pushed a commit to jesuswr/kibana that referenced this pull request Nov 18, 2024
…d component template (elastic#199734)

## Summary

- Delete the old component template after the index template has
referenced to the new component template
- Test cases for the same flow


```JSON
# Let's assume this is 8.15.3
# Create the component template when Risk Score engine is initialised
# Create the index template which references the created component template

PUT /_component_template/.risk-score-mappings
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

# The deployment is updated to 8.16
# User tries to enable the Entity store which init's the Risk Score engine (again!!) 
# Fails, but creates the component template and cannot update the index template to reference the new component template due to the error

PUT /_component_template/.risk-score-mappings-default
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

GET /_component_template?filter_path=component_templates.name&name=.risk-score-mappings*


DELETE /_component_template/.risk-score-mappings

# Fails 

# changed flow
PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings-default"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

DELETE /_component_template/.risk-score-mappings

# Succeeds

#########
```


### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed



### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)
- [ ] This will appear in the **Release Notes** and follow the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
abhishekbhatia1710 added a commit that referenced this pull request Nov 18, 2024
… the old component template (#199734) (#200591)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Entity Analytics] API changes for right placement of deleting the
old component template
(#199734)](#199734)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Abhishek
Bhatia","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-18T15:07:13Z","message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","Team:Entity
Analytics","backport:version","v8.17.0","v8.16.1"],"number":199734,"url":"https://github.com/elastic/kibana/pull/199734","mergeCommit":{"message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199734","number":199734,"mergeCommit":{"message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@abhishekbhatia1710
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

abhishekbhatia1710 added a commit to abhishekbhatia1710/kibana that referenced this pull request Nov 19, 2024
…d component template (elastic#199734)

## Summary

- Delete the old component template after the index template has
referenced to the new component template
- Test cases for the same flow

```JSON
# Let's assume this is 8.15.3
# Create the component template when Risk Score engine is initialised
# Create the index template which references the created component template

PUT /_component_template/.risk-score-mappings
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

# The deployment is updated to 8.16
# User tries to enable the Entity store which init's the Risk Score engine (again!!)
# Fails, but creates the component template and cannot update the index template to reference the new component template due to the error

PUT /_component_template/.risk-score-mappings-default
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

GET /_component_template?filter_path=component_templates.name&name=.risk-score-mappings*

DELETE /_component_template/.risk-score-mappings

# Fails

# changed flow
PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings-default"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

DELETE /_component_template/.risk-score-mappings

# Succeeds

#########
```

### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)
- [ ] This will appear in the **Release Notes** and follow the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

(cherry picked from commit 771c139)

# Conflicts:
#	x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/risk_score_data_client.ts
#	x-pack/test/security_solution_api_integration/test_suites/entity_analytics/risk_engine/trial_license_complete_tier/init_and_status_apis.ts
@muskangulati-qasource
Copy link

Hi @abhishekbhatia1710 ,

We have tested this ticket on the latest 8.16.1 BC2 and below are our observations for the same.

Please find below the testing details:

Build details

VERSION: 8.16.1
BUILD: 79724
COMMIT: c8b46e87c4d61de4fe046ce5ea0a0b68aad5acf9

Screen Recordings

  • Entity risk score and entity store are successfully enabled without any errors
1.mp4
  • Entity store is enabled from the dashboards without any errors
2.mp4
  • The 'enable' button is enabled even when nothing is selected to be enabled
3.mp4

Please let us know if anything is missing from our end.

cc: @MadameSheema
Thanks!!

@abhishekbhatia1710
Copy link
Contributor Author

Thanks, @muskangulati-qasource for testing this feature out and it seems to be fine.

As discussed in our Slack thread, this appears to follow the "standard" flow where the build is freshly created with version 8.16.1.

Another scenario to consider is when a user upgrades to 8.16.1 from any of the earlier 8.15.x versions.

It would be a good idea to test that flow as well. Thanks!

@muskangulati-qasource
Copy link

muskangulati-qasource commented Nov 20, 2024

Hi @abhishekbhatia1710,

Thank you for sharing the details. Please find below the testing details for upgrade testing performed:

Build details

  • 8.15.3:
VERSION: 8.15.3
BUILD: 76711
COMMIT: 3933429968aafb1ba31319fc38649d0f974044bf
  • 8.16.1:
VERSION: 8.16.1
BUILD: 79724
COMMIT: c8b46e87c4d61de4fe046ce5ea0a0b68aad5acf9

Screenshots and Recordings for observations

  • 8.15.3:
    image

  • Upgrade performed:
    image

  • 8.16.1:

  • Entity risk score and entity store are successfully enabled without any errors

1.mp4
  • Entity store is enabled from the dashboards without any errors
2.mp4
  • The 'enable' button is enabled even when nothing is selected to be enabled
3.mp4

Thank you!

@abhishekbhatia1710
Copy link
Contributor Author

Awesome @muskangulati-qasource , thanks a lot for testing the upgrade flow as well.

All looks to be working as expected!

@muskangulati-qasource muskangulati-qasource added the QA:Validated Issue has been validated by QA label Nov 21, 2024
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 25, 2024
@kibanamachine
Copy link
Contributor

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.

2 similar comments
@kibanamachine
Copy link
Contributor

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.

@kibanamachine
Copy link
Contributor

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.

abhishekbhatia1710 added a commit that referenced this pull request Nov 27, 2024
…the old component template (#199734) (#200673)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Entity Analytics] API changes for right placement of deleting the
old component template
(#199734)](#199734)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Abhishek
Bhatia","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-18T15:07:13Z","message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","v9.0.0","Team:Entity
Analytics","backport:version","v8.17.0","v8.16.1"],"number":199734,"url":"https://github.com/elastic/kibana/pull/199734","mergeCommit":{"message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199734","number":199734,"mergeCommit":{"message":"[Entity
Analytics] API changes for right placement of deleting the old component
template (#199734)\n\n## Summary\r\n\r\n- Delete the old component
template after the index template has\r\nreferenced to the new component
template\r\n- Test cases for the same flow\r\n\r\n\r\n```JSON\r\n# Let's
assume this is 8.15.3\r\n# Create the component template when Risk Score
engine is initialised\r\n# Create the index template which references
the created component template\r\n\r\nPUT
/_component_template/.risk-score-mappings\r\n{\r\n \"template\": {\r\n
\"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n \"mappings\":
{\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\": \"date\"\r\n
},\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n \"type\":
\"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n }\r\n
}\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings\"],\r\n \"priority\": 100,\r\n
\"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index template
for indices with the pattern my_index-*\"\r\n }\r\n}\r\n\r\n# The
deployment is updated to 8.16\r\n# User tries to enable the Entity store
which init's the Risk Score engine (again!!) \r\n# Fails, but creates
the component template and cannot update the index template to reference
the new component template due to the error\r\n\r\nPUT
/_component_template/.risk-score-mappings-default\r\n{\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_shards\": 1\r\n },\r\n
\"mappings\": {\r\n \"properties\": {\r\n \"timestamp\": {\r\n \"type\":
\"date\"\r\n },\r\n \"user\": {\r\n \"properties\": {\r\n \"id\": {\r\n
\"type\": \"keyword\"\r\n },\r\n \"name\": {\r\n \"type\": \"text\"\r\n
}\r\n }\r\n }\r\n }\r\n }\r\n },\r\n \"version\": 1\r\n}\r\n\r\nGET
/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\r\n\r\n\r\nDELETE
/_component_template/.risk-score-mappings\r\n\r\n# Fails \r\n\r\n#
changed flow\r\nPUT
/_index_template/.risk-score.risk-score-default-index-template\r\n{\r\n
\"index_patterns\":
[\".risk-score.risk-score-default-index-template\"],\r\n \"template\":
{\r\n \"settings\": {\r\n \"number_of_replicas\": 1\r\n }\r\n },\r\n
\"composed_of\": [\".risk-score-mappings-default\"],\r\n \"priority\":
100,\r\n \"version\": 1,\r\n \"_meta\": {\r\n \"description\": \"Index
template for indices with the pattern my_index-*\"\r\n
}\r\n}\r\n\r\nDELETE /_component_template/.risk-score-mappings\r\n\r\n#
Succeeds\r\n\r\n#########\r\n```\r\n\r\n\r\n### Checklist\r\n\r\nDelete
any items that are not applicable to this PR.\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n\r\n\r\n\r\n### For
maintainers\r\n\r\n- [ ] This was checked for breaking API changes and
was
[labeled\r\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\r\n-
[ ] This will appear in the **Release Notes** and follow
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)","sha":"771c139269ac0eac27274e0858be2fbcf87b31e3"}},{"branch":"8.x","label":"v8.17.0","labelRegex":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.1","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/200591","number":200591,"state":"MERGED","mergeCommit":{"sha":"06999139d210464c236a3784c58b7e5dcbd64ce3","message":"[8.16]
[Entity Analytics] API changes for right placement of deleting the old
component template (#199734) (#200591)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.16`:\n- [[Entity
Analytics] API changes for right placement of deleting the\nold
component
template\n(#199734)](https://github.com/elastic/kibana/pull/199734)\n\n<!---
Backport version: 8.9.8 -->\n\n### Questions ?\nPlease refer to the
[Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n<!--BACKPORT
[{\"author\":{\"name\":\"Abhishek\nBhatia\",\"email\":\"[email protected]\"},\"sourceCommit\":{\"committedDate\":\"2024-11-18T15:07:13Z\",\"message\":\"[Entity\nAnalytics]
API changes for right placement of deleting the old component\ntemplate
(#199734)\\n\\n## Summary\\r\\n\\r\\n- Delete the old
component\ntemplate after the index template has\\r\\nreferenced to the
new component\ntemplate\\r\\n- Test cases for the same
flow\\r\\n\\r\\n\\r\\n```JSON\\r\\n# Let's\nassume this is 8.15.3\\r\\n#
Create the component template when Risk Score\nengine is
initialised\\r\\n# Create the index template which references\nthe
created component
template\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings\\r\\n{\\r\\n
\\\"template\\\": {\\r\\n\n\\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n \\\"mappings\\\":\n{\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n \\\"type\\\":
\\\"date\\\"\\r\\n\n},\\r\\n \\\"user\\\": {\\r\\n \\\"properties\\\":
{\\r\\n \\\"id\\\": {\\r\\n \\\"type\\\":\n\\\"keyword\\\"\\r\\n
},\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\": \\\"text\\\"\\r\\n
}\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n \\\"version\\\":
1\\r\\n}\\r\\n\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\": [\\\".risk-score-mappings\\\"],\\r\\n
\\\"priority\\\": 100,\\r\\n\n\\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index template\nfor indices with the
pattern my_index-*\\\"\\r\\n }\\r\\n}\\r\\n\\r\\n# The\ndeployment is
updated to 8.16\\r\\n# User tries to enable the Entity store\nwhich
init's the Risk Score engine (again!!) \\r\\n# Fails, but creates\nthe
component template and cannot update the index template to
reference\nthe new component template due to the
error\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings-default\\r\\n{\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n\n\\\"mappings\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n
\\\"type\\\":\n\\\"date\\\"\\r\\n },\\r\\n \\\"user\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"id\\\": {\\r\\n\n\\\"type\\\":
\\\"keyword\\\"\\r\\n },\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\":
\\\"text\\\"\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n
\\\"version\\\":
1\\r\\n}\\r\\n\\r\\nGET\n/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\\r\\n\\r\\n\\r\\nDELETE\n/_component_template/.risk-score-mappings\\r\\n\\r\\n#
Fails \\r\\n\\r\\n#\nchanged
flow\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\":
[\\\".risk-score-mappings-default\\\"],\\r\\n
\\\"priority\\\":\n100,\\r\\n \\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index\ntemplate for indices with the
pattern my_index-*\\\"\\r\\n\n}\\r\\n}\\r\\n\\r\\nDELETE
/_component_template/.risk-score-mappings\\r\\n\\r\\n#\nSucceeds\\r\\n\\r\\n#########\\r\\n```\\r\\n\\r\\n\\r\\n###
Checklist\\r\\n\\r\\nDelete\nany items that are not applicable to this
PR.\\r\\n\\r\\n- [ ] [Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most common scenarios\\r\\n- [ ]
[Flaky\nTest\\r\\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)\nwas\\r\\nused
on any tests changed\\r\\n\\r\\n\\r\\n\\r\\n###
For\nmaintainers\\r\\n\\r\\n- [ ] This was checked for breaking API
changes
and\nwas\n[labeled\\r\\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\\r\\n-\n[
] This will appear in the **Release Notes** and
follow\nthe\\r\\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\",\"sha\":\"771c139269ac0eac27274e0858be2fbcf87b31e3\",\"branchLabelMapping\":{\"^v9.0.0$\":\"main\",\"^v8.17.0$\":\"8.x\",\"^v(\\\\d+).(\\\\d+).\\\\d+$\":\"$1.$2\"}},\"sourcePullRequest\":{\"labels\":[\"bug\",\"release_note:fix\",\"v9.0.0\",\"Team:Entity\nAnalytics\",\"backport:version\",\"v8.17.0\",\"v8.16.1\"],\"number\":199734,\"url\":\"https://github.com/elastic/kibana/pull/199734\",\"mergeCommit\":{\"message\":\"[Entity\nAnalytics]
API changes for right placement of deleting the old component\ntemplate
(#199734)\\n\\n## Summary\\r\\n\\r\\n- Delete the old
component\ntemplate after the index template has\\r\\nreferenced to the
new component\ntemplate\\r\\n- Test cases for the same
flow\\r\\n\\r\\n\\r\\n```JSON\\r\\n# Let's\nassume this is 8.15.3\\r\\n#
Create the component template when Risk Score\nengine is
initialised\\r\\n# Create the index template which references\nthe
created component
template\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings\\r\\n{\\r\\n
\\\"template\\\": {\\r\\n\n\\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n \\\"mappings\\\":\n{\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n \\\"type\\\":
\\\"date\\\"\\r\\n\n},\\r\\n \\\"user\\\": {\\r\\n \\\"properties\\\":
{\\r\\n \\\"id\\\": {\\r\\n \\\"type\\\":\n\\\"keyword\\\"\\r\\n
},\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\": \\\"text\\\"\\r\\n
}\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n \\\"version\\\":
1\\r\\n}\\r\\n\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\": [\\\".risk-score-mappings\\\"],\\r\\n
\\\"priority\\\": 100,\\r\\n\n\\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index template\nfor indices with the
pattern my_index-*\\\"\\r\\n }\\r\\n}\\r\\n\\r\\n# The\ndeployment is
updated to 8.16\\r\\n# User tries to enable the Entity store\nwhich
init's the Risk Score engine (again!!) \\r\\n# Fails, but creates\nthe
component template and cannot update the index template to
reference\nthe new component template due to the
error\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings-default\\r\\n{\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n\n\\\"mappings\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n
\\\"type\\\":\n\\\"date\\\"\\r\\n },\\r\\n \\\"user\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"id\\\": {\\r\\n\n\\\"type\\\":
\\\"keyword\\\"\\r\\n },\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\":
\\\"text\\\"\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n
\\\"version\\\":
1\\r\\n}\\r\\n\\r\\nGET\n/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\\r\\n\\r\\n\\r\\nDELETE\n/_component_template/.risk-score-mappings\\r\\n\\r\\n#
Fails \\r\\n\\r\\n#\nchanged
flow\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\":
[\\\".risk-score-mappings-default\\\"],\\r\\n
\\\"priority\\\":\n100,\\r\\n \\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index\ntemplate for indices with the
pattern my_index-*\\\"\\r\\n\n}\\r\\n}\\r\\n\\r\\nDELETE
/_component_template/.risk-score-mappings\\r\\n\\r\\n#\nSucceeds\\r\\n\\r\\n#########\\r\\n```\\r\\n\\r\\n\\r\\n###
Checklist\\r\\n\\r\\nDelete\nany items that are not applicable to this
PR.\\r\\n\\r\\n- [ ] [Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most common scenarios\\r\\n- [ ]
[Flaky\nTest\\r\\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)\nwas\\r\\nused
on any tests changed\\r\\n\\r\\n\\r\\n\\r\\n###
For\nmaintainers\\r\\n\\r\\n- [ ] This was checked for breaking API
changes
and\nwas\n[labeled\\r\\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\\r\\n-\n[
] This will appear in the **Release Notes** and
follow\nthe\\r\\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\",\"sha\":\"771c139269ac0eac27274e0858be2fbcf87b31e3\"}},\"sourceBranch\":\"main\",\"suggestedTargetBranches\":[\"8.x\",\"8.16\"],\"targetPullRequestStates\":[{\"branch\":\"main\",\"label\":\"v9.0.0\",\"labelRegex\":\"^v9.0.0$\",\"isSourceBranch\":true,\"state\":\"MERGED\",\"url\":\"https://github.com/elastic/kibana/pull/199734\",\"number\":199734,\"mergeCommit\":{\"message\":\"[Entity\nAnalytics]
API changes for right placement of deleting the old component\ntemplate
(#199734)\\n\\n## Summary\\r\\n\\r\\n- Delete the old
component\ntemplate after the index template has\\r\\nreferenced to the
new component\ntemplate\\r\\n- Test cases for the same
flow\\r\\n\\r\\n\\r\\n```JSON\\r\\n# Let's\nassume this is 8.15.3\\r\\n#
Create the component template when Risk Score\nengine is
initialised\\r\\n# Create the index template which references\nthe
created component
template\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings\\r\\n{\\r\\n
\\\"template\\\": {\\r\\n\n\\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n \\\"mappings\\\":\n{\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n \\\"type\\\":
\\\"date\\\"\\r\\n\n},\\r\\n \\\"user\\\": {\\r\\n \\\"properties\\\":
{\\r\\n \\\"id\\\": {\\r\\n \\\"type\\\":\n\\\"keyword\\\"\\r\\n
},\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\": \\\"text\\\"\\r\\n
}\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n \\\"version\\\":
1\\r\\n}\\r\\n\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\": [\\\".risk-score-mappings\\\"],\\r\\n
\\\"priority\\\": 100,\\r\\n\n\\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index template\nfor indices with the
pattern my_index-*\\\"\\r\\n }\\r\\n}\\r\\n\\r\\n# The\ndeployment is
updated to 8.16\\r\\n# User tries to enable the Entity store\nwhich
init's the Risk Score engine (again!!) \\r\\n# Fails, but creates\nthe
component template and cannot update the index template to
reference\nthe new component template due to the
error\\r\\n\\r\\nPUT\n/_component_template/.risk-score-mappings-default\\r\\n{\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_shards\\\": 1\\r\\n },\\r\\n\n\\\"mappings\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"timestamp\\\": {\\r\\n
\\\"type\\\":\n\\\"date\\\"\\r\\n },\\r\\n \\\"user\\\": {\\r\\n
\\\"properties\\\": {\\r\\n \\\"id\\\": {\\r\\n\n\\\"type\\\":
\\\"keyword\\\"\\r\\n },\\r\\n \\\"name\\\": {\\r\\n \\\"type\\\":
\\\"text\\\"\\r\\n\n}\\r\\n }\\r\\n }\\r\\n }\\r\\n }\\r\\n },\\r\\n
\\\"version\\\":
1\\r\\n}\\r\\n\\r\\nGET\n/_component_template?filter_path=component_templates.name&name=.risk-score-mappings*\\r\\n\\r\\n\\r\\nDELETE\n/_component_template/.risk-score-mappings\\r\\n\\r\\n#
Fails \\r\\n\\r\\n#\nchanged
flow\\r\\nPUT\n/_index_template/.risk-score.risk-score-default-index-template\\r\\n{\\r\\n\n\\\"index_patterns\\\":\n[\\\".risk-score.risk-score-default-index-template\\\"],\\r\\n
\\\"template\\\":\n{\\r\\n \\\"settings\\\": {\\r\\n
\\\"number_of_replicas\\\": 1\\r\\n }\\r\\n
},\\r\\n\n\\\"composed_of\\\":
[\\\".risk-score-mappings-default\\\"],\\r\\n
\\\"priority\\\":\n100,\\r\\n \\\"version\\\": 1,\\r\\n \\\"_meta\\\":
{\\r\\n \\\"description\\\": \\\"Index\ntemplate for indices with the
pattern my_index-*\\\"\\r\\n\n}\\r\\n}\\r\\n\\r\\nDELETE
/_component_template/.risk-score-mappings\\r\\n\\r\\n#\nSucceeds\\r\\n\\r\\n#########\\r\\n```\\r\\n\\r\\n\\r\\n###
Checklist\\r\\n\\r\\nDelete\nany items that are not applicable to this
PR.\\r\\n\\r\\n- [ ] [Unit
or\nfunctional\\r\\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\\r\\nwere\nupdated
or added to match the most common scenarios\\r\\n- [ ]
[Flaky\nTest\\r\\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)\nwas\\r\\nused
on any tests changed\\r\\n\\r\\n\\r\\n\\r\\n###
For\nmaintainers\\r\\n\\r\\n- [ ] This was checked for breaking API
changes
and\nwas\n[labeled\\r\\nappropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)\\r\\n-\n[
] This will appear in the **Release Notes** and
follow\nthe\\r\\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\",\"sha\":\"771c139269ac0eac27274e0858be2fbcf87b31e3\"}},{\"branch\":\"8.x\",\"label\":\"v8.17.0\",\"labelRegex\":\"^v8.17.0$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"},{\"branch\":\"8.16\",\"label\":\"v8.16.1\",\"labelRegex\":\"^v(\\\\d+).(\\\\d+).\\\\d+$\",\"isSourceBranch\":false,\"state\":\"NOT_CREATED\"}]}]\nBACKPORT-->"}}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <[email protected]>
@kibanamachine kibanamachine added v8.18.0 and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Nov 27, 2024
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Dec 12, 2024
…d component template (elastic#199734)

## Summary

- Delete the old component template after the index template has
referenced to the new component template
- Test cases for the same flow


```JSON
# Let's assume this is 8.15.3
# Create the component template when Risk Score engine is initialised
# Create the index template which references the created component template

PUT /_component_template/.risk-score-mappings
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

# The deployment is updated to 8.16
# User tries to enable the Entity store which init's the Risk Score engine (again!!) 
# Fails, but creates the component template and cannot update the index template to reference the new component template due to the error

PUT /_component_template/.risk-score-mappings-default
{
  "template": {
    "settings": {
      "number_of_shards": 1
    },
    "mappings": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "user": {
          "properties": {
            "id": {
              "type": "keyword"
            },
            "name": {
              "type": "text"
            }
          }
        }
      }
    }
  },
  "version": 1
}

GET /_component_template?filter_path=component_templates.name&name=.risk-score-mappings*


DELETE /_component_template/.risk-score-mappings

# Fails 

# changed flow
PUT /_index_template/.risk-score.risk-score-default-index-template
{
  "index_patterns": [".risk-score.risk-score-default-index-template"],
  "template": {
    "settings": {
      "number_of_replicas": 1
    }
  },
  "composed_of": [".risk-score-mappings-default"],
  "priority": 100,
  "version": 1,
  "_meta": {
    "description": "Index template for indices with the pattern my_index-*"
  }
}

DELETE /_component_template/.risk-score-mappings

# Succeeds

#########
```


### Checklist

Delete any items that are not applicable to this PR.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed



### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#_add_your_labels)
- [ ] This will appear in the **Release Notes** and follow the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels bug Fixes for quality problems that affect the customer experience QA:Validated Issue has been validated by QA release_note:fix Team:Entity Analytics Security Entity Analytics Team v8.16.1 v8.17.0 v8.18.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants