From 5b7771c02840edcf69de34876743200ca5b538c1 Mon Sep 17 00:00:00 2001 From: yangjd33 Date: Mon, 15 May 2023 14:59:31 +0800 Subject: [PATCH 1/5] feat(docker):Add the jattach tool to the docker container(#7538) --- docker/datahub-frontend/Dockerfile | 3 +- docker/datahub-gms/Dockerfile | 1 + docker/datahub-mae-consumer/Dockerfile | 1 + docker/datahub-mce-consumer/Dockerfile | 1 + docs/how/jattach-guide.md | 80 ++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 docs/how/jattach-guide.md diff --git a/docker/datahub-frontend/Dockerfile b/docker/datahub-frontend/Dockerfile index 6bea7beb81607..23c04972209ed 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 0b86a2e420ed4..2d74a288b8c99 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 82048da95ab82..734f8ba452f3e 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 f0fc394f7bc09..ee5d927fb1ddb 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/how/jattach-guide.md b/docs/how/jattach-guide.md new file mode 100644 index 0000000000000..4d3dd20cb298a --- /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 From 004f2b29ab9e2cef289c6fce54048bd64126f47a Mon Sep 17 00:00:00 2001 From: yangjd33 Date: Tue, 16 May 2023 10:55:21 +0800 Subject: [PATCH 2/5] fix error of building docs --- docs-website/sidebars.js | 1 + 1 file changed, 1 insertion(+) diff --git a/docs-website/sidebars.js b/docs-website/sidebars.js index 41073bbe3f814..0a7ab11b92983 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.md", ], }, "docs/how/updating-datahub", From 9cfca232471268ddd5a61129eadf7eae34457788 Mon Sep 17 00:00:00 2001 From: yangjd33 Date: Tue, 16 May 2023 11:51:55 +0800 Subject: [PATCH 3/5] remove space in sidevars.js --- docs-website/sidebars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-website/sidebars.js b/docs-website/sidebars.js index 0a7ab11b92983..4698a4167622b 100644 --- a/docs-website/sidebars.js +++ b/docs-website/sidebars.js @@ -188,7 +188,7 @@ module.exports = { "docs/how/kafka-config", "docs/deploy/confluent-cloud", "docs/advanced/no-code-upgrade", - " docs/how/jattach-guide.md", + "docs/how/jattach-guide.md", ], }, "docs/how/updating-datahub", From 46b63b1fffbfaff54aa027885030bbeb43276f9d Mon Sep 17 00:00:00 2001 From: yangjd33 Date: Tue, 16 May 2023 14:23:21 +0800 Subject: [PATCH 4/5] remove .md suffix --- docs-website/sidebars.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs-website/sidebars.js b/docs-website/sidebars.js index 4698a4167622b..69e07c1bf3014 100644 --- a/docs-website/sidebars.js +++ b/docs-website/sidebars.js @@ -188,7 +188,7 @@ module.exports = { "docs/how/kafka-config", "docs/deploy/confluent-cloud", "docs/advanced/no-code-upgrade", - "docs/how/jattach-guide.md", + "docs/how/jattach-guide", ], }, "docs/how/updating-datahub", From 01f4267530d3e0417965811f25ad7973ad02c410 Mon Sep 17 00:00:00 2001 From: yangjd33 Date: Wed, 24 May 2023 10:49:40 +0800 Subject: [PATCH 5/5] Remove some special characters from the document --- docs/how/jattach-guide.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/how/jattach-guide.md b/docs/how/jattach-guide.md index 4d3dd20cb298a..9b803067950c6 100644 --- a/docs/how/jattach-guide.md +++ b/docs/how/jattach-guide.md @@ -8,17 +8,17 @@ 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 +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