grpc-spring icon indicating copy to clipboard operation
grpc-spring copied to clipboard

Importing GrpcClientMetricAutoConfiguration disables some actuator metrics including hikari-cp, lettuce, jvm, ...

Open ml-taehoon-choi opened this issue 1 year ago • 4 comments

The bug When I use grpcClient in my server, I cannot see some metrics like jvm, hikari-cp, lettuce and so on from actuator/metrics endpoint. But if I comment out the GrpcClientMetricAutoConfiguration importing line, I can see the metrics.

Stacktrace and logs x

Steps to Reproduce

kotlin code to reproduce:

@SpringBootApplication
class SpringBootApplication

fun main(args: Array<String>) {
    runApplication<SpringBootApplication>(*args)
}

@Configuration
@ImportAutoConfiguration(
    value = [
        net.devh.boot.grpc.client.autoconfigure.GrpcClientAutoConfiguration::class,
        net.devh.boot.grpc.client.autoconfigure.GrpcClientMetricAutoConfiguration::class, // if you comment out this line, you can see jvm metrics.
        net.devh.boot.grpc.client.autoconfigure.GrpcClientHealthAutoConfiguration::class,
        net.devh.boot.grpc.client.autoconfigure.GrpcClientSecurityAutoConfiguration::class,
        net.devh.boot.grpc.client.autoconfigure.GrpcClientTraceAutoConfiguration::class,
        net.devh.boot.grpc.client.autoconfigure.GrpcDiscoveryClientAutoConfiguration::class,
    ]
)
class GrpcConfig

@Component
class A(
    @GrpcClient("test")
    private val stub: testStub, // you should change this line to provide a valid stub
)

dependencies in build.gradle.kts:

    implementation("org.springframework.boot:spring-boot-starter-web")
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("net.devh:grpc-client-spring-boot-starter:2.14.0.RELEASE")

application.properties:

management.endpoints.web.exposure.include=*

When you run the server and access localhost:8080/actuator/metrics, you cannot see jvm.* metrics. But if you comment out the GrpcClientMetricAutoConfiguration importing line, you can see jvm.* metrics.

The application's environment

  • Spring boot version: 3.0.2
  • grpc-client-spring-boot-starter version: net.devh:grpc-client-spring-boot-starter:2.14.0.RELEASE
  • java: 17 64bit osx

ml-taehoon-choi avatar Mar 09 '23 06:03 ml-taehoon-choi

This might be an input ordering issue. Try adding @AutoConfigureAfter or Import Springs new Metrics autoconfiguration.

ST-DDT avatar Mar 09 '23 08:03 ST-DDT

Fix:https://github.com/yidongnan/grpc-spring-boot-starter/pull/907

If the constructor injection is causing issues until the update. you can use the following approach:

@Component
class A {
    @GrpcClient("test")
    private lateinit var stub: TestStub
}

@Component
class A {
    private var stub: TestStub

    @GrpcClient("test")
    fun setStub(stub: TestStub) {
        this.stub = stub
    }
}

SOOHYUN-LIM avatar Jun 12 '23 05:06 SOOHYUN-LIM

Any update on this issue? As we would prefer to not use the above workaround.

k3vonk avatar Mar 12 '24 09:03 k3vonk

Hey guys, Are there any updates on this? We've just run into the same problem on our project

aron9609 avatar May 16 '24 12:05 aron9609