ES curator 인덱스 관리 보완
인덱스 관리 보완 배경
ES 반납된 클러스터들을 정리하면서 전체적으로 인덱스 삭제가 제대로 되는지 확인해보았습니다. 인덱스 삭제가 제대로 진행되지 않은 클러스터들이 있었고 이유를 확인해보니 생성한 인덱스의 날짜 형식이 curator의 action_config에 정의된 timestring 형식과 다르기 때문이었습니다. curator는 삭제, 이동 등의 action을 action_config 파일에 정의를 하는데 현재 curator에서 관리하는 인덱스는 아래와 같은 형식으로 정의되어 있습니다.
filters:
- filtertype: pattern #별 다른 요청이 없으면 kibana-2021.11.22 이런 형식의 모든 인덱스를 unit_count에 설정할 날짜 기준으로 관리를 합니다.
kind: prefix
value: '^[a-z].*-'
exclude:
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d' #이 timestring을 time으로 환산하여 인덱스를 관리합니다.
unit: days
unit_count: $unit_count
exclude:
하지만, 저장되고 있는 인덱스는 %Y.%m.%d / %Y%m%d / %Y-%m-%d 등 다양한 날짜 형식으로 지정되어 있었습니다.
예를 들면.. 아래와 같이 %Y.%m.%d / %Y%m%d 로 구성한 경우..
green open k8s-pod-prod-2022.08.18 z6w0_PwIQ1S6IjsA4L8W8Q 10 1 630059 0 531.1mb 265.4mb
green open k8s-pod-prod-2022.08.19 HEUy8cN1SYC2wUeuPetODA 10 1 558301 0 449mb 224.6mb
green open k8s-pod-prod-2022.08.16 ZoyH9HoIRP6LK-4fIAM2SA 10 1 546480 0 467.7mb 233.5mb
green open eden-prod-1-20220531 Pl3kJi_NSmWSWigEU0EFbQ 10 1 1673 0 15.7mb 7.8mb
green open k8s-pod-prod-2022.08.17 1M69qMeQRVadvXww778UAQ 10 1 681887 0 509mb 256mb
green open eden-prod-1-20220530 DRq2hBHcRRaP1-2cuCrAfg 10 1 1124 0 11.8mb 5.9mb
green open k8s-pod-prod-2022.08.15 berDJh8jS120CcBmIDMwrA 10 1 493365 0 411.1mb 205.4mb
green open eden-prod-1-20220414 JUnMXKXWRTmzNM2he-44jw 10 1 1340 0 20.9mb 10.4mb
green open eden-prod-1-20220415 5ffH1FX2Qgyzb1IWmK9CGA 10 1 2657 0 19mb 9.5mb
green open eden-prod-1-20220413 W4KTn0QMTiCgXMIIjXFJdA 10 1 771 0 15.4mb 7.7mb
green open eden-prod-1-20220418 yjQOe8PJToaK-NrYQSpMCw 10 1 2213 0 21.1mb 10.6mb
green open eden-prod-1-20220419 KjwD36IqT-qXi4J4sOyeFQ 10 1 1070 0 21mb 10.5mb
green open eden-prod-1-20220416 djrg81AlSWGRORnRBJMI0Q 10 1 350 0 3.8mb 1.9mb
ES 클러스터 구성시 전체 용량을 산정할 때 인덱스 보관주기도 함께 고려하여 용량을 산정합니다. 하지만, 지금처럼 curator가 동작하더라도 인덱스가 관리되지 않으면 현재는 문제가 없더라도 추후에는 데이터들이 전체 용량을 초과하는 문제가 발생할 수 있다고 판단하여 action_config 파일을 보완하였습니다.
인덱스 관리 보완 방안
아래와 같이 curator_auto.sh 을 수정하였습니다.
#!/bin/bash
escluster="eden-test-es"
url=$escluster".k9etool.io"
unit_count="30"
...
touch /home/eden/curator/action_config/$escluster"-action.yml"
cat <<EOF > /home/eden/curator/action_config/$escluster"-action.yml"
actions:
1:
action: delete_indices
options:
ignore_empty_list: True
timeout_override:
continue_if_exception: False
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: '^[a-z].*-'
exclude:
- filtertype: age
source: name
direction: older
timestring: '%Y.%m.%d'
unit: days
unit_count: $unit_count
exclude:
2: ## 추가 부분
action: delete_indices
options:
ignore_empty_list: True
timeout_override:
continue_if_exception: False
disable_action: False
filters:
- filtertype: pattern
kind: prefix
value: '^[a-z].*-'
exclude:
- filtertype: age
source: creation_date ## creation_date를 기준으로 인덱스 삭제
direction: older
unit: days
unit_count: $unit_count
exclude:
EOF
echo "0 5 * * * /home/eden/curator/scrtips/$escluster".sh" >> /home/eden/curator/log/$escluster".log"" >> /var/spool/cron/root
/home/eden/curator/scrtips/$escluster".sh" >> /home/eden/curator/log/$escluster".log""
2. 로 추가된 것처럼 creation_date를 기준으로 인덱스를 삭제하는 부분을 추가하였습니다.
creation_date는 인덱스가 생성된 날짜이고, 1번에 설정된 %Y.%m.%d 형식으로 지정하지 않은 인덱스들 중에 creation_date가 삭제될 날짜에 해당되는 인덱스들은 삭제하도록 처리하였습니다.
기존 날짜 기반으로 삭제하던 부분을 그대로 둔 이유는 creation_date는 인덱스 생성 날짜인데, reindexing을 하게 되면 creation_date가 reindexing한 날짜로 업데이트되어 내부 document는 예전 데이터여도 삭제가 되지 않을 수 있어서 그대로 두었습니다.
인덱스를 조회하면 아래와 같이 인덱스와 생성일자를 확인할 수 있습니다.
[eden@kep-cloudeng-mgmt1 curator]$ curl http://waas-prod-es.k9etool.io:9200/_cat/indices?h=i,creation.date.string
eden-cbt-20211209 2021-12-09T00:11:07.073Z
eden-prod-2-20220527 2022-05-27T00:04:57.054Z
dry-run으로 삭제될 인덱스 테스트 하였습니다.
2022-09-14 13:52:47,409 INFO Preparing Action ID: 1, "delete_indices"
2022-09-14 13:52:47,409 INFO Creating client object and testing connection
2022-09-14 13:52:47,411 INFO Instantiating client object
2022-09-14 13:52:47,411 INFO Testing client connectivity
2022-09-14 13:52:47,414 INFO Successfully created Elasticsearch client object with provided settings
2022-09-14 13:52:47,416 INFO Trying Action ID: 1, "delete_indices": No description given
2022-09-14 13:52:48,100 INFO DRY-RUN MODE. No changes will be made.
2022-09-14 13:52:48,100 INFO (CLOSED) indices may be shown that may not be acted on by action "delete_indices".
2022-09-14 13:52:48,100 INFO DRY-RUN: delete_indices: k8s-pod-cbt-2022.08.15 with arguments: {}
2022-09-14 13:52:48,100 INFO DRY-RUN: delete_indices: k8s-pod-prod-2022.08.15 with arguments: {}
2022-09-14 13:52:48,101 INFO Action ID: 1, "delete_indices" completed.
2022-09-14 13:52:48,101 INFO Preparing Action ID: 2, "delete_indices"
2022-09-14 13:52:48,101 INFO Creating client object and testing connection
2022-09-14 13:52:48,101 INFO Instantiating client object
2022-09-14 13:52:48,101 INFO Testing client connectivity
2022-09-14 13:52:48,105 INFO Successfully created Elasticsearch client object with provided settings
2022-09-14 13:52:48,107 INFO Trying Action ID: 2, "delete_indices": No description given
2022-09-14 13:52:48,857 INFO DRY-RUN MODE. No changes will be made.
2022-09-14 13:52:48,857 INFO (CLOSED) indices may be shown that may not be acted on by action "delete_indices".
2022-09-14 13:52:48,861 INFO DRY-RUN: delete_indices: eden-cbt-20211019 with arguments: {}
2022-09-14 13:52:48,861 INFO DRY-RUN: delete_indices: eden-cbt-20211022 with arguments: {}
2022-09-14 13:52:48,895 INFO Action ID: 2, "delete_indices" completed.
RegExr: Learn, Build, & Test RegEx
RegExr is an online tool to learn, build, & test Regular Expressions (RegEx / RegExp).
regexr.com
인덱스 조회시 creation date 확인하는 방법 : https://stackoverflow.com/questions/21872448/how-to-find-out-the-index-creation-date-in-elasticsearch
How to find out the index creation date in elasticsearch
How to find out the index created date in elastic search?
stackoverflow.com
[참고] elastic.co/guide/en/elasticsearch/client/curator/current/fe_source.html