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

Add a rollover policy to the setup plugin #269

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

f-galland
Copy link
Member

Description

This PR is meant as a proof of concept that a rollover policy can be set up from a plugin, outside the Index Management plugin itself.
It does so by writing a policy json to the .opendistro-ism-config much like the Index Management plugin itself would do.

Issues Resolved

wazuh/wazuh-indexer#591

@f-galland f-galland self-assigned this Feb 7, 2025
@f-galland f-galland linked an issue Feb 7, 2025 that may be closed by this pull request
6 tasks
@f-galland
Copy link
Member Author

Policy Document

The setup plugin has been modified to index a document to the .opendistro-ism-config index which look as follows:

{
  "policy": {
    "policy_id": "wazuh_rollover_policy",
    "description": "Example rollover policy.",
    "last_updated_time": 1738947466825,
    "schema_version": 21,
    "error_notification": null,
    "default_state": "rollover",
    "states": [
      {
        "name": "rollover",
        "actions": [
          {
            "retry": {
              "count": 3,
              "backoff": "exponential",
              "delay": "1m"
            },
            "rollover": {
              "min_doc_count": 1,
              "copy_alias": false
            }
          }
        ],
        "transitions": []
      }
    ],
    "ism_template": [
      {
        "index_patterns": [
          "test-index-*"
        ],
        "priority": 100,
        "last_updated_time": 1738947466825
      }
    ],
    "user": {
      "name": "admin",
      "backend_roles": [
        "admin"
      ],
      "roles": [
        "own_index",
        "all_access"
      ],
      "custom_attribute_names": [],
      "user_requested_tenant": null
    }
  }
}

@f-galland
Copy link
Member Author

Index Management index template

During testing we found out that our plugin was quicker to load than the Index Management one, so a template must be set up for the .opendistro-ism-config index before creation.

We took the mappings from it from here:

@f-galland
Copy link
Member Author

Trigger the job

An index needs to be written, which matches the index pattern the policy expects, while also being set up as the write index for the rollover alias:

curl -XPUT http://localhost:9200/test-index-0000 -H 'Content-Type: application/json' -d '{"aliases":{"test-alias":{"is_write_index":true}}}'

@f-galland
Copy link
Member Author

Check that indices are being rotated

In order to speed up execution of the rollover policy, the following command can be issued:

curl -XPUT http://localhost:9200/_cluster/settings?pretty=true -H'Content-Type: application/json' -d '{"persistent": {"plugins.index_state_management.job_interval":1}}'

Now we can index new commands pointing towards our index alias:

curl -XPOST http://localhost:9200/test-alias/_doc -H 'Content-Type: application/json' -d '{"field":"value"}'

@f-galland
Copy link
Member Author

Check the policy is reckoned

We can now check whether the ISM plugin is recognizing our policy and will apply it to the right index

$ curl 'http://localhost:9200/_plugins/_ism/explain?pretty'
{
  "test-index-0000" : {
    "index.plugins.index_state_management.policy_id" : "wazuh_rollover_policy",
    "index.opendistro.index_state_management.policy_id" : "wazuh_rollover_policy",
    "index" : "test-index-0000",
    "index_uuid" : "v6dYvuxlS9mJ3DE_78-IyA",
    "policy_id" : "wazuh_rollover_policy",
    "enabled" : true
  },
  "total_managed_indices" : 1
}

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

Successfully merging this pull request may close these issues.

Rollover and alias for stream indices
1 participant