Challenge - 5 Problems
Micrometer Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Micrometer counter increment?
Consider this Spring Boot code snippet using Micrometer:
What is the value of
Counter counter = meterRegistry.counter("my.counter");
counter.increment();
counter.increment(2);What is the value of
counter.count() after these calls?Spring Boot
Counter counter = meterRegistry.counter("my.counter"); counter.increment(); counter.increment(2); double value = counter.count();
Attempts:
2 left
💡 Hint
Remember that each increment adds to the counter's total count.
✗ Incorrect
The counter starts at 0. The first increment adds 1, the second adds 2, so total is 3.0.
📝 Syntax
intermediate2:00remaining
Which option correctly registers a Gauge metric in Micrometer?
You want to register a Gauge metric named "queue.size" that tracks the size of a queue. Which code snippet is correct?
Attempts:
2 left
💡 Hint
The builder requires the object and a function to get the value.
✗ Incorrect
Option A correctly uses Gauge.builder with the object and a lambda to get the size, then registers it.
🔧 Debug
advanced2:00remaining
Why does this Timer metric not record durations correctly?
Given this code:
The printed count is always 0. What is the cause?
Timer timer = meterRegistry.timer("process.time");
timer.record(() -> {
// some process
Thread.sleep(100);
});
System.out.println(timer.count());The printed count is always 0. What is the cause?
Spring Boot
Timer timer = meterRegistry.timer("process.time"); timer.record(() -> { Thread.sleep(100); }); System.out.println(timer.count());
Attempts:
2 left
💡 Hint
Check if the lambda handles checked exceptions properly.
✗ Incorrect
Thread.sleep throws InterruptedException, which must be caught or declared. Without handling, the lambda fails silently and no timing occurs.
❓ state_output
advanced2:00remaining
What is the value of the Gauge after updating the tracked object?
Consider this code:
What is the value of
AtomicInteger value = new AtomicInteger(5);
Gauge gauge = Gauge.builder("current.value", value, AtomicInteger::get).register(meterRegistry);
value.set(10);
double gaugeValue = gauge.value();What is the value of
gaugeValue?Spring Boot
AtomicInteger value = new AtomicInteger(5); Gauge gauge = Gauge.builder("current.value", value, AtomicInteger::get).register(meterRegistry); value.set(10); double gaugeValue = gauge.value();
Attempts:
2 left
💡 Hint
Gauge reads the current value from the object each time it is queried.
✗ Incorrect
Gauge calls AtomicInteger::get on the current object, so after setting to 10, gauge.value() returns 10.0.
🧠 Conceptual
expert2:00remaining
Which Micrometer meter type is best to measure the rate of events per second?
You want to monitor how many requests your service receives per second. Which Micrometer meter type should you use?
Attempts:
2 left
💡 Hint
Think about a metric that only increases and can be used to calculate rates.
✗ Incorrect
Counter is a meter that only increases and is used to count events, which can be used to calculate rates like requests per second.