Skip to content

Commit

Permalink
Merge pull request #146 from harness/revert-145-lifecycleTemplate
Browse files Browse the repository at this point in the history
Revert "fix: [PIPE-20874]: Adjust JFR shutdown and add a default shutdown hook"
  • Loading branch information
chandra1249 authored Dec 18, 2024
2 parents 260d465 + 38fa844 commit 5395755
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 88 deletions.
2 changes: 1 addition & 1 deletion src/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: library
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.3.73
version: 1.3.74

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
80 changes: 0 additions & 80 deletions src/common/templates/_deployment-lifecycle.tpl

This file was deleted.

62 changes: 55 additions & 7 deletions src/common/templates/_jfr-helper.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
{{/*
To note this template also depends on a lifecycle hook being set. See _deployment-lifecycle.tpl for the default hook
which SHOULD always be available. These templates enable the volumes and ENV variables that the hook would read.
Since there's ONLY a single hook allowed, and a set of "sane" defaults on termination are needed, the JFR
code is actually mastered by default there
*/}}
{{/*
USAGE:
{{- include "harnesscommon.jfr.v1.renderEnvironmentVars" (dict "ctx" $) }}
Expand All @@ -26,6 +19,61 @@ USAGE:
{{- end }}
{{- end }}

{{/*
USAGE:
{{- include "harnesscommon.v1.renderLifecycleHooks" (dict "ctx" $) }}
*/}}
{{- define "harnesscommon.v1.renderLifecycleHooks" }}
{{- $ := .ctx }}
{{- if $.Values.lifecycleHooks }}
{{ include "harnesscommon.tplvalues.render" (dict "value" $.Values.lifecycleHooks "context" $) }}
{{- else if $.Values.global.jfr.enabled }}
postStart:
exec:
command:
- /bin/sh
- -c
- |
mkdir -p ${JFR_DUMP_ROOT_LOCATION}/dumps/${SERVICE_NAME}/${ENV_TYPE}/jfr_dumps/${POD_NAME};
ln -s ${JFR_DUMP_ROOT_LOCATION}/dumps/${SERVICE_NAME}/${ENV_TYPE}/jfr_dumps/${POD_NAME} ${JFR_DUMP_ROOT_LOCATION}/POD_NAME ;
preStop:
exec:
command:
- /bin/sh
- -c
- |
touch shutdown;
sleep 20;
ts=$(date '+%s');
loc=${JFR_DUMP_ROOT_LOCATION}/dumps/${SERVICE_NAME}/${ENV_TYPE}/$ts/${POD_NAME};
mkdir -p $loc; sleep 1; echo $ts > $loc/restart;
echo $(date '+%s') > $loc/begin;
PID=$(jps|grep -vi jps|awk '{ print $1}');
#Copy GC log file
cp mygclogfilename.gc $loc/;

#Retry 10 times to take thread dump. Unsuccessful attempt has just 1 line with java process id in the output.
for ((n=0;n<10;n++)); do
jcmd $PID Thread.print -e > $loc/thread-dump-attempt-$n.txt;
if [ $(wc -l < $loc/thread-dump-attempt-$n.txt) -gt 1 ]; then break; fi;
done

#10 retries to take heap histogram. Unsuccessful attempt has just 1 line with java process id in the output.
for ((n=0;n<10;n++)); do
jcmd $PID GC.class_histogram -all > $loc/heap-histogram-attempt-$n.txt;
if [ $(wc -l < $loc/heap-histogram-attempt-$n.txt) -gt 1 ]; then break; fi;
done

jcmd $PID VM.native_memory > $loc/native-memory-dump.txt;

#Dump latest chunk of JFR recording
jcmd $PID JFR.dump name=jfrRecording filename=${JFR_DUMP_ROOT_LOCATION}/dumps/${SERVICE_NAME}/${ENV_TYPE}/jfr_dumps/${POD_NAME}/container_termination_$(date +%Y_%m_%d_%H_%M_%S).jfr > $loc/jfr_done.txt

echo $(date '+%s') > $loc/end
kill -15 $PID;
{{- end }}
{{- end }}

{{/*
USAGE:
{{- include "harnesscommon.jfr.v1.volumes" (dict "ctx" $) }}
Expand Down

0 comments on commit 5395755

Please sign in to comment.