Skip to content

Commit

Permalink
CI: Add Jenkins configuration for running benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
karmi committed May 25, 2020
1 parent 08d9a17 commit 649ae1b
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .ci/jobs/elastic+elasticsearch-ruby+benchmarks.yml
@@ -0,0 +1,17 @@
---
- job:
project-type: freestyle
node: linux && immutable
name: elastic+elasticsearch-ruby+benchmarks
display-name: 'elastic / elasticsearch-ruby # benchmarks'
description: Client benchmarks for the Ruby client
parameters:
- string: { name: branch_specifier, default: refs/heads/benchmarks }
triggers:
- timed: "H H/12 * * *"
vault:
role_id: "ddbd0d44-0e51-105b-177a-c8fdfd445126"
builders:
- shell: |-
#!/usr/local/bin/runbld
.ci/run-benchmarks
40 changes: 40 additions & 0 deletions .ci/run-benchmarks
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
#
# Licensed to Elasticsearch B.V. under one or more agreements.
# Elasticsearch B.V. licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.

set -euxo pipefail

export WORKSPACE=${WORKSPACE:-$PWD}

COMMIT="$(git rev-parse --short HEAD)"

export CLIENT_IMAGE="eu.gcr.io/elastic-clients/elasticsearch-ruby:$COMMIT"
export CLIENT_BRANCH='master'
export CLIENT_COMMAND='. /environment.sh && cd benchmarks && bundle exec ruby bin/run.rb'

set +x
echo -e "\033[1mBuilding Docker image for commit [$COMMIT]\033[0m"
set -x
docker build --file benchmarks/Dockerfile --tag elastic/elasticsearch-ruby .

set +u
if [[ -n $JENKINS_URL ]]; then
set +x
VAULT_TOKEN=$(vault write -field=token auth/approle/login role_id="$VAULT_ROLE_ID" secret_id="$VAULT_SECRET_ID")
export VAULT_TOKEN
set -x
fi
set -u

mkdir -p "$WORKSPACE/tmp"
vault read -field=gcp_service_account secret/clients-team/benchmarking > "$WORKSPACE/tmp/credentials.json"
gcloud auth activate-service-account --key-file "$WORKSPACE/tmp/credentials.json"

gcloud auth configure-docker --quiet
gcloud auth print-access-token | docker login -u oauth2accesstoken --password-stdin https://eu.gcr.io
docker tag elastic/elasticsearch-ruby "$CLIENT_IMAGE"
docker push "$CLIENT_IMAGE"

exec "$WORKSPACE/.ci/scripts/run-benchmarks.sh"
73 changes: 73 additions & 0 deletions .ci/scripts/run-benchmarks.sh
@@ -0,0 +1,73 @@
#!/usr/bin/env bash
#
# Licensed to Elasticsearch B.V. under one or more agreements.
# Elasticsearch B.V. licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.
#
# Runner for the client benchmarks.
#
# Export the following environment variables when running the script:
#
# * CLIENT_IMAGE
# * CLIENT_BRANCH
# * CLIENT_COMMAND
#
# The WORKSPACE environment variable is automatically set on Jenkins.
#
# The VAULT_ADDR is automatically set on Jenkins.

set -euxo pipefail

mkdir -p "$WORKSPACE/tmp"

vault read -field=gcp_service_account secret/clients-team/benchmarking > "$WORKSPACE/tmp/credentials.json"

export GOOGLE_CLOUD_KEYFILE_JSON="$WORKSPACE/tmp/credentials.json"
export GOOGLE_APPLICATION_CREDENTIALS="$WORKSPACE/tmp/credentials.json"

set +x
report_url="$(vault read -field=reporting_url secret/clients-team/benchmarking)"
report_password="$(vault read -field=reporting_password secret/clients-team/benchmarking)"
export ELASTICSEARCH_REPORT_URL="$report_url"
export ELASTICSEARCH_REPORT_PASSWORD="$report_password"

export TF_VAR_reporting_url="$ELASTICSEARCH_REPORT_URL"
export TF_VAR_reporting_password="$ELASTICSEARCH_REPORT_PASSWORD"
set -x

TERRAFORM=$(command -v terraform)
GCLOUD=$(command -v gcloud)

DESTROY=${DESTROY:-yes}

function cleanup {
if [[ $DESTROY != "no" ]]; then
$TERRAFORM destroy --auto-approve --input=false --var client_image="$CLIENT_IMAGE"
fi
}

trap cleanup INT TERM EXIT;

if [[ ! -d "$WORKSPACE/tmp/elasticsearch-clients-benchmarks" ]]; then
git clone --depth 1 git@github.com:elastic/elasticsearch-clients-benchmarks.git "$WORKSPACE/tmp/elasticsearch-clients-benchmarks"
fi

cd "$WORKSPACE/tmp/elasticsearch-clients-benchmarks/terraform/gcp"

$TERRAFORM init --input=false
$TERRAFORM apply --auto-approve --input=false --var client_image="$CLIENT_IMAGE"

set +x
echo -e "\033[1mWaiting for [$($TERRAFORM output runner_instance_name)] to be ready...\033[0m"
until $GCLOUD compute --project 'elastic-clients' ssh "$($TERRAFORM output runner_instance_name)" --zone='europe-west1-b' --command="sudo su - runner -c 'docker container inspect benchmarks-data'" &> /dev/null; do sleep 1; done;

echo -e "\nRunning benchmarks for [$CLIENT_IMAGE]\n"
set -x

$GCLOUD compute --project 'elastic-clients' ssh "$($TERRAFORM output runner_instance_name)" \
--zone='europe-west1-b' \
--ssh-flag='-t' \
--command="\
CLIENT_BRANCH=$CLIENT_BRANCH \
CLIENT_BENCHMARK_ENVIRONMENT=production \
/home/runner/runner.sh \"$CLIENT_COMMAND\""

0 comments on commit 649ae1b

Please sign in to comment.