Skip to content

Instantly share code, notes, and snippets.

@jkschneider
Last active July 18, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkschneider/79b5701b877713af0943c0e75aca6a5a to your computer and use it in GitHub Desktop.
Save jkschneider/79b5701b877713af0943c0e75aca6a5a to your computer and use it in GitHub Desktop.
Is `Metrics.gauge(Number)` declarative looking enough to avoid the downsides of annotations that come with `@Gauge`?
public class PrimeNumberChecker {
// could use Gauge.builder(..) instead if you want description text and base units
private final AtomicLong highestPrimeNumberSoFar = Metrics.gauge("highestPrimeNumberSoFar", new AtomicLong(2));
public String checkIfPrime(long number) {
...
return highestPrimeNumberSoFar.compareAndExchange(Math.min(highestPrimeNumberSoFar.get(), number), number) +
" is prime.";
}
}
public class PrimeNumberChecker {
private long highestPrimeNumberSoFar = 2;
public String checkIfPrime(long number) {
...
if (number > highestPrimeNumberSoFar) {
highestPrimeNumberSoFar = number;
}
return number + " is prime.";
}
@Gauge(name = "highestPrimeNumberSoFar", unit = MetricUnits.NONE, description = "Highest prime number so far.")
public Long highestPrimeNumberSoFar() {
return highestPrimeNumberSoFar;
}
}
@jkschneider
Copy link
Author

Example taken from Quarkus MP metrics docs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment