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

Make Custom Result Index Name an Alias #1225

Merged
merged 1 commit into from
Jun 7, 2024

Conversation

kaituo
Copy link
Collaborator

@kaituo kaituo commented Jun 6, 2024

Description

Previously, we used configured custom result index names as the index name, creating the index only when a detector was created. This approach caused several problems for index management:

  1. Index State Management (ISM) Incompatibility: ISM requires an alias for rolling over an index, but we only had the index name.
  2. Index Recognition Issue: Even if we managed to roll over an index, AD could not recognize it because the index would not be recreated unless the detector was recreated.
  3. Result History and Top Anomaly Results: The result history on the dashboard and top anomaly results were reading from a single index instead of an index pattern. Thus, after rolling over an index, the result history and top anomaly results would be lost.

This PR addresses these issues:

  1. Custom Result Index Creation: We now create a custom result index with the name <custom-name-history-{now/d}-1> and use the alias custom-name to point to it.
  2. Index Recreation: We recreate an index when failing to find a result index, updating the configured alias to point to the new index. This ensures continuity when an index is rolled over and new indices do not exist.
  3. Query Index Pattern: The top anomaly result API now queries an index pattern instead of a single index. The result history on the dashboard follows the same approach. The dashboard code will be posted in a separate PR.

Additionally, this PR updates the custom result index mapping when the mapping is outdated, similar to existing logic on the default result index.

Testing Done:

  • Successfully updated the mapping of the custom result index when the mapping is outdated.
  • Verified that the frontend can still see old and new results after a rollover.
  • Confirmed that the backend can still write to new indices after a rollover.
  • Ensured all existing tests pass.

More tests will be added in the following PRs.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Previously, we used configured custom result index names as the index name, creating the index only when a detector was created. This approach caused several problems for index management:

1. **Index State Management (ISM) Incompatibility**: ISM requires an alias for rolling over an index, but we only had the index name.
2. **Index Recognition Issue**: Even if we managed to roll over an index, AD could not recognize it because the index would not be recreated unless the detector was recreated.
3. **Result History and Top Anomaly Results**: The result history on the dashboard and top anomaly results were reading from a single index instead of an index pattern. Thus, after rolling over an index, the result history and top anomaly results would be lost.

This PR addresses these issues:

1. **Custom Result Index Creation**: We now create a custom result index with the name `<custom-name-history-{now/d}-1>` and use the alias `custom-name` to point to it.
2. **Index Recreation**: We recreate an index when failing to find a result index, updating the configured alias to point to the new index. This ensures continuity when an index is rolled over and new indices do not exist.
3. **Query Index Pattern**: The top anomaly result API now queries an index pattern instead of a single index. The result history on the dashboard follows the same approach. The dashboard code will be posted in a separate PR.

Additionally, this PR updates the custom result index mapping when the mapping is outdated, similar to existing logic on the default result index.

**Testing Done**:
* Successfully updated the mapping of the custom result index when the mapping is outdated.
* Verified that the frontend can still see old and new results after a rollover.
* Confirmed that the backend can still write to new indices after a rollover.
* Ensured all existing tests pass.

More tests will be added in the following PRs.

Signed-off-by: Kaituo Li <kaituo@amazon.com>
@jackiehanyang
Copy link
Collaborator

jackiehanyang commented Jun 7, 2024

Synced offline about this pr. Thanks for the change!

@kaituo kaituo merged commit 4d400e3 into opensearch-project:main Jun 7, 2024
28 checks passed
@opensearch-trigger-bot
Copy link

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/anomaly-detection/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/anomaly-detection/backport-2.x
# Create a new branch
git switch --create backport/backport-1225-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 4d400e3c926528ec884b54749e035c7855fb104c
# Push it to GitHub
git push --set-upstream origin backport/backport-1225-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/anomaly-detection/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-1225-to-2.x.

kaituo added a commit to kaituo/anomaly-detection-1 that referenced this pull request Jun 10, 2024
Previously, we used configured custom result index names as the index name, creating the index only when a detector was created. This approach caused several problems for index management:

1. **Index State Management (ISM) Incompatibility**: ISM requires an alias for rolling over an index, but we only had the index name.
2. **Index Recognition Issue**: Even if we managed to roll over an index, AD could not recognize it because the index would not be recreated unless the detector was recreated.
3. **Result History and Top Anomaly Results**: The result history on the dashboard and top anomaly results were reading from a single index instead of an index pattern. Thus, after rolling over an index, the result history and top anomaly results would be lost.

This PR addresses these issues:

1. **Custom Result Index Creation**: We now create a custom result index with the name `<custom-name-history-{now/d}-1>` and use the alias `custom-name` to point to it.
2. **Index Recreation**: We recreate an index when failing to find a result index, updating the configured alias to point to the new index. This ensures continuity when an index is rolled over and new indices do not exist.
3. **Query Index Pattern**: The top anomaly result API now queries an index pattern instead of a single index. The result history on the dashboard follows the same approach. The dashboard code will be posted in a separate PR.

Additionally, this PR updates the custom result index mapping when the mapping is outdated, similar to existing logic on the default result index.

**Testing Done**:
* Successfully updated the mapping of the custom result index when the mapping is outdated.
* Verified that the frontend can still see old and new results after a rollover.
* Confirmed that the backend can still write to new indices after a rollover.
* Ensured all existing tests pass.

More tests will be added in the following PRs.

Signed-off-by: Kaituo Li <kaituo@amazon.com>
kaituo added a commit that referenced this pull request Jun 10, 2024
Previously, we used configured custom result index names as the index name, creating the index only when a detector was created. This approach caused several problems for index management:

1. **Index State Management (ISM) Incompatibility**: ISM requires an alias for rolling over an index, but we only had the index name.
2. **Index Recognition Issue**: Even if we managed to roll over an index, AD could not recognize it because the index would not be recreated unless the detector was recreated.
3. **Result History and Top Anomaly Results**: The result history on the dashboard and top anomaly results were reading from a single index instead of an index pattern. Thus, after rolling over an index, the result history and top anomaly results would be lost.

This PR addresses these issues:

1. **Custom Result Index Creation**: We now create a custom result index with the name `<custom-name-history-{now/d}-1>` and use the alias `custom-name` to point to it.
2. **Index Recreation**: We recreate an index when failing to find a result index, updating the configured alias to point to the new index. This ensures continuity when an index is rolled over and new indices do not exist.
3. **Query Index Pattern**: The top anomaly result API now queries an index pattern instead of a single index. The result history on the dashboard follows the same approach. The dashboard code will be posted in a separate PR.

Additionally, this PR updates the custom result index mapping when the mapping is outdated, similar to existing logic on the default result index.

**Testing Done**:
* Successfully updated the mapping of the custom result index when the mapping is outdated.
* Verified that the frontend can still see old and new results after a rollover.
* Confirmed that the backend can still write to new indices after a rollover.
* Ensured all existing tests pass.

More tests will be added in the following PRs.

Signed-off-by: Kaituo Li <kaituo@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport-failed infra Changes to infrastructure, testing, CI/CD, pipelines, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants