Skip to content

Commit

Permalink
Report test statistics to elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
msimberg committed Dec 19, 2023
1 parent dc24ede commit e4240cb
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 14 deletions.
6 changes: 5 additions & 1 deletion .gitlab/docker/Dockerfile.spack_base
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,22 @@ RUN apt-get update && apt-get -yqq install --no-install-recommends \
gcc \
git \
gnupg2 \
jq \
libtool \
locales \
m4 \
moreutils \
openssl \
pipx \
pkgconf \
python3 \
python3-pip \
tar \
unzip \
vim \
xz-utils \
&& rm -Rf /var/lib/apt/lists/*
&& rm -Rf /var/lib/apt/lists/* && \
pipx install xq && pipx ensurepath

# Install spack
ARG SPACK_REPO=https://github.com/spack/spack
Expand Down
5 changes: 4 additions & 1 deletion .gitlab/includes/clang14_cuda11_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ clang14_cuda11_debug_test:
extends:
- .variables_clang14_cuda11_config
- .test_common_gpu_clariden_cuda
- .cmake_variables_common
needs:
- clang14_cuda11_debug_build
script:
- spack arch
- spack build-env $spack_spec -- bash -c "ctest --label-exclude COMPILE_ONLY --test-dir ${BUILD_DIR} -j$(nproc) --timeout 120 --output-on-failure --no-compress-output --no-tests=error"
- export CTEST_XML=$PWD/ctest.xml
- trap "${SOURCE_DIR}/.gitlab/scripts/collect_ctest_metrics.sh ${CTEST_XML}" EXIT
- spack build-env $spack_spec -- bash -c "ctest --junit ${CTEST_XML} --label-exclude COMPILE_ONLY --test-dir ${BUILD_DIR} -j$(nproc) --timeout 120 --output-on-failure --no-compress-output --no-tests=error"
image: $PERSIST_IMAGE_NAME
24 changes: 12 additions & 12 deletions .gitlab/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# file BOOST_LICENSE_1_0.rst or copy at http://www.boost.org/LICENSE_1_0.txt)

include:
- local: '.gitlab/includes/dockerhub_pipeline.yml'
- local: '.gitlab/includes/gcc9_pipeline.yml'
- local: '.gitlab/includes/gcc9_cuda11_pipeline.yml'
- local: '.gitlab/includes/gcc11_pipeline.yml'
- local: '.gitlab/includes/gcc12_pipeline.yml'
- local: '.gitlab/includes/gcc12_cuda12_pipeline.yml'
- local: '.gitlab/includes/gcc13_pipeline.yml'
- local: '.gitlab/includes/clang11_pipeline.yml'
- local: '.gitlab/includes/clang12_pipeline.yml'
- local: '.gitlab/includes/clang13_pipeline.yml'
# - local: '.gitlab/includes/dockerhub_pipeline.yml'
# - local: '.gitlab/includes/gcc9_pipeline.yml'
# - local: '.gitlab/includes/gcc9_cuda11_pipeline.yml'
# - local: '.gitlab/includes/gcc11_pipeline.yml'
# - local: '.gitlab/includes/gcc12_pipeline.yml'
# - local: '.gitlab/includes/gcc12_cuda12_pipeline.yml'
# - local: '.gitlab/includes/gcc13_pipeline.yml'
# - local: '.gitlab/includes/clang11_pipeline.yml'
# - local: '.gitlab/includes/clang12_pipeline.yml'
# - local: '.gitlab/includes/clang13_pipeline.yml'
- local: '.gitlab/includes/clang14_cuda11_pipeline.yml'
- local: '.gitlab/includes/clang15_pipeline.yml'
- local: '.gitlab/includes/clang16_pipeline.yml'
# - local: '.gitlab/includes/clang15_pipeline.yml'
# - local: '.gitlab/includes/clang16_pipeline.yml'
140 changes: 140 additions & 0 deletions .gitlab/scripts/collect_ctest_metrics.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env bash

# Copyright (c) 2023 ETH Zurich
#
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

set -euo pipefail

ctest_xml="${1}"

function submit_logstash {
echo Submitting to logstash:
jq . "${1}"

curl \
--request POST \
--header "Content-Type: application/json" \
--data "@${1}" \
"${CSCS_LOGSTASH_URL}"
}

function json_merge {
# Merge json files according to
# https://stackoverflow.com/questions/19529688/how-to-merge-2-json-objects-from-2-files-using-jq
#
# --slurp adds all the objects from different files into an array, and add merges the objects
# --sort-keys is used only to always have the keys in the same order
echo $(jq --slurp --sort-keys add "${1}" "${2}") > "${3}"
}

function json_add_value {
file=${1}
key=${2}
value=${3}

jq --arg value "${value}" ".${key} += \$value" "${file}" | sponge "${file}"
}

function json_add_value_json {
file=${1}
key=${2}
value=${3}

jq --argjson value "${value}" ".${key} += \$value" "${file}" | sponge "${file}"
}

function json_add_from_env {
file=${1}
key=${2}

for var in ${@:3}; do
jq --arg value "${!var:-}" ".${key}.${var} += \$value" "${file}" | sponge "${file}"
done
}

function json_add_from_command {
file=${1}
key=${2}

for cmd in ${@:3}; do
jq --arg value "$(${cmd})" ".${key}.${cmd} += \$value" "${file}" | sponge "${file}"
done
}

metadata_file=$(mktemp --tmpdir metadata.XXXXXXXXXX.json)
echo '{}' > "${metadata_file}"

# Logstash data stream metadata section
json_add_value "${metadata_file}" "data_stream.type" "logs"
json_add_value "${metadata_file}" "data_stream.dataset" "telemetry.pika"
json_add_value "${metadata_file}" "data_stream.namespace" "test5"

# CI/git metadata section
json_add_value "${metadata_file}" "ci.organization" "pika-org"
json_add_value "${metadata_file}" "ci.repository" "pika"
json_add_from_env \
"${metadata_file}" "ci" \
CI_COMMIT_AUTHOR \
CI_COMMIT_BRANCH \
CI_COMMIT_DESCRIPTION \
CI_COMMIT_MESSAGE \
CI_COMMIT_SHA \
CI_COMMIT_SHORT_SHA \
CI_COMMIT_TIMESTAMP \
CI_COMMIT_TITLE \
CI_JOB_IMAGE

# System section
json_add_from_command "${metadata_file}" "system" "hostname"

# Slurm section
json_add_from_env \
"${metadata_file}" "slurm" \
SLURM_CLUSTER_NAME \
SLURM_CPUS_ON_NODE \
SLURM_CPU_BIND \
SLURM_JOBID \
SLURM_JOB_NAME \
SLURM_JOB_NODELIST \
SLURM_JOB_NUM_NODES \
SLURM_JOB_PARTITION \
SLURM_NODELIST \
SLURM_NTASKS \
SLURM_TASKS_PER_NODE

# Build configuration section
json_add_from_env \
"${metadata_file}" "build_configuration" \
ARCH \
BUILD_TYPE \
CMAKE_COMMON_FLAGS \
CMAKE_FLAGS \
COMPILER \
SPACK_COMMIT \
SPACK_SPEC

# Submit individual test data
num_tests=$(xq . "${ctest_xml}" | jq '.testsuite.testcase | length')
for i in $(seq 1 ${num_tests}); do
result_file=$(mktemp --tmpdir "ctest_${i}.XXXXXXXXXX.json")
echo '{}' > "${result_file}"

ctest_object=$(xq . "${ctest_xml}" | jq ".testsuite.testcase[$((i - 1))]")
json_add_value_json "${result_file}" "metric.ctest.testcase" "${ctest_object}"

json_merge "${metadata_file}" "${result_file}" "${result_file}"
submit_logstash "${result_file}"
done

result_file=$(mktemp --tmpdir "ctest.XXXXXXXXXX.json")
echo '{}' > "${result_file}"

# Submit overall ctest data
ctest_object=$(xq . "${ctest_xml}" | jq "del(.testsuite.testcase)")
json_add_value_json "${result_file}" "metric.ctest.testuite" "${ctest_object}"

json_merge "${metadata_file}" "${result_file}" "${result_file}"
submit_logstash "${result_file}"

0 comments on commit e4240cb

Please sign in to comment.