简体   繁体   中英

Use @Timed for inheritanced functions

We use a abstract classes for services like this pseudocode

abstract class AbstractApiService {
    @Timed(value="get", useClassPrefix=true)
    def get(Long id) {
       ... returns sth ....
    }

    @Timed(value="create", useClassPrefix=true)
    def create(Map params) {
        ... returns sth ....
    }
}

There are beans which inherit AbstractApiService and serve features like creating, deleting, updating entities like

class UserAccountService extends AbstractApiService {
    ... code ....
}

I would like to get metrics for each call a function from child classes like UserAccountService , but Prometheus sends events with full parent class prefix.

App is based on Grails 3.3.8

build.gradle:

compile 'com.moelholm:prometheus-spring-boot-starter:1.0.2' 
compile 'io.dropwizard.metrics:metrics-core:4.0.0-alpha2'
compile 'io.dropwizard.metrics:metrics-jvm:4.0.0-alpha2' 
compile 'org.grails.plugins:dropwizard-metrics:1.0.0.M2'

Unfortunately, I believe you will have to define the @Timed annotation for each method you want tracked. I don't think that the annotation code will spin up a separate metric for each concrete class.

我创建了一个自定义手动解决方案https://gist.github.com/michmzr/1e03534bc5fb6df89065f6964acf9c71

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM