From e9dfc8c07d376605075158f76b8f6dea0307073d Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Wed, 27 Mar 2024 19:47:41 -0400 Subject: [PATCH] Extract log dumping into a callable workflow --- .github/workflows/_charm-dump-logs.yaml | 53 +++++++++++++++++++ .../workflows/_charm-tests-integration.yaml | 38 +------------ 2 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/_charm-dump-logs.yaml diff --git a/.github/workflows/_charm-dump-logs.yaml b/.github/workflows/_charm-dump-logs.yaml new file mode 100644 index 0000000..f862083 --- /dev/null +++ b/.github/workflows/_charm-dump-logs.yaml @@ -0,0 +1,53 @@ +name: Dump logs + +on: + workflow_call: + +jobs: + dump-logs: + name: Dump logs + runs-on: ubuntu-latest + steps: + - name: Dump debug log + if: failure() + run: | + for ctl in $(juju controllers --format json | jq -r '.controllers | keys[]'); do for mdl in $(juju models --format json | jq -r '.models[].name' | grep -v "admin/controller"); do juju debug-log -m $ctl:$mdl --replay --ms --no-tail; done; done || true + exit 0 + shell: bash + - name: Dump pods and their logs + if: failure() + shell: bash + run: | + juju status --relations --storage + kubectl get pods \ + -A \ + -o=jsonpath='{range.items[*]}{.metadata.namespace} {.metadata.name}{"\n"}' \ + --sort-by=.metadata.namespace \ + | grep -v "^\s*$" \ + | while read namespace pod; do \ + kubectl -n $namespace describe pod $pod; \ + kubectl -n $namespace logs $pod \ + --all-containers=true \ + --tail=100; \ + done + - name: Dump deployments + if: failure() + run: | + kubectl describe deployments -A + exit 0 + - name: Dump replicasets + if: failure() + run: | + kubectl describe replicasets -A + exit 0 + - name: Dump node information + if: failure() + run: | + kubectl get nodes -v=10 + exit 0 + - name: Dump charmcraft logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: charmcraft-logs + path: ~/.local/state/charmcraft/log/*.log diff --git a/.github/workflows/_charm-tests-integration.yaml b/.github/workflows/_charm-tests-integration.yaml index 921f15c..bddad92 100644 --- a/.github/workflows/_charm-tests-integration.yaml +++ b/.github/workflows/_charm-tests-integration.yaml @@ -59,40 +59,6 @@ jobs: run: | for m in $(juju models --format json | jq -r '.models[].name' | grep -v "admin/controller"); do juju debug-log -m $m --replay --ms --no-tail; done exit 0 - - name: Dump pods and their logs + - name: Dump logs if: failure() - run: | - juju status --relations --storage - kubectl get pods \ - -A \ - -o=jsonpath='{range.items[*]}{.metadata.namespace} {.metadata.name}{"\n"}' \ - --sort-by=.metadata.namespace \ - | grep -v "^\s*$" \ - | while read namespace pod; do \ - kubectl -n $namespace describe pod $pod; \ - kubectl -n $namespace logs $pod \ - --all-containers=true \ - --tail=100; \ - done - exit 0 - - name: Dump node information - if: failure() - run: | - kubectl get nodes -v=10 - exit 0 - - name: Dump deployments - if: failure() - run: | - kubectl describe deployments -A - exit 0 - - name: Dump replicasets - if: failure() - run: | - kubectl describe replicasets -A - exit 0 - - name: Dump charmcraft logs - if: failure() - uses: actions/upload-artifact@v3 - with: - name: charmcraft-logs - path: ~/.local/state/charmcraft/log/*.log + uses: canonical/observability/.github/workflows/_dump-logs.yaml@main