Skip to content

Commit fad689d

Browse files
Pass Rally exit code along to night_rally
With this commit we will fail a benchmarking trial run with night_rally if Rally failed at least once. Closes elastic#7
1 parent 09b86c2 commit fad689d

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

night_rally.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ def ensure_dir(directory):
104104
raise
105105

106106

107-
def run(tracks, effective_start_date, override_src_dir):
108-
_configure_rally()
109-
_run_rally(effective_start_date, tracks, override_src_dir)
110-
111-
112-
def _configure_rally():
107+
def configure_rally():
113108
user_home = os.getenv("HOME")
114109
root = os.path.dirname(os.path.realpath(__file__))
115110
source = "%s/resources/rally-nightly.ini" % root
@@ -123,9 +118,10 @@ def _configure_rally():
123118
print(line.replace("~", user_home))
124119

125120

126-
def _run_rally(effective_start_date, tracks, override_src_dir, system=os.system):
121+
def run_rally(effective_start_date, tracks, override_src_dir, system=os.system):
127122
ts = date_for_cmd_param(effective_start_date)
128123
revision_ts = to_iso8601(effective_start_date)
124+
rally_failure = False
129125

130126
if override_src_dir is not None:
131127
override = " --override-src-dir=%s" % override_src_dir
@@ -147,9 +143,11 @@ def _run_rally(effective_start_date, tracks, override_src_dir, system=os.system)
147143
"rally --configuration-name=nightly --pipeline={6} --quiet --revision \"@{0}\" --effective-start-date \"{1}\" "
148144
"--track={2} --challenge={3} --car={4} --report-format=csv --report-file={5}{7}"
149145
.format(revision_ts, ts, track, challenge, car, report_path, pipeline, override)):
146+
rally_failure = True
150147
logger.error("Failed to run track [%s]. Please check the logs." % track)
151148
# after we've executed the first benchmark, there is no reason to build again from sources
152149
pipeline = "from-sources-skip-build"
150+
return rally_failure
153151

154152

155153
def v(d, k):
@@ -222,6 +220,7 @@ def key_for(metric_pattern, metric_key, metric_name, op_name):
222220
return metric_key
223221
return None
224222

223+
225224
def meta_key_for(metric_pattern, metric_key, metric_name):
226225
if re.match(metric_pattern, metric_name):
227226
return metric_key
@@ -246,6 +245,7 @@ def extract_metrics(source_report):
246245
metrics[final_key] = metric_value
247246
return metrics
248247

248+
249249
def extract_meta_metrics(source_meta_report):
250250
meta_metrics = {}
251251
for row in csv.reader(source_meta_report):
@@ -352,14 +352,12 @@ def report(effective_start_date, tracks, default_setup_per_track):
352352
with open("%s/merge_parts.csv" % output_report_path, "a") as f:
353353
f.write("%s,%s\n" % (report_timestamp, ",".join(metrics["merge_time_parts"])))
354354

355-
356-
357355
with open(meta_report_path) as csvfile:
358356
meta_metrics = extract_meta_metrics(csvfile)
359357

360-
if "source_revision" in metrics:
358+
if "source_revision" in meta_metrics:
361359
with open("%s/source_revision.csv" % output_report_path, "a") as f:
362-
f.write("%s,%s\n" % (report_timestamp, ",".join(metrics["source_revision"])))
360+
f.write("%s,%s\n" % (report_timestamp, ",".join(meta_metrics["source_revision"])))
363361

364362
if len(segment_count_metrics) > 0:
365363
with open("%s/segment_counts.csv" % output_report_path, "a") as f:
@@ -389,8 +387,11 @@ def parse_args():
389387
def main():
390388
args = parse_args()
391389

392-
run(tracks, args.effective_start_date, args.override_src_dir)
390+
configure_rally()
391+
rally_failure = run_rally(args.effective_start_date, tracks, args.override_src_dir)
393392
report(args.effective_start_date, tracks, defaults)
393+
if rally_failure:
394+
exit(1)
394395

395396

396397
if __name__ == "__main__":

night_rally.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SOURCE="${BASH_SOURCE[0]}"
2424
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
2525
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
2626
SOURCE="$(readlink "$SOURCE")"
27-
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
27+
[[ ${SOURCE} != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
2828
done
2929
NIGHT_RALLY_HOME="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
3030

@@ -33,7 +33,7 @@ SELF_UPDATE=NO
3333

3434
for i in "$@"
3535
do
36-
case $i in
36+
case ${i} in
3737
--override-src-dir=*)
3838
OVERRIDE_SRC_DIR="${i#*=}"
3939
shift # past argument=value
@@ -84,9 +84,17 @@ aws s3 sync "${S3_ROOT_BUCKET}/" "${LOCAL_REPORT_ROOT}"
8484
echo "Copying most recent assets to ${LOCAL_REPORT_ROOT}"
8585
cp -R ${NIGHT_RALLY_HOME}/external/pages/ ${LOCAL_REPORT_ROOT}
8686

87+
88+
# Avoid failing before we transferred all results. Usually only a single benchmark trial run fails but lots of other succeed.
89+
set +e
8790
# We invoke it currently with the current (UTC) timestamp. This determines the version to checkout
8891
python3 ${NIGHT_RALLY_HOME}/night_rally.py --effective-start-date="`date -u "+%Y-%m-%d %H:%M:%S"`" ${NIGHT_RALLY_OVERRIDE}
92+
set -e
93+
exit_code=$?
8994

9095
echo "Uploading results to $S3_ROOT_BUCKET"
9196
#s3cmd sync --guess-mime-type -P ~/.rally/benchmarks/reports/out/ ${S3_ROOT_BUCKET}/
92-
aws s3 sync --acl "public-read" "${LOCAL_REPORT_ROOT}" "${S3_ROOT_BUCKET}/"
97+
aws s3 sync --acl "public-read" "${LOCAL_REPORT_ROOT}" "${S3_ROOT_BUCKET}/"
98+
99+
# Exit with the same exit code as night_rally.py
100+
exit ${exit_code}

0 commit comments

Comments
 (0)