From 43a3c8beaa1e6553a318939b050566f082742160 Mon Sep 17 00:00:00 2001 From: rodrigozhou Date: Mon, 20 Nov 2023 13:03:20 -0600 Subject: [PATCH] Add parent execution search attributes to ES mappings --- .../visibility/index_template_v7.json | 2 +- .../versioned/v6/index_template_v7.json | 93 +++++++++++++++++++ .../visibility/versioned/v6/upgrade.sh | 57 ++++++++++++ 3 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 schema/elasticsearch/visibility/versioned/v6/index_template_v7.json create mode 100755 schema/elasticsearch/visibility/versioned/v6/upgrade.sh diff --git a/schema/elasticsearch/visibility/index_template_v7.json b/schema/elasticsearch/visibility/index_template_v7.json index 5c7e0072a06..4efa0d16322 120000 --- a/schema/elasticsearch/visibility/index_template_v7.json +++ b/schema/elasticsearch/visibility/index_template_v7.json @@ -1 +1 @@ -versioned/v5/index_template_v7.json \ No newline at end of file +./versioned/v6/index_template_v7.json \ No newline at end of file diff --git a/schema/elasticsearch/visibility/versioned/v6/index_template_v7.json b/schema/elasticsearch/visibility/versioned/v6/index_template_v7.json new file mode 100644 index 00000000000..55fded9476d --- /dev/null +++ b/schema/elasticsearch/visibility/versioned/v6/index_template_v7.json @@ -0,0 +1,93 @@ +{ + "order": 0, + "index_patterns": ["temporal_visibility_v1*"], + "settings": { + "index": { + "number_of_shards": "1", + "number_of_replicas": "0", + "auto_expand_replicas": "0-2", + "search.idle.after": "365d", + "sort.field": ["CloseTime", "StartTime", "RunId"], + "sort.order": ["desc", "desc", "desc"], + "sort.missing": ["_first", "_first", "_first"] + } + }, + "mappings": { + "dynamic": "false", + "properties": { + "NamespaceId": { + "type": "keyword" + }, + "TemporalNamespaceDivision": { + "type": "keyword" + }, + "WorkflowId": { + "type": "keyword" + }, + "RunId": { + "type": "keyword" + }, + "WorkflowType": { + "type": "keyword" + }, + "StartTime": { + "type": "date_nanos" + }, + "ExecutionTime": { + "type": "date_nanos" + }, + "CloseTime": { + "type": "date_nanos" + }, + "ExecutionDuration": { + "type": "long" + }, + "ExecutionStatus": { + "type": "keyword" + }, + "TaskQueue": { + "type": "keyword" + }, + "TemporalChangeVersion": { + "type": "keyword" + }, + "BatcherNamespace": { + "type": "keyword" + }, + "BatcherUser": { + "type": "keyword" + }, + "BinaryChecksums": { + "type": "keyword" + }, + "HistoryLength": { + "type": "long" + }, + "StateTransitionCount": { + "type": "long" + }, + "TemporalScheduledStartTime": { + "type": "date_nanos" + }, + "TemporalScheduledById": { + "type": "keyword" + }, + "TemporalSchedulePaused": { + "type": "boolean" + }, + "HistorySizeBytes": { + "type": "long" + }, + "BuildIds": { + "type": "keyword" + }, + "ParentWorkflowId": { + "type": "keyword" + }, + "ParentRunId": { + "type": "keyword" + } + } + }, + "aliases": {} +} diff --git a/schema/elasticsearch/visibility/versioned/v6/upgrade.sh b/schema/elasticsearch/visibility/versioned/v6/upgrade.sh new file mode 100755 index 00000000000..13b634bea63 --- /dev/null +++ b/schema/elasticsearch/visibility/versioned/v6/upgrade.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +set -eu -o pipefail + +# Prerequisites: +# - jq +# - curl + +# Input parameters. +: "${ES_SCHEME:=http}" +: "${ES_SERVER:=127.0.0.1}" +: "${ES_PORT:=9200}" +: "${ES_USER:=}" +: "${ES_PWD:=}" +: "${ES_VERSION:=v7}" +: "${ES_VIS_INDEX_V1:=temporal_visibility_v1_dev}" +: "${AUTO_CONFIRM:=}" +: "${SLICES_COUNT:=auto}" + +es_endpoint="${ES_SCHEME}://${ES_SERVER}:${ES_PORT}" + +echo "=== Step 0. Sanity check if Elasticsearch index is accessible ===" + +if ! curl --silent --fail --user "${ES_USER}":"${ES_PWD}" "${es_endpoint}/${ES_VIS_INDEX_V1}/_stats/docs" --write-out "\n"; then + echo "Elasticsearch index ${ES_VIS_INDEX_V1} is not accessible at ${es_endpoint}." + exit 1 +fi + +echo "=== Step 1. Add new builtin search attributes ===" + +new_mapping=' +{ + "properties": { + "ParentWorkflowId": { + "type": "keyword" + }, + "ParentRunId": { + "type": "keyword" + } + } +} +' + +if [ -z "${AUTO_CONFIRM}" ]; then + read -p "Add new builtin search attributes to the index ${ES_VIS_INDEX_V1}? (N/y)" -n 1 -r + echo +else + REPLY="y" +fi +if [ "${REPLY}" = "y" ]; then + curl --silent --fail --user "${ES_USER}":"${ES_PWD}" -X PUT "${es_endpoint}/${ES_VIS_INDEX_V1}/_mapping" -H "Content-Type: application/json" --data-binary "$new_mapping" | jq + # Wait for mapping changes to go through. + until curl --silent --user "${ES_USER}":"${ES_PWD}" "${es_endpoint}/_cluster/health/${ES_VIS_INDEX_V1}" | jq --exit-status '.status=="green" | .'; do + echo "Waiting for Elasticsearch index ${ES_VIS_INDEX_V1} become green." + sleep 1 + done +fi