Skip to content

Commit 97994dc

Browse files
committed
Set number of replicas to 0 in integration test ES deployment
1 parent c910583 commit 97994dc

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

.buildkite/scripts/steps/ess.sh

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function ess_up() {
88
local STACK_VERSION=$1
99
local STACK_BUILD_ID=${2:-""}
1010
local ESS_REGION=${3:-"gcp-us-west2"}
11-
11+
1212
if [ -z "$STACK_VERSION" ]; then
1313
echo "Error: Specify stack version: ess_up [stack_version]" >&2
1414
return 1
@@ -17,8 +17,8 @@ function ess_up() {
1717
BUILDKITE_BUILD_CREATOR="${BUILDKITE_BUILD_CREATOR:-"$(get_git_user_email)"}"
1818
BUILDKITE_BUILD_NUMBER="${BUILDKITE_BUILD_NUMBER:-"0"}"
1919
BUILDKITE_PIPELINE_SLUG="${BUILDKITE_PIPELINE_SLUG:-"elastic-agent-integration-tests"}"
20-
21-
pushd "${TF_DIR}"
20+
21+
pushd "${TF_DIR}"
2222
terraform init
2323
terraform apply \
2424
-auto-approve \
@@ -44,7 +44,7 @@ function ess_down() {
4444
local ESS_REGION=${1:-"gcp-us-west2"}
4545
local WORKSPACE=$(git rev-parse --show-toplevel)
4646
local TF_DIR="${WORKSPACE}/test_infra/ess/"
47-
47+
4848
pushd "${TF_DIR}"
4949
terraform init
5050
terraform destroy -auto-approve \
@@ -54,17 +54,57 @@ function ess_down() {
5454

5555
function get_git_user_email() {
5656
if ! git rev-parse --is-inside-work-tree &>/dev/null; then
57-
echo "unknown"
57+
echo "unknown"
5858
return
5959
fi
6060

6161
local email
6262
email=$(git config --get user.email)
63-
63+
6464
if [ -z "$email" ]; then
65-
echo "unknown"
65+
echo "unknown"
6666
else
6767
echo "$email"
6868
fi
6969
}
7070

71+
function set_default_number_of_replicas() {
72+
if [ -z "$ELASTICSEARCH_HOST" ]; then
73+
echo "Error: Elasticsearch hostname not specified via ELASTICSEARCH_HOST environment variable"
74+
return 3
75+
fi
76+
77+
if [ -z "$ELASTICSEARCH_USERNAME" ]; then
78+
echo "Error: Elasticsearch username not specified via ELASTICSEARCH_USERNAME environment variable"
79+
return 4
80+
fi
81+
82+
if [ -z "$ELASTICSEARCH_PASSWORD" ]; then
83+
echo "Error: Elasticsearch password not specified via ELASTICSEARCH_PASSWORD environment variable"
84+
return 5
85+
fi
86+
87+
resp=$(curl \
88+
--fail-with-body \
89+
-X PUT \
90+
-u "${ELASTICSEARCH_USERNAME}:${ELASTICSEARCH_PASSWORD}" \
91+
-H "Content-Type: application/json" \
92+
-d '{
93+
"index_patterns": ["*"],
94+
"template": {
95+
"settings": {
96+
"number_of_replicas": 0
97+
}
98+
}
99+
}'\
100+
"https://${ELASTICSEARCH_HOST}/_index_template/global_default_replicas")
101+
102+
echo "$resp"
103+
104+
# Parse response body for any errors
105+
num_errors=$(echo "$resp" | jq '.items[].statusCode | select(.>=400)' | wc -l)
106+
if [ "$num_errors" -gt 0 ]; then
107+
echo "$resp"
108+
return 6
109+
fi
110+
}

.buildkite/scripts/steps/ess_start.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ESS_REGION="${ESS_REGION:-gcp-us-west2}"
1515

1616
ess_up "$STACK_VERSION" "$STACK_BUILD_ID" "$ESS_REGION"
1717

18+
set_default_number_of_replicas
1819
preinstall_fleet_packages
1920

2021
echo "ES_HOST: ${ELASTICSEARCH_HOST}"

0 commit comments

Comments
 (0)