From 39625a3cfafb514ecbc1ed4c06cf4efc50eb8c55 Mon Sep 17 00:00:00 2001 From: davidatkinsuk Date: Wed, 22 Jan 2025 09:12:58 +0000 Subject: [PATCH] Improve seed job log checking instructions --- doc/how-to/run_seed_job_remotely.md | 6 +++++- script/pod_logs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100755 script/pod_logs diff --git a/doc/how-to/run_seed_job_remotely.md b/doc/how-to/run_seed_job_remotely.md index 647b2de2e0..23364ede39 100644 --- a/doc/how-to/run_seed_job_remotely.md +++ b/doc/how-to/run_seed_job_remotely.md @@ -50,7 +50,11 @@ For XLSX files: /app/run_seed_from_excel_job cas1_import_site_survey_rooms ap_seed_file ``` -- Check the logs using [Azure Application Insights](https://dsdmoj.atlassian.net/wiki/spaces/AP/pages/4154196024/Viewing+and+Tailing+Kubernetes+logs) to see how processing is progressing. The following query will provide seed traces and exceptions only: +- Whilst App Insights can be used to view seed logs, we've found that if we're running multiple seed jobs concurrently, some logs are lost in app insights. Checking the container logs directly avoids this issue, although they're not retained for as long. E.g. + +```./pod_logs preprod {container_name} | grep -i 'seed'``` + +- Alternatively, you can check the logs using [Azure Application Insights](https://dsdmoj.atlassian.net/wiki/spaces/AP/pages/4154196024/Viewing+and+Tailing+Kubernetes+logs) with the following query: ``` union traces, exceptions | where cloud_RoleName == 'approved-premises-api' and customDimensions contains ("uk.gov.justice.digital.hmpps.approvedpremisesapi.seed") diff --git a/script/pod_logs b/script/pod_logs new file mode 100755 index 0000000000..12f538de97 --- /dev/null +++ b/script/pod_logs @@ -0,0 +1,23 @@ + +if [ -z "$1" ] || ! [[ "$1" =~ ^(dev|test|preprod|prod)$ ]]; then + echo "Usage:" + echo "pod_logs dev|test|preprod|prod [pod_name]" + echo "" + echo "If no pod name is defined, the first API pod found will be used" + exit 1 +else + environment=$1 +fi + +namespace="hmpps-community-accommodation-$environment" + +if [ -z "$2" ]; then + echo "No pod specified, will use first API pod found" + pod=$(kubectl -n "$namespace" get pods -l app=hmpps-approved-premises-api -o jsonpath='{.items[0].metadata.name}') +else + pod="$2" +fi + +echo "Outputting logs for $pod" + +kubectl -n $namespace logs "$pod" \ No newline at end of file