1#!/usr/bin/env bash 2# Copyright 2021 The gRPC Authors 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15set -ex 16 17# Enter the gRPC repo root. 18cd "$(dirname "$0")/../../.." 19 20source tools/internal_ci/helper_scripts/prepare_build_linux_rc 21 22 23# Environment variables to select repos and branches for various repos. 24# You can edit these lines if you want to run from a fork. 25GRPC_CORE_REPO=grpc/grpc 26GRPC_CORE_GITREF=master 27GRPC_DOTNET_REPO=grpc/grpc-dotnet 28GRPC_DOTNET_GITREF=master 29GRPC_GO_REPO=grpc/grpc-go 30GRPC_GO_GITREF=master 31GRPC_JAVA_REPO=grpc/grpc-java 32GRPC_JAVA_GITREF=master 33GRPC_NODE_REPO=grpc/grpc-node 34GRPC_NODE_GITREF=master 35TEST_INFRA_REPO=grpc/test-infra 36TEST_INFRA_GITREF=master 37 38# This is to ensure we can push and pull images from gcr.io. We do not 39# necessarily need it to run load tests, but will need it when we employ 40# pre-built images in the optimization. 41gcloud auth configure-docker 42 43# Connect to benchmarks-prod2 cluster. 44gcloud config set project grpc-testing 45gcloud container clusters get-credentials benchmarks-prod2 \ 46 --zone us-central1-b --project grpc-testing 47 48# Set up environment variables. 49LOAD_TEST_PREFIX="${KOKORO_BUILD_INITIATOR}" 50# BEGIN differentiate experimental configuration from master configuration. 51if [[ "${KOKORO_BUILD_INITIATOR%%-*}" == kokoro && "${KOKORO_GITHUB_COMMIT_URL%/*}" == "https://github.com/grpc/grpc/commit" ]]; then 52 # Use "official" BQ tables only for builds initiated by Kokoro and running 53 # from grpc/grpc. These results show up in the "official" public dashboard. 54 BIGQUERY_TABLE_8CORE=e2e_benchmarks.ci_master_results_8core 55 BIGQUERY_TABLE_32CORE=e2e_benchmarks.ci_master_results_32core 56else 57 # Use experimental BQ tables otherwise. 58 BIGQUERY_TABLE_8CORE=e2e_benchmarks.experimental_results 59 BIGQUERY_TABLE_32CORE=e2e_benchmarks.experimental_results_32core 60fi 61# END differentiate experimental configuration from master configuration. 62CLOUD_LOGGING_URL="https://source.cloud.google.com/results/invocations/${KOKORO_BUILD_ID}" 63PREBUILT_IMAGE_PREFIX="gcr.io/grpc-testing/e2etest/prebuilt/${LOAD_TEST_PREFIX}" 64UNIQUE_IDENTIFIER="$(date +%Y%m%d%H%M%S)" 65ROOT_DIRECTORY_OF_DOCKERFILES="../test-infra/containers/pre_built_workers/" 66# Head of the workspace checked out by Kokoro. 67GRPC_COMMIT="$(git show --format="%H" --no-patch)" 68# Prebuilt workers for core languages are always built from grpc/grpc. 69if [[ "${KOKORO_GITHUB_COMMIT_URL%/*}" == "https://github.com/grpc/grpc/commit" ]]; then 70 GRPC_CORE_COMMIT="${KOKORO_GIT_COMMIT}" 71else 72 GRPC_CORE_COMMIT="$(git ls-remote -h "https://github.com/${GRPC_CORE_REPO}.git" "${GRPC_CORE_GITREF}" | cut -f1)" 73fi 74 75GRPC_DOTNET_COMMIT="$(git ls-remote "https://github.com/${GRPC_DOTNET_REPO}.git" "${GRPC_DOTNET_GITREF}" | cut -f1)" 76GRPC_GO_COMMIT="$(git ls-remote "https://github.com/${GRPC_GO_REPO}.git" "${GRPC_GO_GITREF}" | cut -f1)" 77GRPC_JAVA_COMMIT="$(git ls-remote "https://github.com/${GRPC_JAVA_REPO}.git" "${GRPC_JAVA_GITREF}" | cut -f1)" 78GRPC_NODE_COMMIT="$(git ls-remote "https://github.com/${GRPC_NODE_REPO}.git" "${GRPC_NODE_GITREF}" | cut -f1)" 79# Kokoro jobs run on dedicated pools. 80DRIVER_POOL=drivers-ci 81WORKER_POOL_8CORE=workers-c2-8core-ci 82# c2-standard-30 is the closest machine spec to 32 core there is 83WORKER_POOL_32CORE=workers-c2-30core-ci 84# Prefix for log URLs in cnsviewer. 85LOG_URL_PREFIX="http://cnsviewer/placer/prod/home/kokoro-dedicated/build_artifacts/${KOKORO_BUILD_ARTIFACTS_SUBDIR}/github/grpc/" 86 87# Clone test-infra repository and build all tools. 88mkdir ../test-infra 89pushd ../test-infra 90git clone "https://github.com/${TEST_INFRA_REPO}.git" . 91git checkout "${TEST_INFRA_GITREF}" 92make all-tools 93popd 94 95# Build test configurations. 96buildConfigs() { 97 local -r pool="$1" 98 local -r table="$2" 99 shift 2 100 tools/run_tests/performance/loadtest_config.py "$@" \ 101 -t ./tools/run_tests/performance/templates/loadtest_template_prebuilt_all_languages.yaml \ 102 -s driver_pool="${DRIVER_POOL}" -s driver_image= \ 103 -s client_pool="${pool}" -s server_pool="${pool}" \ 104 -s big_query_table="${table}" -s timeout_seconds=900 \ 105 -s prebuilt_image_prefix="${PREBUILT_IMAGE_PREFIX}" \ 106 -s prebuilt_image_tag="${UNIQUE_IDENTIFIER}" \ 107 -a ci_buildNumber="${KOKORO_BUILD_NUMBER}" \ 108 -a ci_buildUrl="${CLOUD_LOGGING_URL}" \ 109 -a ci_jobName="${KOKORO_JOB_NAME}" \ 110 -a ci_gitCommit="${GRPC_COMMIT}" \ 111 -a ci_gitCommit_core="${GRPC_CORE_COMMIT}" \ 112 -a ci_gitCommit_dotnet="${GRPC_DOTNET_COMMIT}" \ 113 -a ci_gitCommit_go="${GRPC_GO_COMMIT}" \ 114 -a ci_gitCommit_java="${GRPC_JAVA_COMMIT}" \ 115 -a ci_gitActualCommit="${KOKORO_GIT_COMMIT}" \ 116 --prefix="${LOAD_TEST_PREFIX}" -u "${UNIQUE_IDENTIFIER}" -u "${pool}" \ 117 -a pool="${pool}" --category=scalable \ 118 --allow_client_language=c++ --allow_server_language=c++ \ 119 --allow_server_language=node \ 120 -o "loadtest_with_prebuilt_workers_${pool}.yaml" 121} 122 123# Add languages 124declare -a configLangArgs8core=() 125declare -a configLangArgs32core=() 126declare -a runnerLangArgs=() 127 128# c++ 129configLangArgs8core+=( -l c++ ) 130configLangArgs32core+=( -l c++ ) 131runnerLangArgs+=( -l "cxx:${GRPC_CORE_REPO}:${GRPC_CORE_COMMIT}" ) 132 133# dotnet 134configLangArgs8core+=( -l dotnet ) 135configLangArgs32core+=( -l dotnet ) 136runnerLangArgs+=( -l "dotnet:${GRPC_DOTNET_REPO}:${GRPC_DOTNET_COMMIT}" ) 137 138# # go 139configLangArgs8core+=( -l go ) 140configLangArgs32core+=( -l go ) 141runnerLangArgs+=( -l "go:${GRPC_GO_REPO}:${GRPC_GO_COMMIT}" ) 142 143# java 144configLangArgs8core+=( -l java ) 145configLangArgs32core+=( -l java ) 146runnerLangArgs+=( -l "java:${GRPC_JAVA_REPO}:${GRPC_JAVA_COMMIT}" ) 147 148# node 149configLangArgs8core+=( -l node ) # 8-core only. 150runnerLangArgs+=( -l "node:${GRPC_NODE_REPO}:${GRPC_NODE_COMMIT}" ) 151 152# python 153configLangArgs8core+=( -l python ) # 8-core only. 154runnerLangArgs+=( -l "python:${GRPC_CORE_REPO}:${GRPC_CORE_COMMIT}" ) 155 156# ruby 157configLangArgs8core+=( -l ruby ) # 8-core only. 158runnerLangArgs+=( -l "ruby:${GRPC_CORE_REPO}:${GRPC_CORE_COMMIT}" ) 159 160buildConfigs "${WORKER_POOL_8CORE}" "${BIGQUERY_TABLE_8CORE}" "${configLangArgs8core[@]}" 161buildConfigs "${WORKER_POOL_32CORE}" "${BIGQUERY_TABLE_32CORE}" "${configLangArgs32core[@]}" 162 163# Delete prebuilt images on exit. 164deleteImages() { 165 echo "deleting images on exit" 166 ../test-infra/bin/delete_prebuilt_workers \ 167 -p "${PREBUILT_IMAGE_PREFIX}" \ 168 -t "${UNIQUE_IDENTIFIER}" 169} 170trap deleteImages EXIT 171 172# Build and push prebuilt images for running tests. 173time ../test-infra/bin/prepare_prebuilt_workers "${runnerLangArgs[@]}" \ 174 -p "${PREBUILT_IMAGE_PREFIX}" \ 175 -t "${UNIQUE_IDENTIFIER}" \ 176 -r "${ROOT_DIRECTORY_OF_DOCKERFILES}" 177 178# Run tests. 179time ../test-infra/bin/runner \ 180 -i "loadtest_with_prebuilt_workers_${WORKER_POOL_8CORE}.yaml" \ 181 -i "loadtest_with_prebuilt_workers_${WORKER_POOL_32CORE}.yaml" \ 182 -log-url-prefix "${LOG_URL_PREFIX}" \ 183 -polling-interval 5s \ 184 -delete-successful-tests \ 185 -c "${WORKER_POOL_8CORE}:2" -c "${WORKER_POOL_32CORE}:2" \ 186 -o "runner/sponge_log.xml" 187