Skip to content

Commit

Permalink
Support collecting coverage data
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisburr committed Sep 25, 2023
1 parent 43a77dd commit 3a93621
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TODO
| autoscaling.maxReplicas | int | `100` | |
| autoscaling.minReplicas | int | `1` | |
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| developer.enableCoverage | bool | `false` | |
| developer.enabled | bool | `true` | |
| developer.modulesToInstall | list | `[]` | |
| developer.sourcePath | string | `"/diracx_source"` | |
Expand Down
9 changes: 9 additions & 0 deletions diracx/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,21 @@ spec:
- name: signing-key-mount
emptyDir:
sizeLimit: 5Mi
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
- name: coverage-data
persistentVolumeClaim:
claimName: pvc-coverage
{{- end }}

{{/* Define common volume mounts for reusability */}}
{{- $commonVolumeMounts := list }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/cs_store" "name" "cs-store-mount" "readOnly" false) }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/signing-key" "name" "signing-key-mount" "readOnly" false) }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/entrypoint.sh" "name" "container-entrypoint" "subPath" "entrypoint.sh") }}
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/diracx-coveragerc" "name" "container-entrypoint" "subPath" "coveragerc") }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/coverage-reports" "name" "coverage-data" "readOnly" false) }}
{{- end }}
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" .Values.developer.sourcePath "name" "diracx-code-mount" "readOnly" true) }}
{{- range $module := .Values.developer.modulesToInstall }}
Expand Down
50 changes: 50 additions & 0 deletions diracx/templates/diracx-container-entrypoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,54 @@ data:
pip install {{- range $moduleName := .Values.developer.modulesToInstall }} -e {{ $.Values.developer.sourcePath }}/{{ $moduleName }} {{- end }}
{{- end }}
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
SITE_PACKAGES_DIR=$(python -m sysconfig | grep platlib | head -n 1 | cut -d '=' -f 2 | cut -d '"' -f 2)
echo "Enabling coverage using pth file in SITE_PACKAGES_DIR=${SITE_PACKAGES_DIR}"
echo 'import coverage; coverage.process_startup()' > "${SITE_PACKAGES_DIR}/coverage.pth"
export COVERAGE_PROCESS_START=/diracx-coveragerc
{{- end }}
exec "$@"
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
coveragerc: |
[run]
data_file=/coverage-reports/coverage
relative_files=True
parallel=True
sigterm=True
[paths]
source =
src/
*/site-packages/
/diracx_source/*/src/
{{- end }}
---
{{/* If we're collecting coverage we also need a volume to store it in */}}
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-coverage
spec:
storageClassName: ""
accessModes:
- ReadWriteMany
capacity:
storage: 2Gi
hostPath:
path: /coverage-reports
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-coverage
spec:
storageClassName: ""
volumeName: pv-coverage
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
{{ end }}
1 change: 1 addition & 0 deletions diracx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ developer:
# Path from which to mount source of DIRACX
sourcePath: /diracx_source
modulesToInstall: []
enableCoverage: false
# If set, mount the CS stored localy instead of initializing a default one
# localCSPath: /local_cs_store

Expand Down
45 changes: 41 additions & 4 deletions run_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,23 @@ function check_hostname(){
fi
}

usage="${0##*/} [-h|--help] [--exit-when-done] [--] <diracx_src_dir> [other source directories]"
usage="${0##*/} [-h|--help] [--exit-when-done] [--enable-coverage] [--set-value key=value] [--] [source directories]"
usage+="\n\n"
usage+=" -h|--help: Print this help message and exit\n"
usage+=" --exit-when-done: Exit after the demo has been started (it will be left running in the background)\n"
usage+=" --enable-coverage: Enable coverage reporting\n"
usage+=" --set-value: Set a value in the Helm values file. This can be used to override the default values.\n"
usage+=" For example, to enable coverage reporting pass: --set-value developer.enableCoverage=true\n"
usage+=" source directories: A list of directories containing Python packages to mount in the demo cluster.\n"

# Parse command-line switches
exit_when_done=0
declare -a helm_arguments=()
enable_coverage=0
while [ -n "${1:-}" ]; do case $1 in
# Print a brief usage summary and exit
-h|--help|-\?)
printf 'Usage: %s\n' "$usage"
printf 'Usage: %b\n' "$usage"
exit ;;

# # Unbundle short options
Expand All @@ -74,7 +83,25 @@ while [ -n "${1:-}" ]; do case $1 in
--exit-when-done)
exit_when_done=1;
shift
break ;;
continue ;;

--enable-coverage)
helm_arguments+=("--set")
helm_arguments+=("developer.enableCoverage=true")
enable_coverage=1
shift
continue ;;

--set-value)
shift
if [[ -z "${1:-}" ]]; then
printf "%b Error: --set-value requires an argument\n" ${SKULL_EMOJI}
exit 1
fi
helm_arguments+=("--set")
helm_arguments+=("${1}")
shift
continue ;;

# Double-dash: Terminate option parsing
--)
Expand Down Expand Up @@ -186,6 +213,16 @@ if [ ${#pkg_dirs[@]} -gt 0 ]; then
sed "s@{{ hostPaths }}@ - hostPath: ${pkg_dir}\n containerPath: /diracx_source/$(basename "${pkg_dir}")\n{{ hostPaths }}@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
done
fi
# If coverage is enabled mount .demo/coverage-reports into the cluster
if [[ ${enable_coverage} ]]; then
rm -rf "${demo_dir}/coverage-reports"
mkdir -p "${demo_dir}/coverage-reports"
# Make sure the directory is writable by the container
chmod 777 "${demo_dir}/coverage-reports"
mv "${demo_dir}/demo_cluster_conf.yaml" "${demo_dir}/demo_cluster_conf.yaml.bak"
sed "s@{{ hostPaths }}@ - hostPath: ${demo_dir}/coverage-reports\n containerPath: /coverage-reports\n{{ hostPaths }}@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
fi
# Cleanup the "{{ hostPaths }}" part of the template and make sure things look reasonable
mv "${demo_dir}/demo_cluster_conf.yaml" "${demo_dir}/demo_cluster_conf.yaml.bak"
sed "s@{{ hostPaths }}@@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
if grep '{{' "${demo_dir}/demo_cluster_conf.yaml"; then
Expand Down Expand Up @@ -229,7 +266,7 @@ printf "%b Waiting for ingress controller to be created...\n" ${UNICORN_EMOJI}

# Install the DiracX chart
printf "%b Installing DiracX...\n" ${UNICORN_EMOJI}
if ! "${demo_dir}/helm" install diracx-demo "${script_dir}/diracx" --values "${demo_dir}/values.yaml"; then
if ! "${demo_dir}/helm" install diracx-demo "${script_dir}/diracx" --values "${demo_dir}/values.yaml" "${helm_arguments[@]}"; then
printf "%b Error using helm DiracX\n" ${WARN_EMOJI}
echo "Failed to run \"helm install\"" >> "${demo_dir}/.failed"
else
Expand Down

0 comments on commit 3a93621

Please sign in to comment.