Skip to content

Commit

Permalink
Remove some metrics that are already covered in upstream (#1005)
Browse files Browse the repository at this point in the history
* Remove some metrics that are already covered in upstream

* Fix test

* removed some more stuff
  • Loading branch information
Mateusz Rzeszutek authored Dec 13, 2022
1 parent 2c58260 commit dc3199a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import com.splunk.opentelemetry.instrumentation.jvmmetrics.micrometer.MicrometerGcMemoryMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelAllocatedMemoryMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelGcMemoryMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelJvmGcMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelJvmHeapPressureMetrics;
import com.splunk.opentelemetry.instrumentation.jvmmetrics.otel.OtelJvmThreadMetrics;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics;
Expand Down Expand Up @@ -59,8 +57,25 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetr
new JvmThreadMetrics().bindTo(Metrics.globalRegistry);
}
if (useOtelMetrics(metricsImplementation)) {
new OtelJvmGcMetrics().install();
new OtelJvmHeapPressureMetrics().install();
// gc metrics were removed:
// runtime.jvm.gc.concurrent.phase.time is replaced by OTel
// process.runtime.jvm.gc.duration{gc=<concurrent gcs>}
// runtime.jvm.gc.pause is replaced by OTel
// process.runtime.jvm.gc.duration{gc!=<concurrent gcs>}
// runtime.jvm.gc.max.data.size is replaced by OTel
// process.runtime.jvm.memory.limit{pool=<long lived pools>}
// runtime.jvm.gc.live.data.size is replaced by OTel
// process.runtime.jvm.memory.usage_after_last_gc{pool=<long lived pools>}
// runtime.jvm.gc.memory.allocated is replaced by memory profiling metric
// process.runtime.jvm.memory.allocated
// runtime.jvm.gc.memory.promoted is removed with no direct replacement

// heap pressure metrics were removed:
// runtime.jvm.memory.usage.after.gc is replaced by OTel
// process.runtime.jvm.memory.usage_after_last_gc{pool=<long lived pools>,type=heap} /
// process.runtime.jvm.memory.limit{pool=<long lived pools>,type=heap}
// runtime.jvm.gc.overhead is something that should to done in a dashboard, not here

new OtelJvmThreadMetrics().install();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,14 @@

package com.splunk.opentelemetry.instrumentation.jvmmetrics.otel;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryPoolMXBean;
import java.lang.management.MemoryType;
import java.lang.management.MemoryUsage;
import java.util.function.ToLongFunction;
import java.util.stream.Stream;
import javax.annotation.Nullable;

/** This class is copied from micrometer. */
class JvmMemory {

private JvmMemory() {}

static Stream<MemoryPoolMXBean> getLongLivedHeapPools() {
return ManagementFactory.getMemoryPoolMXBeans().stream()
.filter(JvmMemory::isHeap)
.filter(mem -> isLongLivedPool(mem.getName()));
}

static boolean isConcurrentPhase(String cause, String name) {
return "No GC".equals(cause) || "Shenandoah Cycles".equals(name) || "ZGC Cycles".equals(name);
}
Expand Down Expand Up @@ -84,26 +73,4 @@ static boolean isLongLivedPool(String name) {
static boolean isHeap(MemoryPoolMXBean memoryPoolBean) {
return MemoryType.HEAP.equals(memoryPoolBean.getType());
}

static double getUsageValue(
MemoryPoolMXBean memoryPoolMXBean, ToLongFunction<MemoryUsage> getter) {
MemoryUsage usage = getUsage(memoryPoolMXBean);
if (usage == null) {
return Double.NaN;
}
return getter.applyAsLong(usage);
}

@Nullable
private static MemoryUsage getUsage(MemoryPoolMXBean memoryPoolMXBean) {
try {
return memoryPoolMXBean.getUsage();
} catch (InternalError e) {
// Defensive for potential InternalError with some specific JVM options. Based
// on its Javadoc,
// MemoryPoolMXBean.getUsage() should return null, not throwing InternalError,
// so it seems to be a JVM bug.
return null;
}
}
}
Loading

0 comments on commit dc3199a

Please sign in to comment.