From 31356cecf32730db802d27d24ceebd105345e621 Mon Sep 17 00:00:00 2001 From: Arpad Kiss Date: Fri, 29 Nov 2024 14:44:24 +0100 Subject: [PATCH] Add test to log level change via signals feature Signed-off-by: Arpad Kiss --- examples/features/README.md | 1 + .../runtime-loglevel-change/README.md | 67 +++++++++++++++++++ .../forwarder-patch.yaml | 14 ++++ .../kustomization.yaml | 11 +++ 4 files changed, 93 insertions(+) create mode 100644 examples/features/runtime-loglevel-change/README.md create mode 100644 examples/features/runtime-loglevel-change/forwarder-patch.yaml create mode 100644 examples/features/runtime-loglevel-change/kustomization.yaml diff --git a/examples/features/README.md b/examples/features/README.md index d9e6f1b4d797..240ce1ce8d81 100644 --- a/examples/features/README.md +++ b/examples/features/README.md @@ -36,4 +36,5 @@ To run any feature example follow steps for [Basic NSM setup](../basic) - [Scaled Registry K8s](./scaled-registry) - [NSC changes endpoints dynamically](./change-nse-dynamically) - [NSE IPAM Policies](./ipam-policies) +- [Runtime LogLevel Change](./runtime-loglevel-change) diff --git a/examples/features/runtime-loglevel-change/README.md b/examples/features/runtime-loglevel-change/README.md new file mode 100644 index 000000000000..f6876053d34c --- /dev/null +++ b/examples/features/runtime-loglevel-change/README.md @@ -0,0 +1,67 @@ +# Test runtime log level change via signals + +This example shows how log level can be set, and reset to and from TRACE level + +## Requires + +Make sure that you have completed steps from [basic](../../basic) setup. + + +## Run + +Ensure log level is not set to TRACE +```bash +kubectl apply -k ../https://github.com/networkservicemesh/deployments-k8s/examples/features/runtime-loglevel-change?ref=a93498171537efbfcfb704c5272519cc771c5ff0 +``` + +Wait for forwarders to get ready +```bash +kubectl rollout status --timeout=3m -n nsm-system daemonset forwarder-vpp +``` + +Select a forwarder pod, get the pid of the running forwarder, and send SIGUSR1 to switch on TRACE +```bash +forwarder="$(kubectl get pods -n nsm-system --selector=app=forwarder-vpp --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | head -1)" +kubectl exec "$forwarder" -n nsm-system -i -- bash <<'EOF' + kill -s SIGUSR1 "$(pgrep 'forwarder')" +EOF +``` + +Check if signal has arrived +```bash +kubectl logs --selector=app=forwarder-vpp -n nsm-system --tail -1 --since=1m | grep "SetupLevelChangeOnSignal" +``` + +Check if there are TRACE logs +```bash +sleep 1m +kubectl logs --selector=app=forwarder-vpp -n nsm-system --tail -1 --since=1m | grep "TRAC" +``` + +Select a forwarder pod, get the pid of the running forwarder, and send SIGUSR2 to restore original log level +```bash +forwarder="$(kubectl get pods -n nsm-system --selector=app=forwarder-vpp --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}' | head -1)" +kubectl exec "$forwarder" -n nsm-system -i -- bash <<'EOF' + kill -s SIGUSR2 "$(pgrep 'forwarder')" +EOF +``` + +Check if signal has arrived +```bash +kubectl logs --selector=app=forwarder-vpp -n nsm-system --tail -1 --since=1m | grep "SetupLevelChangeOnSignal" + ``` + +Check if there are no TRACE logs +```bash +sleep 1m +! kubectl logs --selector=app=forwarder-vpp -n nsm-system --tail -1 --since=1m | grep "TRAC" +``` + +//---------------------------------------------------------------------------// +## Cleanup + +Reset original basic example +```bash +kubectl apply -k https://github.com/networkservicemesh/deployments-k8s/examples/basic?ref=a93498171537efbfcfb704c5272519cc771c5ff0 +kubectl rollout status --timeout=3m -n nsm-system daemonset forwarder-vpp +``` diff --git a/examples/features/runtime-loglevel-change/forwarder-patch.yaml b/examples/features/runtime-loglevel-change/forwarder-patch.yaml new file mode 100644 index 000000000000..c290b79ceb33 --- /dev/null +++ b/examples/features/runtime-loglevel-change/forwarder-patch.yaml @@ -0,0 +1,14 @@ +--- +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: forwarder-vpp +spec: + selector: {} + template: + spec: + containers: + - name: forwarder-vpp + env: + - name: NSM_LOG_LEVEL + value: "INFO" diff --git a/examples/features/runtime-loglevel-change/kustomization.yaml b/examples/features/runtime-loglevel-change/kustomization.yaml new file mode 100644 index 000000000000..e5cd009c3ae1 --- /dev/null +++ b/examples/features/runtime-loglevel-change/kustomization.yaml @@ -0,0 +1,11 @@ +--- +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: nsm-system + +resources: +- ../../basic + +patches: +- path: forwarder-patch.yaml