From 5588a04bc577dea12ad30fde23585e06e2b8c33f Mon Sep 17 00:00:00 2001 From: Yang Jiandan Date: Thu, 8 Jun 2023 01:23:38 +0800 Subject: [PATCH] feat(docker):Add the jattach tool to the docker container(#7538) (#8040) Co-authored-by: yangjd33 Co-authored-by: david-leifker <114954101+david-leifker@users.noreply.github.com> --- docker/datahub-frontend/Dockerfile | 3 +- docker/datahub-gms/Dockerfile | 1 + docker/datahub-mae-consumer/Dockerfile | 1 + docker/datahub-mce-consumer/Dockerfile | 1 + docs-website/sidebars.js | 1 + docs/how/jattach-guide.md | 80 ++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 docs/how/jattach-guide.md diff --git a/docker/datahub-frontend/Dockerfile b/docker/datahub-frontend/Dockerfile index 6bea7beb81..23c0497220 100644 --- a/docker/datahub-frontend/Dockerfile +++ b/docker/datahub-frontend/Dockerfile @@ -9,7 +9,8 @@ RUN addgroup -S datahub && adduser -S datahub -G datahub # PFP-260: Upgrade Sqlite to >=3.28.0-r0 to fix https://security.snyk.io/vuln/SNYK-ALPINE39-SQLITE-449762 RUN apk --no-cache --update-cache --available upgrade \ && apk --no-cache add curl sqlite \ - && apk --no-cache add openjdk11-jre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community + && apk --no-cache add openjdk11-jre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \ + && apk --no-cache add jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ FROM base as prod-install diff --git a/docker/datahub-gms/Dockerfile b/docker/datahub-gms/Dockerfile index 0b86a2e420..2d74a288b8 100644 --- a/docker/datahub-gms/Dockerfile +++ b/docker/datahub-gms/Dockerfile @@ -20,6 +20,7 @@ ENV JMX_VERSION=0.18.0 RUN apk --no-cache --update-cache --available upgrade \ && apk --no-cache add curl bash coreutils gcompat sqlite \ && apk --no-cache add openjdk11-jre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \ + && apk --no-cache add jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ \ && curl -sS https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-runner/9.4.46.v20220331/jetty-runner-9.4.46.v20220331.jar --output jetty-runner.jar \ && curl -sS https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-jmx/9.4.46.v20220331/jetty-jmx-9.4.46.v20220331.jar --output jetty-jmx.jar \ && curl -sS https://repo1.maven.org/maven2/org/eclipse/jetty/jetty-util/9.4.46.v20220331/jetty-util-9.4.46.v20220331.jar --output jetty-util.jar \ diff --git a/docker/datahub-mae-consumer/Dockerfile b/docker/datahub-mae-consumer/Dockerfile index 82048da95a..734f8ba452 100644 --- a/docker/datahub-mae-consumer/Dockerfile +++ b/docker/datahub-mae-consumer/Dockerfile @@ -20,6 +20,7 @@ ENV JMX_VERSION=0.18.0 RUN apk --no-cache --update-cache --available upgrade \ && apk --no-cache add curl bash coreutils sqlite \ && apk --no-cache add openjdk11-jre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \ + && apk --no-cache add jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ \ && wget --no-verbose https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.24.0/opentelemetry-javaagent.jar \ && wget --no-verbose https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${JMX_VERSION}/jmx_prometheus_javaagent-${JMX_VERSION}.jar -O jmx_prometheus_javaagent.jar \ && cp /usr/lib/jvm/java-11-openjdk/jre/lib/security/cacerts /tmp/kafka.client.truststore.jks diff --git a/docker/datahub-mce-consumer/Dockerfile b/docker/datahub-mce-consumer/Dockerfile index f0fc394f7b..ee5d927fb1 100644 --- a/docker/datahub-mce-consumer/Dockerfile +++ b/docker/datahub-mce-consumer/Dockerfile @@ -20,6 +20,7 @@ ENV JMX_VERSION=0.18.0 RUN apk --no-cache --update-cache --available upgrade \ && apk --no-cache add curl bash sqlite \ && apk --no-cache add openjdk11-jre --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community \ + && apk --no-cache add jattach --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ \ && wget --no-verbose https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.24.0/opentelemetry-javaagent.jar \ && wget --no-verbose https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/${JMX_VERSION}/jmx_prometheus_javaagent-${JMX_VERSION}.jar -O jmx_prometheus_javaagent.jar \ && cp /usr/lib/jvm/java-11-openjdk/jre/lib/security/cacerts /tmp/kafka.client.truststore.jks diff --git a/docs-website/sidebars.js b/docs-website/sidebars.js index 874d1fed8a..a00a1e8eca 100644 --- a/docs-website/sidebars.js +++ b/docs-website/sidebars.js @@ -188,6 +188,7 @@ module.exports = { "docs/how/kafka-config", "docs/deploy/confluent-cloud", "docs/advanced/no-code-upgrade", + "docs/how/jattach-guide", ], }, "docs/how/updating-datahub", diff --git a/docs/how/jattach-guide.md b/docs/how/jattach-guide.md new file mode 100644 index 0000000000..9b80306795 --- /dev/null +++ b/docs/how/jattach-guide.md @@ -0,0 +1,80 @@ +--- +title: "Debugging by Jattach" +hide_title: true +--- +We have installed jattach in Docker image of datahub-gms, datahub-mae-consumer, datahub-mce-consumer +and datahub-frontend to facilitating troubleshooting in a production environment. + +# Introduction to Jattach +Jattach is a utility to send commands to a JVM process via Dynamic Attach mechanism. + +Supported commands: +- load : load agent library +- properties : print system properties +- agentProperties : print agent properties +- datadump : show heap and thread summary +- threaddump : dump all stack traces (like jstack) +- dumpheap : dump heap (like jmap) +- inspectheap : heap histogram (like jmap -histo) +- setflag : modify manageable VM flag +- printflag : print VM flag +- jcmd : execute jcmd command + +# Use examples + +Jattach is a All-in-one **jmap + jstack + jcmd + jinfo** functionality in a single tiny program. +The scenarios where these commands were previously used can now be replaced with jattach. + +## Example 1: Dump heap +The jattach dumpheap command is typically used in the following scenarios: + +- Memory leak analysis: When an application experiences memory leaks or abnormal memory growth, the jattach dumpheap +command is used to generate a heap dump file for further analysis and identification of the memory leak causes. + +- Memory analysis: By generating a heap dump file, various memory analysis tools such as Eclipse Memory Analyzer and +VisualVM can be utilized to analyze objects, reference relationships, and memory usage within the heap. This helps +identify potential performance issues and optimization opportunities. + +- Troubleshooting: When encountering frequent Full GCs, memory out-of-memory errors, or other memory-related issues, +generating a heap dump file provides additional information for troubleshooting and debugging purposes. + +- Performance optimization: By analyzing the heap dump file, it becomes possible to identify which objects in the +application consume a significant amount of memory. This information can be used for targeted performance optimizations, +such as reducing object creation or optimizing cache usage. + +It's important to note that generating a heap dump file can have an impact on the performance of the application. +Therefore, caution should be exercised when using it in a production environment, ensuring sufficient resources and +permissions are available for the operation. + +The command is as follows: +```bash +jattach dumpheap /tmp/heap.bin +``` + +## Example 2: Dump thread +The jattach threaddump command is typically used in the following scenarios: + +- Deadlock analysis: When an application experiences deadlocks or thread contention issues, the jattach threaddump +command is used to generate a thread dump file. It provides the current thread's stack trace information, helping to +identify the code paths and lock contention causing the deadlock. + +- Thread troubleshooting: When threads in an application encounter exceptions, long blocking times, excessive CPU usage, +or other issues, generating a thread dump file provides detailed information about each thread's state, stack trace, and +resource usage. This helps with troubleshooting and analysis. + +- Performance analysis: By generating a thread dump file, it becomes possible to understand the thread activity, call +paths, and resource contention within the application. This aids in identifying potential performance bottlenecks and +concurrency issues. + +- Monitoring and diagnostics: Regularly generating thread dump files can be used to monitor the health of an application +and provide historical data for subsequent diagnostics. This helps gain a better understanding of the application's +behavior and performance. + +It's important to note that generating a thread dump file may impact the performance of the application. Therefore, +caution should be exercised when using it in a production environment, ensuring sufficient resources and permissions +are available for the operation. + +The command is as follows: +```bash +jattach threaddump -l > /tmp/jstack.out +``` \ No newline at end of file