You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2022/04/29 00:43:14 UTC

[GitHub] [bookkeeper] Shoothzj opened a new pull request, #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Shoothzj opened a new pull request, #3252:
URL: https://github.com/apache/bookkeeper/pull/3252

   Fix #2637 #3247
   
   ### Motivation
   The mertics about `jvm_memory_direct_bytes_used` is acquired by netty's `PlatformDependent#DIRECT_MEMORY_COUNTER`. Which can only acquired the memory used by netty.
   
   ### Changes
   - use `java.nio.Bits#RESERVED_MEMORY` for jvm direct memory metrics.
   - add tests to ensure `jvm_memory_direct_bytes_max` and `jvm_memory_direct_bytes_used` gets value.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on a diff in pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on code in PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#discussion_r861573603


##########
stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/main/java/org/apache/bookkeeper/stats/prometheus/PrometheusMetricsProvider.java:
##########
@@ -223,9 +224,11 @@ private void registerMetrics(Collector collector) {
         AtomicLong tmpDirectMemoryUsage = null;
 
         try {
-            Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");
-            field.setAccessible(true);
-            tmpDirectMemoryUsage = (AtomicLong) field.get(null);
+            Class<?> name = Class.forName("java.nio.Bits");
+            String fieldName = SystemUtils.IS_JAVA_1_8 ? "reservedMemory" : "RESERVED_MEMORY";
+            Field reservedMemory = name.getDeclaredField(fieldName);
+            reservedMemory.setAccessible(true);
+            tmpDirectMemoryUsage = (AtomicLong) reservedMemory.get(null);

Review Comment:
   @dlg99 It's a stataic method, FieldUtils doesn't work



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1116875525

   @eolivelli @merlimat @pkumar-singh @nicoloboschi PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1113281347

   @eolivelli @merlimat @pkumar-singh @nicoloboschi PTAL @dlg99  PTAL again, thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1115499927

   @eolivelli @merlimat @pkumar-singh @nicoloboschi PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112816610

   rerun failure checks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] zymap merged pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
zymap merged PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] dlg99 commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
dlg99 commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112853060

   e.g. see https://github.com/apache/bookkeeper/pull/3234 : "Starting from JDK17 the reflection is not allowed in the jdk internals modules"


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112827658

   rerun failure checks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1113976736

   @eolivelli @merlimat @pkumar-singh @nicoloboschi PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112816909

   @eolivelli @dlg99 @merlimat @pkumar-singh @nicoloboschi  PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] dlg99 commented on a diff in pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
dlg99 commented on code in PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#discussion_r861436192


##########
stats/bookkeeper-stats-providers/prometheus-metrics-provider/src/main/java/org/apache/bookkeeper/stats/prometheus/PrometheusMetricsProvider.java:
##########
@@ -223,9 +224,11 @@ private void registerMetrics(Collector collector) {
         AtomicLong tmpDirectMemoryUsage = null;
 
         try {
-            Field field = PlatformDependent.class.getDeclaredField("DIRECT_MEMORY_COUNTER");
-            field.setAccessible(true);
-            tmpDirectMemoryUsage = (AtomicLong) field.get(null);
+            Class<?> name = Class.forName("java.nio.Bits");
+            String fieldName = SystemUtils.IS_JAVA_1_8 ? "reservedMemory" : "RESERVED_MEMORY";
+            Field reservedMemory = name.getDeclaredField(fieldName);
+            reservedMemory.setAccessible(true);
+            tmpDirectMemoryUsage = (AtomicLong) reservedMemory.get(null);

Review Comment:
   fyi, you can use org.apache.commons.lang.reflect.FieldUtils [FieldUtils.readDeclaredField() ](https://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/reflect/FieldUtils.html#readField-java.lang.reflect.Field-java.lang.Object-boolean-)with forceAccess
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] horizonzy commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
horizonzy commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1331617433

   This may be a breaking change, after this pr. The old user who used jdk8 didn't record the direct memory metrics.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112835893

   rerun failure checks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1112846534

   rerun failure checks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Shoothzj commented on pull request #3252: [ISSUE 2637] Fix jvm_memory_direct_bytes_used metrics when using jdk11+

Posted by GitBox <gi...@apache.org>.
Shoothzj commented on PR #3252:
URL: https://github.com/apache/bookkeeper/pull/3252#issuecomment-1118220994

   @eolivelli @merlimat @pkumar-singh @nicoloboschi PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org