From 9311f72f3dec1ea714484f86786cd3440b3a4de1 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 28 Oct 2024 16:55:23 +1100 Subject: [PATCH] fix: disable metrics if endpoint not set (#3213) fixes: #3156 --- .../xyz/block/ftl/deployment/StaticConfigSource.java | 10 ++-------- .../xyz/block/ftl/runtime/config/FTLConfigSource.java | 9 +++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java index 220491e335..5819ecf2f9 100644 --- a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java +++ b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java @@ -7,7 +7,6 @@ public class StaticConfigSource implements ConfigSource { public static final String QUARKUS_BANNER_ENABLED = "quarkus.banner.enabled"; - final static String OTEL_METRICS_ENABLED = "quarkus.otel.metrics.enabled"; @Override public Set getPropertyNames() { @@ -16,13 +15,8 @@ public Set getPropertyNames() { @Override public String getValue(String propertyName) { - switch (propertyName) { - case (QUARKUS_BANNER_ENABLED) -> { - return "false"; - } - case OTEL_METRICS_ENABLED -> { - return "true"; - } + if (propertyName.equals(QUARKUS_BANNER_ENABLED)) { + return "false"; } return null; } diff --git a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/config/FTLConfigSource.java b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/config/FTLConfigSource.java index ae7d941c9e..f0359aaf9e 100644 --- a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/config/FTLConfigSource.java +++ b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/config/FTLConfigSource.java @@ -5,6 +5,7 @@ import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.regex.Matcher; @@ -23,9 +24,11 @@ public class FTLConfigSource implements ConfigSource { final static String HOST = "quarkus.http.host"; final static String FTL_BIND = "FTL_BIND"; + private static final String OTEL_ENV_VAR = "OTEL_EXPORTER_OTLP_ENDPOINT"; final FTLController controller; + private static final String OTEL_METRICS_DISABLED = "quarkus.otel.sdk.disabled"; private static final String DEFAULT_USER = "quarkus.datasource.username"; private static final String DEFAULT_PASSWORD = "quarkus.datasource.password"; private static final String DEFAULT_URL = "quarkus.datasource.jdbc.url"; @@ -67,6 +70,12 @@ public int getOrdinal() { @Override public String getValue(String s) { switch (s) { + case OTEL_METRICS_DISABLED -> { + var v = System.getenv(OTEL_ENV_VAR); + return Boolean + .toString(v == null || Objects.equals(v, "false") || Objects.equals(v, "0") || Objects.equals(v, "no") + || Objects.equals(v, "")); + } case SEPARATE_SERVER -> { return "false"; }