bdelacretaz commented on a change in pull request #27:
URL: 
https://github.com/apache/sling-org-apache-sling-graphql-core/pull/27#discussion_r824706318



##########
File path: 
src/main/java/org/apache/sling/graphql/core/servlet/GraphQLServlet.java
##########
@@ -196,8 +196,11 @@ private void activate(Config config) {
         cacheMisses = metricsService.counter(METRIC_NS + "." + 
servletRegistrationProperties + ".cache_misses");
         requestsServed = metricsService.counter(METRIC_NS + "." + 
servletRegistrationProperties + ".requests_total");
         gaugeCacheHitRate = METRIC_NS + "." + servletRegistrationProperties + 
".cache_hit_rate";
-        metricRegistry.register(gaugeCacheHitRate,
-                (Gauge<Float>) () -> (cacheHits.getCount() / (float) 
(cacheHits.getCount() + cacheMisses.getCount())));
+        metricRegistry.register(gaugeCacheHitRate, (Gauge<Float>) () -> {
+            float hitCount = cacheHits.getCount();
+            float missCount = cacheMisses.getCount();
+            return hitCount > 0 || missCount > 0 ? hitCount / (hitCount + 
missCount) : 0.0f;

Review comment:
       I think testing for `missCount > 0` is sufficient to avoid NaN but 
that's a detail




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to