Skip to content

Commit

Permalink
Merge pull request quarkusio#36039 from alesj/mm_grpc_cnfe
Browse files Browse the repository at this point in the history
Fix gRPC interceptors lookup in Micrometer binders
  • Loading branch information
ebullient authored Sep 20, 2023
2 parents c3149c3 + e8c1ec1 commit 76348f3
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.function.BooleanSupplier;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.bootstrap.classloading.QuarkusClassLoader;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalIndexedClassesBuildItem;
import io.quarkus.micrometer.runtime.MicrometerRecorder;
import io.quarkus.micrometer.runtime.config.MicrometerConfig;

/**
Expand All @@ -22,27 +22,27 @@ public class GrpcBinderProcessor {
static final String CLIENT_INTERCEPTOR = "io.grpc.ClientInterceptor";
static final String SERVER_INTERCEPTOR = "io.grpc.ServerInterceptor";

static final Class<?> CLIENT_INTERCEPTOR_CLASS = MicrometerRecorder.getClassForName(CLIENT_INTERCEPTOR);
static final Class<?> SERVER_INTERCEPTOR_CLASS = MicrometerRecorder.getClassForName(SERVER_INTERCEPTOR);

static class GrpcClientSupportEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return CLIENT_INTERCEPTOR_CLASS != null && mConfig.checkBinderEnabledWithDefault(mConfig.binder.grpcClient);
return QuarkusClassLoader.isClassPresentAtRuntime(CLIENT_INTERCEPTOR)
&& mConfig.checkBinderEnabledWithDefault(mConfig.binder.grpcClient);
}
}

static class GrpcServerSupportEnabled implements BooleanSupplier {
MicrometerConfig mConfig;

public boolean getAsBoolean() {
return SERVER_INTERCEPTOR_CLASS != null && mConfig.checkBinderEnabledWithDefault(mConfig.binder.grpcServer);
return QuarkusClassLoader.isClassPresentAtRuntime(SERVER_INTERCEPTOR)
&& mConfig.checkBinderEnabledWithDefault(mConfig.binder.grpcServer);
}
}

@BuildStep(onlyIf = GrpcClientSupportEnabled.class)
AdditionalBeanBuildItem addGrpcClientMetricInterceptor() {
AdditionalBeanBuildItem addGrpcClientMetricInterceptor(BuildProducer<AdditionalIndexedClassesBuildItem> producer) {
producer.produce(new AdditionalIndexedClassesBuildItem(CLIENT_GRPC_METRICS_INTERCEPTOR));
return AdditionalBeanBuildItem.unremovableOf(CLIENT_GRPC_METRICS_INTERCEPTOR);
}

Expand Down

0 comments on commit 76348f3

Please sign in to comment.