grpc-ecosystem / grpc-spring

Spring Boot starter module for gRPC framework.
https://grpc-ecosystem.github.io/grpc-spring/
Apache License 2.0
3.52k stars 826 forks source link

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

Open ml-taehoon-choi opened 1 year ago

ml-taehoon-choi commented 1 year ago

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

ST-DDT commented 1 year ago

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

SOOHYUN-LIM commented 1 year ago

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
    }
}
k3vonk commented 7 months ago

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

aron9609 commented 5 months ago

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