spring-boot metrics vs spring-cloud metrics

gadams00 Source

I've been playing with metrics in spring-boot and run into a bit of confusion around how spring-cloud seems to change the behavior.

A simple minimal spring-boot 1.3.3.RELEASE application with actuator and with a single controller:

@RestController
public class HelloController {

    @Autowired
    private CounterService counterService;

    @RequestMapping("/hello")
    public String sayHello(@RequestParam("name") String name) {
        counterService.increment("counter.calls.hello");
        return "Hello, " + name;
    }
}

the metrics endpoint for this application has

...
gauge.response.hello: 5,
gauge.response.metrics: 69,
gauge.response.star-star.favicon.ico: 2,
counter.status.200.star-star.favicon.ico: 4,
counter.status.200.metrics: 1,
counter.calls.hello: 5,
counter.status.200.hello: 5

which is as described in spring-boot docs. My custom counter (counter.calls.hello) functions as a counter as expected.

Now if I add spring-cloud-starter-eureka (Brixton.RC1) to my pom and don't change anything else, the metrics endpoint has

...
gauge.servo.counter.calls.hello: 1,
normalized.servo.rest.totaltime: 0,
normalized.servo.rest.count: 0,
gauge.servo.rest.min: 0,
gauge.servo.rest.max: 0,
gauge.servo.response.hello: 7,
gauge.servo.response.star-star.favicon.ico: 2,

the normal MVC metrics are gone. Where's the response code info? My custom counter is being reported as gauge.servo.counter.calls.hello, but it no longer works as a counter, it seems to just show a value of 1 even if I've made 5 calls to HelloController. A little debugging and searching led me to change the counter metric name to meter.calls.hello, which results in counter.servo.calls.hello in the metrics response, and restores counter functionality.

Further reading indicates that spring-cloud is defaulting servo for metrics and indicates that if I'm using java 8, I should be using spectator. Adding spring-cloud-starter-spectator to my pom, and going back to "counter.calls.hello" as the counter metric name, the metrics endpoint has

...
counter.calls.hello(): 3,
response.hello(): 7,
response.metrics(): 9,
response.star-star.favicon.ico(): 2,

this has even less built-in info about the rest endpoint, but my custom counter does seem to function.

Spring-cloud docs about metrics seem to indicate that I should be using ServoRegistry whether using servo or spectator. Terminology in the spectator metrics section is different. A counter doesn't work the way I'd expect. When I publish a simple hit counter using ServoRegistry as described in docs, I get back some kind of rate in the metrics endpoint.

Is there some added value in servo and/or spectator over what's provided by spring-boot? Spring-cloud docs indicate that there is more information being recorded to default controller metrics, but they're not showing up in /metrics. Should I just exclude ServoMetricsAutoConfiguration and use the spring-boot implementation?

spring-bootspring-cloud

Answers

answered 1 year ago Jon Ekdahl #1

According to the Spring Cloud Brixton documentation the advantage of Servo/Spectator metrics is that they are tagged (a.k.a. dimensional) while regular Spring Boot metrics are hierarchical.

Spring Boot

"counter.status.200.root": 20
"counter.status.400.root": 3

Netflix

"root(method=GET,status=200,statistic=count)": 20
"root(method=GET,status=400,statistic=count)": 3

Dimensional metrics allow more querying flexibility and by default, MVC requests are tagged with HTTP method, HTTP status, URI and exception (if the request handler threw an exception).

Unfortunately the dimensional Netflix metrics don't seem to translate well when they are shown in the /metrics actuator endpoint, so if all you need are the default request counters that Spring Boot provides in the metrics endpoint you'll be better off disabling the Servo configuration:

spring.metrics.servo.enabled=false

comments powered by Disqus