|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The Cockroach Authors. |
| 4 | +# |
| 5 | +# Use of this software is governed by the CockroachDB Software License |
| 6 | +# included in the /LICENSE file. |
| 7 | + |
| 8 | +set -exuo pipefail |
| 9 | + |
| 10 | +export ROACHPROD_DISABLED_PROVIDERS=aws,azure,ibm |
| 11 | +export ROACHPROD_DISABLE_UPDATE_CHECK=true |
| 12 | + |
| 13 | +export ROACHPROD_GCE_DEFAULT_SERVICE_ACCOUNT=${GOOGLE_SERVICE_ACCOUNT:-teamcity-pua@cockroach-ephemeral.iam.gserviceaccount.com} |
| 14 | +export ROACHPROD_GCE_DEFAULT_PROJECT=${GOOGLE_PROJECT:-cockroach-ephemeral} |
| 15 | + |
| 16 | +export ROACHPROD_DNS=${ROACHPROD_DNS:-roachprod.crdb.io} |
| 17 | +export ROACHPROD_GCE_DNS_ZONE=${ROACHPROD_GCE_DNS_ZONE:-roachprod} |
| 18 | +export ROACHPROD_GCE_DNS_DOMAIN=${ROACHPROD_GCE_DNS_DOMAIN:-roachprod.crdb.io} |
| 19 | + |
| 20 | +# generate the ssh key if it doesn't exist. |
| 21 | +if [[ ! -f ~/.ssh/id_rsa.pub ]]; then |
| 22 | + ssh-keygen -q -C "teamcity-pua-bazel $(date)" -N "" -f ~/.ssh/id_rsa |
| 23 | +fi |
| 24 | + |
| 25 | +# set up google credentials. |
| 26 | +if [[ "$GOOGLE_APPLICATION_CREDENTIALS_CONTENT" ]]; then |
| 27 | + echo "$GOOGLE_APPLICATION_CREDENTIALS_CONTENT" > creds.json |
| 28 | + gcloud auth activate-service-account --key-file=creds.json |
| 29 | + |
| 30 | + # Set GOOGLE_APPLICATION_CREDENTIALS so that gcp go libraries can find it. |
| 31 | + export GOOGLE_APPLICATION_CREDENTIALS="$(pwd)/creds.json" |
| 32 | +else |
| 33 | + echo 'warning: $GOOGLE_APPLICATION_CREDENTIALS_CONTENT not set' >&2 |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +# build the binaries: roachprod, roachtest, and drtprod. |
| 38 | +build() { |
| 39 | + config="crosslinux" |
| 40 | + # prepare the bin/ and artifacts/ directories. |
| 41 | + mkdir -p bin artifacts |
| 42 | + chmod o+rwx bin artifacts |
| 43 | + |
| 44 | + # array of arguments to be passed to bazel for the component. |
| 45 | + bazel_args=() |
| 46 | + |
| 47 | + # array of build artifacts. each item has format "src:dest"; src is relative to |
| 48 | + # the bazel-bin directory, dst is relative to cwd. |
| 49 | + artifacts=() |
| 50 | + |
| 51 | + bazel_args+=(//pkg/cmd/roachtest) |
| 52 | + artifacts+=("pkg/cmd/roachtest/roachtest_/roachtest:bin/roachtest") |
| 53 | + artifacts+=("pkg/cmd/roachtest/roachtest_/roachtest:artifacts/roachtest") |
| 54 | + |
| 55 | + bazel_args+=(//pkg/cmd/roachprod) |
| 56 | + artifacts+=("pkg/cmd/roachprod/roachprod_/roachprod:bin/roachprod") |
| 57 | + artifacts+=("pkg/cmd/roachprod/roachprod_/roachprod:artifacts/roachprod") |
| 58 | + |
| 59 | + bazel_args+=(//pkg/cmd/drtprod) |
| 60 | + artifacts+=("pkg/cmd/drtprod/drtprod_/drtprod:bin/drtprod") |
| 61 | + artifacts+=("pkg/cmd/drtprod/drtprod_/drtprod:artifacts/drtprod") |
| 62 | + |
| 63 | + bazel build --config $config -c opt "${bazel_args[@]}" |
| 64 | + BAZEL_BIN=$(bazel info bazel-bin --config $config -c opt) |
| 65 | + for artifact in "${artifacts[@]}"; do |
| 66 | + src=${artifact%%:*} |
| 67 | + dst=${artifact#*:} |
| 68 | + cp "$BAZEL_BIN/$src" "$dst" |
| 69 | + # Make files writable to simplify cleanup and copying (e.g., scp retry). |
| 70 | + chmod a+w "$dst" |
| 71 | + done |
| 72 | + |
| 73 | + # add bin to path. |
| 74 | + export PATH=$PATH:$(pwd)/bin |
| 75 | +} |
| 76 | + |
| 77 | +# run the build function. |
| 78 | +build |
| 79 | + |
| 80 | +log_file="artifacts/pua.log" |
| 81 | +export config=${PUA_CONFIG:-"single_region"} |
| 82 | +if [[ "$config" == "single_region" ]]; then |
| 83 | + CLUSTER=drt-pua-9 |
| 84 | + WORKLOAD=workload-pua-9 |
| 85 | + ZONE_NODE=7-9 |
| 86 | + config_file="pkg/cmd/drtprod/configs/drt_pua_9.yaml" |
| 87 | +elif [[ "$config" == "multi_region" ]]; then |
| 88 | + CLUSTER=drt-pua-15 |
| 89 | + WORKLOAD=workload-pua-15 |
| 90 | + ZONE_NODE=3-4 |
| 91 | + config_file="pkg/cmd/drtprod/configs/drt_pua_mr.yaml" |
| 92 | +else |
| 93 | + echo "Error: Invalid PUA_CONFIG value: '$config'. Must be 'single_region' or 'multi_region'." >&2 |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | + |
| 97 | +# execute the pua benchmark test. |
| 98 | +drtprod execute ${config_file} | tee -a "${log_file}" |
| 99 | + |
| 100 | +# the pua dashboard uses a json file to show the benchmark results. |
| 101 | +# we will generate the json file from the datadog metrics. |
| 102 | +# download metric converter from gcs bucket pua-backup-us-east1. |
| 103 | +mkdir -p datadog-metric-converter |
| 104 | +gsutil -m cp -r gs://pua-backup-us-east1/datadog-metric-converter/** datadog-metric-converter/ |
| 105 | + |
| 106 | +# install pip for python3.8. |
| 107 | +curl -sS https://bootstrap.pypa.io/pip/3.8/get-pip.py -o get-pip.py |
| 108 | +python3 get-pip.py |
| 109 | + |
| 110 | +# install the requirements for the metric converter. |
| 111 | +python3 -m pip install -r datadog-metric-converter/requirements.txt |
| 112 | + |
| 113 | +# get the start and end time of the benchmark. |
| 114 | +epoch_start_time=$(grep "\[Phase-1: Baseline Performance\]" ${log_file} | grep "Starting" | awk -F'[][]' '{print $4}') |
| 115 | +epoch_start_time=$((epoch_start_time - 240)) |
| 116 | +epoch_end_time=$(( $(date +%s) - 120 )) |
| 117 | +host=$(hostname) |
| 118 | + |
| 119 | +# generate the benchmark.json file |
| 120 | +python3 datadog-metric-converter/convert-datadog-metric.py --start-time=${epoch_start_time} --end-time=${epoch_end_time} \ |
| 121 | + --cluster-name ${CLUSTER} --workload-name ${WORKLOAD} \ |
| 122 | + --monitor-host ${host} --zone-node ${ZONE_NODE} |
| 123 | + |
| 124 | + |
| 125 | +# delete the binaries - roachprod, roachtest and drtprod, |
| 126 | +# as we don't need them to be uploaded to TeamCity artifacts |
| 127 | +rm -f artifacts/roachprod artifacts/roachtest artifacts/drtprod |
| 128 | +cp benchmark.json "artifacts/benchmark.json" |
| 129 | + |
| 130 | +rm -rf datadog-metric-converter |
| 131 | + |
| 132 | +# destroy the clusters. |
| 133 | +drtprod destroy ${CLUSTER} |
| 134 | +drtprod destroy ${WORKLOAD} |
0 commit comments