ã¨ã ã¹ãªã¼ã¨ã³ã¸ãã¢ãªã³ã°ã°ã«ã¼ã AIã»æ©æ¢°å¦ç¿ãã¼ã ã§ã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ããã¦ããä¸æ(po3rin) ã§ããæ¤ç´¢ã¨Goã好ãã§ãã
ä»åã¯Elasticsearchã®ãã¼ã¸ã§ã³ãã¢ããã°ã¬ã¼ãããéã«ãElastic Cloudã®ãããã¤ã¡ã³ã管çãTerraformã«ç§»è¡ãã話ããã¾ãã
- ãªãTerraformã«ç§»è¡ããå¿ è¦ããã£ãã
- Terraformã¸ã®ç§»è¡
- Clusterè¨å®
- output
- Sudachiã®ãã¼ã¸ã§ã³ã¢ããã¨Extensionã®æ´æ°
- Reindexä½æ¥
- ã¾ã¨ã
ãªãTerraformã«ç§»è¡ããå¿ è¦ããã£ãã
Elastic Cloudã§ã¯ã³ã³ã½ã¼ã«ããUpgradeãã¿ã³ã§ãã¼ãªã³ã°ã¢ãããã¼ããå¯è½ã§ããã¨ã¦ã楽ã§ããã
ãããããã®ãã¿ã³ã®åé¡ã¯ãã¼ã«ããã¯ãç´ãã«ã§ããªãç¹ã«ããã¾ãããããã¤ã¡ã³ãã§é¸ã¹ãElasticsearchã®ãã¼ã¸ã§ã³ã¯ææ°å«ã3ã¤ãããªãã®ã§ãå¤ããããã¤ã¡ã³ããã移è¡ããã¨ãå ã®ãã¼ã¸ã§ã³ã«ç´ãã«æ»ãã¾ãããã¾ããAIã»æ©æ¢°å¦ç¿ãã¼ã ã§ã¯Sudachiãå©ç¨ãã¦ããã®ã§ãSudachiã®ãã¼ã¸ã§ã³ãä¸ããå¿ è¦ãããã¾ãããã®ãããåç´ã«Upgradeãã¿ã³ãæ¼ããã ãã§ã¯ãã©ã°ã¤ã³ã®ãã¼ã¸ã§ã³ã¨ã©ã¼ãåºã¦ãã¾ãã¾ãã
ãã®ãããå¼ç¤¾ã§ã¯ç§»è¡å ã®ãããã¤ã¡ã³ããæ°ããç«ã¦ã¦ãreindexãè¡ããæ°ãããããã¤ã¡ã³ããå®å®ãã¦åãåä½ç¢ºèªãããå¾ã«ãæ¤ç´¢APIããã¼ã¿æå ¥Batchã®åãå ã§ããURLãåãæ¿ããéç¨ãè¡ãªã£ã¦ãã¾ãã
ãã®ãããã¤ã¡ã³ããç«ã¦ãä½æ¥ãè·äººæã«ãªã£ã¦ãããä»ã®äººãä½æ¥ããã®ãå°é£ã«ãã¦ãã¾ããã
ä¾ãã°ãå¼ç¤¾ã§ã¯mappingã使ã£ã¦indexãä½æããã®ã§ãããããã©ã«ãã®è¨å®ã ã¨ããã¼ã¿æå ¥ããã¨èªåã§ç°¡æçãªmappingè¨å®ã®indexãä½æããã¦ãã¾ãã¾ãããã®ããããããã¤ã¡ã³ããç«ã¦ããã¯ã©ã¹ã¿ã®è¨å®ãå¤æ´ãããªã©ã®ããªããã¼ãªä½æ¥ãçºçãã¦ãã¾ããã
ããã§ãããã¤ã¡ã³ãä½ææã«ä½ãå¿ è¦ãªã®ããã³ã¼ãã§ç解ã§ããããã«ããä½æ¥ã³ã¹ããæ¸ããããã«ãTerraformãå°å ¥ãããã¨ã«ãã¾ããã
Terraformã¸ã®ç§»è¡
ä»åå®ç¾©ããTerraformã¯ä¸è¨ã«ãªãã¾ããä¸è¨ã¯ãµã³ãã«ã¨ãã¦QAç¨ã®æå°æ§æãæ³å®ãã¦ãã¾ãã
provider "ec" { timeout = "15m" verbose_file = "15m" } locals { sudachi_bundle_file_path = "es/sudachi/sudachi_bundles.zip" plugin_file_path = "es/sudachi/plugin/elasticsearch-8.8.1-analysis-sudachi-3.1.0.zip" dict_bundle_file_path = "es/dict/dict.zip" user_settings_override_file_path = "es/user_settings_yaml.yaml" } data "ec_stack" "latest" { version_regex = "8.8.1" region = "ap-northeast-1" } resource "ec_deployment_extension" "sudachi_dict_bundle" { name = "XXX-sudachi-dict-${local.env}-all-version" description = "Sudachiç¨ãã³ãã«ã主ã«v8.8.1ç¨ã«çæããããæ確ãªãã¼ã¸ã§ã³ã®ç¸ãã¯ãªãã" version = "*" extension_type = "bundle" file_path = local.sudachi_bundle_file_path file_hash = filebase64sha256(local.sudachi_bundle_file_path) } resource "ec_deployment_extension" "sudachi_plugin" { name = "XXX-sudachi-plugin-${local.env}-8.8.1" description = "Elasticsearch v8.8.1対å¿Sudachi Plugin" version = data.ec_stack.latest.version extension_type = "plugin" file_path = local.plugin_file_path file_hash = filebase64sha256(local.plugin_file_path) } resource "ec_deployment_extension" "XXX_dict_bundle" { name = "XXX-dict-bundle-${local.env}-all-version" description = "Sudachi以å¤ã®dict" version = "*" extension_type = "bundle" file_path = local.dict_bundle_file_path file_hash = filebase64sha256(local.dict_bundle_file_path) } resource "ec_deployment" "XXX-deployment" { name = local.deployment_name region = data.ec_stack.latest.region version = data.ec_stack.latest.version deployment_template_id = local.deployment_template_id elasticsearch = { config = { plugins = ["analysis-icu", "analysis-kuromoji"] user_settings_yaml = file(local.user_settings_override_file_path) }, hot = { autoscaling = {} size = local.memory_size zone_count = local.zone_count }, extension = [ { name = ec_deployment_extension.sudachi_dict_bundle.name type = "bundle" version = data.ec_stack.latest.version url = ec_deployment_extension.sudachi_dict_bundle.url }, { name = ec_deployment_extension.XXX_dict_bundle.name type = "bundle" version = data.ec_stack.latest.version url = ec_deployment_extension.XXX_dict_bundle.url }, { name = ec_deployment_extension.sudachi_plugin.name type = "plugin" version = data.ec_stack.latest.version url = ec_deployment_extension.sudachi_plugin.url }, ] } kibana = { size = "1g" zone_count = 1 } }
ãã¤ã³ããç´¹ä»ãã¾ãã
ExtensionãTerraformã管çãã
ExtensionãTerraformã§ã¢ãããã¼ãããããã«ãã¦ãã¾ãã
ä»ã¾ã§ã¯Extensionã¯èªåã§zipå§ç¸®ãã¦ã¢ãããã¼ãããéç¨ãè¡ãªã£ã¦ãã¾ãããExtensionã«ã¯è¾æ¸ãã¡ã¤ã«ãSudachiãªã©ã®Pluginãå«ã¾ãã¾ãã
Extensionãèªåéã§ã¢ãããã¼ããã¦ããã¨ãã©ã®Extensionãã©ã®ãããã¤ã¡ã³ãã§ä½¿ããã¦ããããã±ã£ã¨è¦åããã¾ãã(ãããã¤ã¡ã³ããä¸åä¸åè¦ã¦ãã£ã¦ä½¿ããã¦ãããã確èªããå¿ è¦ããã)ãå®éã«å¤ãExtensionãElastic Cloudã«æ®ã£ã¦ãã¾ã£ã¦ããã¨ããç¶æ³ãçºçããExtensionã®ç®¡çã³ã¹ããä¸ãã£ã¦ãã¾ããã
ã¿ã¤ã ã¢ã¦ãã®å®ç¾©
Terraform Providerã®å®ç¾©ã®ä¸ã§timeoutãå®ç¾©ã§ãã¾ãã
provider "ec" { timeout = "15m" verbose_file = "15m" }
ãããã¤ã¡ã³ããç«ã¡ä¸ããã®ã¯æéã®ãããå¦çãªã®ã§ãtimeoutãè¨å®ããªãã¦ã¯ããã¾ãããããã©ã«ãã ã¨timeout
ã1m
ã¨ã ãã¶çãã®ã§å®å®ãã¦ç«ã¡ä¸ãããå ´åã¯timeoutã¯å¿
é ã®è¨å®ã«ãªãã¾ãã
verbose_file
ã¯åAPIå¼ã³åºãã®timeoutã®è¨å®ã§ããExtensionãã¢ãããã¼ãããéã«ãã¡ã¤ã«ã大ããã¨è¥å¹²æéããããã®ã§ããããé·ãã«è¨å®ãã¦ãããæ¹ãè¯ãã§ãããã
Clusterè¨å®
config.user_settings_yaml
ãã£ã¼ã«ãã§ãããã©ã«ãã®è¨å®ãä»»æã®è¨å®ã§ä¸æ¸ãã§ãã¾ããå¼ç¤¾ã§ã¯ãã¼ã¿æå
¥æã®indexèªåä½æãé¿ãããã®ã§ã¯ã©ã¹ã¿ã®è¨å®ã§ããaction.auto_create_index
ãfalse
ã«ãã¦ãã¾ãã
action.auto_create_index: false
ãã®ä»è¨å®ã§ããé ç®ã¯ä¸è¨ãã覧ãã ããã
output
ãã¹ã¯ã¼ããªã©ã®ã¯ã¬ãã³ã·ã£ã«ã¯å®è¡æã«åå¾ã§ããããã«output.tf
ã«å®ç¾©ãã¦ããã¾ããå¾ããã³ã³ã½ã¼ã«ã§ãã¹ã¯ã¼ããåå¾ã§ããªãã®ã§ãããã§ã®ã¢ã¦ããããå®ç¾©ã¯å¿
è¦ã§ãã
output "credential_name" { value = ec_deployment.myapp-deployment.elasticsearch_username } output "credential_password" { value = nonsensitive(ec_deployment.myapp-deployment.elasticsearch_password) } output "endpoint" { value = ec_deployment.myapp-deployment.elasticsearch.https_endpoint }
Sudachiã®ãã¼ã¸ã§ã³ã¢ããã¨Extensionã®æ´æ°
Terraformã§ã¢ãããã¼ãããExtensionãæ´æ°ãã¾ãã
Sudachi Pluginã®æ´æ°
Sudachiã®Pluginã¯Elasticsearchã«ãã¼ã¸ã§ã³ãåãããå¿ è¦ãããã¾ãããã®ãããSudachiã®ãªãã¸ããªãã対象ãã¼ã¸ã§ã³ã®Sudachi Pluginããã¦ã³ãã¼ããã¦ããã¾ããããã対象ãã¼ã¸ã§ã³ã®Pluginãã¾ã ãªãªã¼ã¹ããã¦ããªãå ´åã¯ãã³ã¼ãããç´æ¥ãã«ããã¾ããä»åã®ç§»è¡ã§ã¯å¯¾è±¡ãã¼ã¸ã§ã³ããªãªã¼ã¹ããã¦ããã®ã§ãã®ã¾ã¾å©ç¨ãã¾ããã
詳細ã¯Sudachi Pluginã®ãªãã¸ããªãã覧ãã ããã
ã«ã¹ã¿ã è¾æ¸ã¨ã·ããã è¾æ¸ã®æ´æ°
Sudachi Pluginãæ´æ°ãããã«ã¹ã¿ã è¾æ¸ãæ´æ°ãã¾ãããã¡ããå¼ç¤¾ã§ã¯æ§ã ãªç¬èªãã¼ã«ã使ã£ã¦ä»¥å使ã£ã¦ããkuromojiè¾æ¸ããSudachiè¾æ¸ãä½æãã¦ãã¾ãã詳ããã¯ç§ãæ¸ããä¸è¨ã®ããã°ãã覧ãã ããã
Reindexä½æ¥
Elastic Cloudã§Deploymentãç«ã¡ä¸ãã£ããReindexä½æ¥ã§ãã
Snapshot Restoreã¨ããæ¹æ³ãããã¾ããããã¡ãã¯indexæ§é ãã¨Restoreãããã®ã§ãå¤ãSudachiã®åå²çµæãæ®ã£ã¦ãã¾ããæ¤ç´¢ã«å¼ã£æãããªããªã£ã¦ãã¾ãåèªãåºã¦ãã¾ãããã®ãããReindexã§ãã¼ã¿ã®ç§»è¡ããã¾ãã
ã¾ãã¯æ°ããDeploymentã«indexãä½æãã¾ããå¼ç¤¾ã§ã¯eskeeperã¨ãããã¼ã«ã§aliasãindexã管çãã¦ããã®ã§ãã®ãã¡ã¤ã«ãå¤æ´ãã¦applyããã°å®äºã§ããä¸è¨ã¯eskeeperã§indexãä½æããä¾ã§ããAliasãeskeeperã§åãæ¿ããããããã«ãªã£ã¦ããã®ã§ãæ°ããIndexãä½æããå ´åã¯ç¡åæ¢ã§åãå ãåãæ¿ããããããã«ãªã£ã¦ãã¾ãã
index: - name: docs-v0.1 mapping: es/mapping/docs.json status: close alias: - name: docs index: - docs-v0.1
eskeeperã®ãªãã¸ããªã¯ãã¡ãã§ãã
Reindex対象ã®æ°ããDeploymentã«ã¯ã¾ã APIãåãã¦ããªãç¶æ ãªã®ã§ãæ¬çªå½±é¿ãçºçãããè² è·ãæ°ã«ããã«Reindexã§ãã¾ãã
ä»ã¯æç´ã«ãã¼ã«ã«ããAPIãå©ãéç¨ã«ãªã£ã¦ããã®ã§ããããä»å¾ä¸æãå±äººåãæé¤ãã¦ããããã¨èãã¦ãã¾ãã
ã¾ã¨ã
ä»åã¯Elasticsearch Deployment管çãTerraformã«ç§»è¡ããã話ããã¾ãããä½æ¥ã³ã¹ãã®åæ¸ãå±äººåã®æé¤ã®è¦³ç¹ã§Terraformåã¯ããããã§ããPluginã®ãã¼ã¸ã§ã³æ´æ°ãä¸ç·ã«è¡ãéã«ã¯Terraformã§Extensionã管çã§ããã¨ãã便å©ã§ãã
ä»å¾ããã«æ¤ç´¢ã¨ã³ã¸ã³éç¨æ¹åãè¡ãªã£ã¦ããããã¨æãã¾ãï¼
We are hiring !!
AIã»æ©æ¢°å¦ç¿ãã¼ã ã§ã¯æ å ±æ¤ç´¢/æ¨è¦ã好ããªã¨ã³ã¸ãã¢ãåéä¸ã§ããã«ã¸ã¥ã¢ã«é¢è«ã§ãã詳ããã話ããã¾ãããï¼