This is an automated email from the ASF dual-hosted git repository. rcordier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 0b7d1beb876a19f8feadf0fcb259376b4218ef0c Author: LanKhuat <[email protected]> AuthorDate: Tue Jun 23 17:09:35 2020 +0700 JAMES-3269 Use SlidingWindowAverages --- .../james/metrics/dropwizard/DropWizardMetricFactory.java | 5 +++-- .../projections/MessageFastViewProjectionHealthCheck.java | 13 +++++++------ .../MessageFastViewProjectionHealthCheckTest.java | 12 ++++++------ .../FastViewProjectionHealthCheckIntegrationContract.java | 9 +++------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java index a647407..78f8a65 100644 --- a/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java +++ b/metrics/metrics-dropwizard/src/main/java/org/apache/james/metrics/dropwizard/DropWizardMetricFactory.java @@ -30,7 +30,9 @@ import org.apache.james.metrics.api.Metric; import org.apache.james.metrics.api.MetricFactory; import org.reactivestreams.Publisher; +import com.codahale.metrics.Meter; import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.SlidingTimeWindowMovingAverages; import com.codahale.metrics.jmx.JmxReporter; import reactor.core.publisher.Flux; @@ -50,7 +52,7 @@ public class DropWizardMetricFactory implements MetricFactory, Startable { @Override public Metric generate(String name) { - return new DropWizardMetric(metricRegistry.meter(name), name); + return new DropWizardMetric(metricRegistry.meter(name, () -> new Meter(new SlidingTimeWindowMovingAverages())), name); } @Override @@ -81,5 +83,4 @@ public class DropWizardMetricFactory implements MetricFactory, Startable { public void stop() { jmxReporter.stop(); } - } diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheck.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheck.java index 74f24b2..358de53 100644 --- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheck.java +++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheck.java @@ -64,13 +64,14 @@ public class MessageFastViewProjectionHealthCheck implements HealthCheck { }); } - private Result check(double hitCount, double missCount) { - double totalCount = hitCount + missCount; - double missCountPercentage = missCount * 100.0d / totalCount; - if (missCountPercentage > MAXIMUM_MISS_PERCENTAGE_ACCEPTED) { + private Result check(double hitAverage, double missAverage) { + double total = hitAverage + missAverage; + double missPercentage = missAverage * 100.0d / total; + + if (missPercentage > MAXIMUM_MISS_PERCENTAGE_ACCEPTED) { return Result.degraded(COMPONENT_NAME, - String.format("retrieveMissCount percentage %s%% (%s/%s) is higher than the threshold %s%%", - missCountPercentage, missCount, totalCount, MAXIMUM_MISS_PERCENTAGE_ACCEPTED)); + String.format("Miss percentage %.2f%% (%.0f/%.0f) is higher than the threshold %.0f%%", + missPercentage, missAverage, total, MAXIMUM_MISS_PERCENTAGE_ACCEPTED)); } return Result.healthy(COMPONENT_NAME); diff --git a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheckTest.java b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheckTest.java index da44964..54254b5 100644 --- a/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheckTest.java +++ b/server/data/data-jmap/src/test/java/org/apache/james/jmap/api/projections/MessageFastViewProjectionHealthCheckTest.java @@ -72,7 +72,7 @@ class MessageFastViewProjectionHealthCheckTest { missMetric.increment(); assertThat(testee.check().block()) - .isEqualTo(Result.degraded(COMPONENT_NAME, "retrieveMissCount percentage 100.0% (2.0/2.0) is higher than the threshold 10.0%")); + .isEqualTo(Result.degraded(COMPONENT_NAME, "Miss percentage 100.00% (2/2) is higher than the threshold 10%")); } @Test @@ -100,7 +100,7 @@ class MessageFastViewProjectionHealthCheckTest { assertThat(testee.check().block()) .isEqualTo(Result.degraded(COMPONENT_NAME, - "retrieveMissCount percentage 25.0% (1.0/4.0) is higher than the threshold 10.0%")); + "Miss percentage 25.00% (1/4) is higher than the threshold 10%")); } @Test @@ -116,7 +116,7 @@ class MessageFastViewProjectionHealthCheckTest { SoftAssertions.assertSoftly(softly -> { softly.assertThat(resultWithLessHit) .isEqualTo(Result.degraded(COMPONENT_NAME, - "retrieveMissCount percentage 50.0% (1.0/2.0) is higher than the threshold 10.0%")); + "Miss percentage 50.00% (1/2) is higher than the threshold 10%")); softly.assertThat(resultWithMoreHit) .isEqualTo(Result.healthy(COMPONENT_NAME)); }); @@ -135,10 +135,10 @@ class MessageFastViewProjectionHealthCheckTest { SoftAssertions.assertSoftly(softly -> { softly.assertThat(resultWithLessHit) .isEqualTo(Result.degraded(COMPONENT_NAME, - "retrieveMissCount percentage 50.0% (1.0/2.0) is higher than the threshold 10.0%")); + "Miss percentage 50.00% (1/2) is higher than the threshold 10%")); softly.assertThat(resultWithMoreHit) .isEqualTo(Result.degraded(COMPONENT_NAME, - "retrieveMissCount percentage 20.0% (1.0/5.0) is higher than the threshold 10.0%")); + "Miss percentage 20.00% (1/5) is higher than the threshold 10%")); }); } @@ -158,7 +158,7 @@ class MessageFastViewProjectionHealthCheckTest { softly.assertThat(resultWithEnoughOfHits) .isEqualTo(Result.healthy(COMPONENT_NAME)); softly.assertThat(resultWithMoreMiss) - .isEqualTo(Result.degraded(COMPONENT_NAME, "retrieveMissCount percentage 16.666666666666668% (2.0/12.0) is higher than the threshold 10.0%")); + .isEqualTo(Result.degraded(COMPONENT_NAME, "Miss percentage 16.67% (2/12) is higher than the threshold 10%")); }); } diff --git a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationContract.java b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationContract.java index 47c17f8..24acfa1 100644 --- a/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationContract.java +++ b/server/protocols/webadmin-integration-test/webadmin-integration-test-common/src/main/java/org/apache/james/webadmin/integration/FastViewProjectionHealthCheckIntegrationContract.java @@ -111,11 +111,10 @@ public abstract class FastViewProjectionHealthCheckIntegrationContract { } @Test - void checkShouldReturnDegradedAfterFewReadsOnAMissedProjection(GuiceJamesServer guiceJamesServer) { + void checkShouldReturnDegradedAfterFewReadsOnAMissedProjection(GuiceJamesServer guiceJamesServer) throws Exception { bobSendAMessageToAlice(); - guiceJamesServer.getProbe(JmapGuiceProbe.class) - .clearMessageFastViewProjection(); + makeHealthCheckDegraded(guiceJamesServer); IntStream.rangeClosed(1, 3) // Will miss at the first time as we cleared the preview .forEach(counter -> aliceReadLastMessage()); @@ -132,8 +131,7 @@ public abstract class FastViewProjectionHealthCheckIntegrationContract { @Test void checkShouldTurnFromDegradedToHealthyAfterMoreReadsOnAMissedProjection(GuiceJamesServer guiceJamesServer) { bobSendAMessageToAlice(); - calmlyAwait.untilAsserted(() -> assertThat(listMessageIdsForAccount(aliceAccessToken)) - .hasSize(1)); + makeHealthCheckDegraded(guiceJamesServer); IntStream.rangeClosed(1, 100) @@ -182,7 +180,6 @@ public abstract class FastViewProjectionHealthCheckIntegrationContract { .body() .path(ARGUMENTS + ".created." + messageCreationId + ".id"); - calmlyAwait.untilAsserted(() -> assertThat(listMessageIdsForAccount(aliceAccessToken)) .hasSize(1)); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
