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

[8.x] [Entity Analytics] API changes for right placement of deleting the old component template (#199734) #200673

Merged

Conversation

abhishekbhatia1710
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sqren/backport)\n\n"}}]}] BACKPORT-->

…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
Copy link
Contributor

@CAWilson94 CAWilson94 left a comment

Choose a reason for hiding this comment

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

LGTM, nice!

@abhishekbhatia1710
Copy link
Contributor Author

Weird, the same test passes locally. Investigating it further.

Ref :

image

@abhishekbhatia1710 abhishekbhatia1710 self-assigned this Nov 27, 2024
@abhishekbhatia1710 abhishekbhatia1710 merged commit 24cbc3e into elastic:8.x Nov 27, 2024
8 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @abhishekbhatia1710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants