summaryrefslogtreecommitdiff
path: root/scripts/benchmark/run-benchmarks-ci-job.sh
blob: adf37b7a047db2abb6b0e4d0093c8f4e4b21f6bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh

# Run benchmakr tests for CI jobs, and optionally compare results with historic
# series.
#
# Usage Example
# -------------
#
# Run this script with the environment name as the only argument:
#
#   ./run-benchmarks-ci-job.sh environment-name
#
# This script is used in .gitlab-ci.yml to run benchmark jobs. It has been
# factored out from that file to avoid bloating it with too much information.
#
# Environment Variables
# ---------------------
#
#   RUN_BENCHMARKS          - If not set, skip this run.
#   STATUS_CODE_IF_OUTLIERS - Exit with this status code if outliers are detected.

set -eu
set -o xtrace

ENVIRONMENT=${1}
RUN_BENCHMARKS=${RUN_BENCHMARKS:-}

if [ -z "${RUN_BENCHMARKS}" ]; then
  echo "Skipping benchmarks because RUN_BENCHMARKS is not set..."
  exit 0
fi

echo "Running tox in environment ${ENVIRONMENT}..."

#
# run benchmark tests with tox
#

tempfile=$(mktemp)
/usr/bin/unbuffer \
  tox \
    --recreate \
    -e ${ENVIRONMENT} \
    -- \
    --couch-url http://couchdb:5984 \
    --benchmark-json=${tempfile} \
  | /usr/bin/ts -s

#
# check results for bad outlier detecion
#

# stop here unless environment starts with "benchmark-"
if [ -z "$(echo ${ENVIRONMENT} | grep ^benchmark-)" ]; then
  exit 0
fi

# check for bad outliers
basedir=$(dirname "${0}")
${basedir}/check-for-outliers.py --status-code ${STATUS_CODE_IF_OUTLIERS:-0} ${tempfile}