From dbc547e5cf017bfcd3cc1602115c06256d508dde Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Wed, 9 Oct 2024 17:09:43 +1100 Subject: [PATCH] feat: obervability support for JVM fixes: #3041 --- jvm-runtime/ftl-runtime/common/deployment/pom.xml | 4 ++++ ...erConfigSource.java => StaticConfigSource.java} | 14 ++++++++++---- ...rg.eclipse.microprofile.config.spi.ConfigSource | 2 +- jvm-runtime/ftl-runtime/common/runtime/pom.xml | 8 ++++++++ .../java/xyz/block/ftl/runtime/VerbHandler.java | 12 +++++++++++- 5 files changed, 34 insertions(+), 6 deletions(-) rename jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/{BannerConfigSource.java => StaticConfigSource.java} (53%) diff --git a/jvm-runtime/ftl-runtime/common/deployment/pom.xml b/jvm-runtime/ftl-runtime/common/deployment/pom.xml index 0ba449822e..72d4d26f41 100644 --- a/jvm-runtime/ftl-runtime/common/deployment/pom.xml +++ b/jvm-runtime/ftl-runtime/common/deployment/pom.xml @@ -23,6 +23,10 @@ io.quarkus quarkus-rest-jackson-deployment + + io.quarkus + quarkus-opentelemetry-deployment + io.quarkus quarkus-agroal-spi diff --git a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/BannerConfigSource.java b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java similarity index 53% rename from jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/BannerConfigSource.java rename to jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java index 0ce5fff4e4..220491e335 100644 --- a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/BannerConfigSource.java +++ b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/StaticConfigSource.java @@ -4,9 +4,10 @@ import org.eclipse.microprofile.config.spi.ConfigSource; -public class BannerConfigSource implements ConfigSource { +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() { @@ -15,14 +16,19 @@ public Set getPropertyNames() { @Override public String getValue(String propertyName) { - if (propertyName.equals(QUARKUS_BANNER_ENABLED)) { - return "false"; + switch (propertyName) { + case (QUARKUS_BANNER_ENABLED) -> { + return "false"; + } + case OTEL_METRICS_ENABLED -> { + return "true"; + } } return null; } @Override public String getName() { - return "Quarkus Banner"; + return "Quarkus Static Config Source"; } } diff --git a/jvm-runtime/ftl-runtime/common/deployment/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/jvm-runtime/ftl-runtime/common/deployment/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource index d8995dc83b..3560bbbc3a 100644 --- a/jvm-runtime/ftl-runtime/common/deployment/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource +++ b/jvm-runtime/ftl-runtime/common/deployment/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource @@ -1 +1 @@ -xyz.block.ftl.deployment.BannerConfigSource \ No newline at end of file +xyz.block.ftl.deployment.StaticConfigSource \ No newline at end of file diff --git a/jvm-runtime/ftl-runtime/common/runtime/pom.xml b/jvm-runtime/ftl-runtime/common/runtime/pom.xml index d8b58c7940..1f0ac4cce3 100644 --- a/jvm-runtime/ftl-runtime/common/runtime/pom.xml +++ b/jvm-runtime/ftl-runtime/common/runtime/pom.xml @@ -24,6 +24,14 @@ io.quarkus quarkus-rest-jackson + + io.quarkus + quarkus-opentelemetry + + + io.opentelemetry.instrumentation + opentelemetry-jdbc + com.fasterxml.jackson.module jackson-module-kotlin diff --git a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/VerbHandler.java b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/VerbHandler.java index 50f6fac6f1..86c77aab87 100644 --- a/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/VerbHandler.java +++ b/jvm-runtime/ftl-runtime/common/runtime/src/main/java/xyz/block/ftl/runtime/VerbHandler.java @@ -1,8 +1,11 @@ package xyz.block.ftl.runtime; +import io.opentelemetry.api.metrics.DoubleGauge; import jakarta.inject.Singleton; import io.grpc.stub.StreamObserver; +import io.opentelemetry.api.metrics.LongCounter; +import io.opentelemetry.api.metrics.Meter; import io.quarkus.grpc.GrpcService; import xyz.block.ftl.v1.*; @@ -11,14 +14,21 @@ public class VerbHandler extends VerbServiceGrpc.VerbServiceImplBase { final VerbRegistry registry; + final LongCounter counter; - public VerbHandler(VerbRegistry registry) { + public VerbHandler(VerbRegistry registry, Meter meter) { this.registry = registry; + counter = meter.counterBuilder("ftl-jvm-runtime/verb_invocations") + .setDescription("The number of verb invocations") + .setUnit("invocations") + .build(); } @Override public void call(CallRequest request, StreamObserver responseObserver) { try { + counter.add(1); + var response = registry.invoke(request); responseObserver.onNext(response); responseObserver.onCompleted();