Last active
July 18, 2020 21:22
-
-
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`?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example taken from Quarkus MP metrics docs here.