Error Occurred while setting ISM Policy for Data Retention in OpenSearch
Error Occurred while setting ISM Policy for Data Retention in OpenSearch in OpenSearch Issues.
Error Occurred while setting ISM Policy for Data Retention in OpenSearch#
Error Occurred while setting ism policy for Data Retention in OpenSearch
Solution: Follow the below steps.
-
Get the ISM policy name by curl. (use your OpenSearch host:port )
Or
Check ISM policy script for policy name
-
Execute the below command to get details of particular ISM policy.
curl -u admin:admin http://192.0.2.10:9201/_plugins/_ism/policies/(ISM Policy name)For Example:
curl -u admin:admin http://192.0.2.10:9201/_plugins/_ism/policies/logscan_raw-ism-policyExpected Output:
{"_id":"logscan_raw-ism- policy","_version":1,"_primary_term":4,"_seq_no":13904744,"policy": {"policy":{"policy_id":"logscan_raw-ism- policy","description":"Policy that deletes indicies older than 7 days.","last_updated_time":1653558327846,"schema_version":4,"error_n otification":null,"default_state":"open","states": [{"name":"open","actions":[{"open":{}}],"transitions": [{"state_name":"delete","conditions":{"min_index_age":"7d"}}]}, {"name":"delete","actions":[{"delete":{}}],"transitions": []}],"ism_template":[{"index_patterns":["logscan- raw*"],"priority":200,"last_updated_time":1653558327846}]}}}Added data retention policy for 7 days. -
Copy the field’s pri mary term":4,"_seq_no":13904744 value.
-
Update the ISM policy script (or create another) with the ? if_seq_no=13904744&if_primary_term=4 parameters.
curl -u $userpass -XPUT "http://$hostport/_plugins/_ism/policies/logscan_raw-ism-policy? if_seq_no=13904744&if_primary_term=4"Note: Parameters value will different as per the curl’s output.
Example Script:
if [ "$#" -eq 3 ]; then userpass="${1:='admin:admin'}" hostport="${2:='127.0.0.1:9200'}" dataretention="${3:=30}" CurlData=curl_data.json echo "{ \"policy\": { \"description\": \"Policy that deletes indicies older than $dataretention days.\", \"schema_version\": 4, \"error_notification\": null, \"default_state\": \"open\", \"states\": [ { \"name\": \"open\", \"actions\": [ { \"open\": {} } ], \"transitions\": [ { \"state_name\": \"delete\", \"conditions\": { \"min_index_age\": \"${dataretention}d\" } } ] }, { \"name\": \"delete\", \"actions\": [ { \"delete\": {} } ], \"transitions\": [] } ], \"ism_template\": { \"index_patterns\": [ \"logscan-raw*\" ], \"priority\": 200 } }}" > $CurlData # Command to put data retention policy. curl -u $userpass -XPUT "http://$hostport/_plugins/_ism/policies/logscan_raw-ism-policy? if_seq_no=13904744&if_primary_term=4" -H 'Content-Type: application/json' -d @${CurlData} echo "Added data retention policy for $dataretention days." rm -rf ${CurlData} else echo "Command usage: logscan_raw_ism_policy.sh <opensearch userid:password> <opensearch host:port> <data retention days count>" fi -
Execute the script to update ISM policy/data retention period:
sh logscan_raw_ism_update.sh admin:admin opensearch_ip:port no. of daysFor Example:
sh logscan_raw_ism_update.sh admin:admin 192.0.2.10:9201 30
Set the ISM Policy#
Perform below steps to set ism_policy for indices :
-
Execute the below command to get the existing ism policy. Also save this o/p in your local.
curl -XGET -k -u admin:admin "https://<opensearch_ip>: <opensearch_port>/_plugins/_ism/policies/" | jq -
Execute the below command to delete existing ism policy.
curl -ku admin:admin -XDELETE "https://<opensearch_ip>: <opensearch_port>/_plugins/_ism/policies/<ism_policy_name>" -
Execute the command like below (not exact) to apply the new policy.
curl -ku admin:admin -XPUT "https://<opensearch_ip>: <opensearch_port>/_plugins/_ism/policies/ism_collated_indexes" -H 'Content-Type: application/json' -d'{"policy": {"description": "Policy that deletes indices older than 365days","schema_version": 12,"error_notification": null,"default_state": "open","states": [{"name": "open","actions": [{"open": {}}],"transitions": [{"state_name": "delete","conditions": {"min_index_age": "365d"}}]}, {"name": "delete","actions": [{"delete": {}}],"transitions": []}],"ism_template": {"index_patterns": ["heal_collated_agent_txn_*", "heal_collated_txn_*", "heal_collated_kpi_*"],"priority": 1}}}'-
Update policy name, description, schema version, min index age, index patterns, priority etc as per existing setup.
-
Compare all fields with your current is m_policy and update the same.
Only change the min_index_age and description as per your requirement.
-
-
Once the is m_policy is updated, thereafter whichever new indices get created, it will be applicable to only those.
The already existing indices will still follow the old is m_policy . If you want to retain any older indices, it is suggested to perform OpenSearch snapshot.
Data Collection Interruption in UI#
Data collection in the UI has ceased, and the OpenSearch cluster status is marked as red. This was attributed to unassigned shards in KPI-type indices with a zone specified as 'heal,' while none of our OpenSearch nodes were assigned to a zone with the name 'heal.'
Root Cause Analysis: The issue originated from a zoning template update performed last Thursday, wherein the zone 'heal' was incorrectly applied to the indices. This misalignment led to unassigned shards and a red cluster status.
Solution: To rectify this, follow the below steps:
-
Correct the zoning template and align the zone with the OpenSearch nodes.
-
Existing unassigned indices were updated with the proper zone 'kpi ' using the provided command.
-
Correcting Zoning Template and Updating Unassigned Indices:
-
Correct the zone for existing unassigned indices using the following command:
heal_error_kpi_heal_health_2023.w37 heal_raw_kpi_app_2023.09.10 heal_raw_kpi_heal_health_2023.09.09 heal_raw_kpi_app_2023.09.07 heal_raw_kpi_app_2023.09.08 heal_collated_kpi_heal_health_2023.w37 heal_raw_kpi_app_2023.09.09 heal_raw_kpi_heal_health_2023.09.07 heal_error_kpi_app_2023.w37 heal_raw_kpi_heal_health_2023.09.11 heal_raw_kpi_heal_health_2023.09.08 heal_collated_kpi_app_2023.w37 heal_raw_kpi_heal_health_2023.09.10 heal_raw_kpi_app_2023.09.11These indices got created with zone as ‘heal ’ but there none of our OpenSearch nodes are assigned has one name ‘heal ’.
"explanation": "node does not match index setting [index.routing.allocation.require] filters [zone:\"heal\"]" -
As the 'collated-kpi ' index was created with the incorrect zone, data insertion was halted until the correction command was executed.
curl -ku admin:admin -XPUT "https://<opensearch_ip>: <opensearch_port>/<index_name>/_settings" -H 'Content-Type: application/json' - d'{"index.routing.allocation.require.zone":"kpi"}' -
Update the zoning template correctly, setting the zone as 'kpi ' to ensure proper zone allocation for upcoming indices:
curl -sk -u admin:admin -X PUT "https://192.0.2.11:9201/_template/heal_collated_kpi_zone- template" -H 'Content-Type: application/json' -d@a.jsonJson file:
{ "order" : 20, "version" : 3, "index_patterns" : [ "heal_collated_kpi_*", "heal_error_kpi_*", "heal_watcher_kpi_snapshots_*", "heal_raw_kpi_*", "heal_raw_external_data_*" ], "settings" : { "index" : { "routing" : { "allocation" : { "require" : { "zone" : "kpi" } } } } }, "mappings" : { }, "aliases" : { } }'For information:
- For any future updates to the zoning template, always verify the "node.attr.zone " parameter from the OpenSearch yml file for the corresponding OpenSearch node.
- Ensure that the zone provided in the template matches the configuration in the respective OpenSearch nodes. This verification process ensures accurate and consistent zoning configurations.
-