Skip to content

Commit

Permalink
Merge pull request #609 from swisspost/use-set-for-metric
Browse files Browse the repository at this point in the history
Avoid usage of metrics where a history is kept
  • Loading branch information
dominik-cnx authored Sep 23, 2024
2 parents cc3d53d + 45f39c1 commit 231a50b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void stopRequestMetricTracking(final String metricName, long startTime, S
if (metricName != null) {
double duration = (System.nanoTime() - startTime) / 1000000d;
vertx.eventBus().publish(getMonitoringAddress(),
new JsonObject().put(METRIC_NAME, prefix + "routing." + metricName + ".duration").put(METRIC_ACTION, "update").put("n", duration));
new JsonObject().put(METRIC_NAME, prefix + "routing." + metricName + ".duration").put(METRIC_ACTION, "set").put("n", duration));
}
updatePendingRequestCount(false);
}
Expand Down Expand Up @@ -389,7 +389,7 @@ public void updateLastUsedQueueSizeInformation(final String queue) {
vertx.eventBus().request(getRedisquesAddress(), buildGetQueueItemsCountOperation(queue), (Handler<AsyncResult<Message<JsonObject>>>) reply -> {
if (reply.succeeded() && OK.equals(reply.result().body().getString(STATUS))) {
final long count = reply.result().body().getLong(VALUE);
vertx.eventBus().publish(getMonitoringAddress(), new JsonObject().put(METRIC_NAME, prefix + LAST_USED_QUEUE_SIZE_METRIC).put(METRIC_ACTION, "update").put("n", count));
vertx.eventBus().publish(getMonitoringAddress(), new JsonObject().put(METRIC_NAME, prefix + LAST_USED_QUEUE_SIZE_METRIC).put(METRIC_ACTION, "set").put("n", count));
} else {
log.error("Error gathering queue size for queue '{}'", queue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
@RunWith(VertxUnitRunner.class)
public class MonitoringTest extends AbstractTest {
Logger log = LoggerFactory.getLogger(MonitoringTest.class);

private static final long MAX_DURATION_THRESHOLD = 100;
private static final double MEAN_DURATION_THRESHOLD = 25.0;

/**
* Overwrite RestAssured configuration
*/
Expand Down Expand Up @@ -95,17 +91,7 @@ public void testStorageMetrics(TestContext context) throws Exception {

// read the jmx infos
if (mbs.isRegistered(beanNameObject)) {
log.info(" > Min: {}", mbs.getAttribute(beanNameObject, "Min"));
log.info(" > Mean: {}", mbs.getAttribute(beanNameObject, "Mean"));
log.info(" > Max: {}", mbs.getAttribute(beanNameObject, "Max"));
log.info(" > Count: {}", mbs.getAttribute(beanNameObject, "Count"));
log.info(" > StdDev: {}", mbs.getAttribute(beanNameObject, "StdDev"));

// check max threshold
context.assertTrue((Long) mbs.getAttribute(beanNameObject, "Max") <= MAX_DURATION_THRESHOLD, "'Max' should be below the threshold");

// checm mean threshold
context.assertTrue((Double) mbs.getAttribute(beanNameObject, "Mean") <= MEAN_DURATION_THRESHOLD, "'Mean' should be below the threshold");
log.info(" > Value: {}", mbs.getAttribute(beanNameObject, "Value"));
} else {
context.fail("could not found mbean " + beanName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ public void testDiscardPayloadQueueingStrategy(TestContext context) {
when().get("pushnotification/queuing/queues/")
.then().assertThat()
.body("queues", hasItem(queueName));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + queueName)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + queueName)
.then().assertThat()
.body(queueName, hasSize(3));

// check that no queue items do have a payload
String responseIndex0 = given().urlEncodingEnabled(true)
String responseIndex0 = given().urlEncodingEnabled(false)
.when().get("pushnotification/queuing/queues/" + queueName + "/0")
.then().extract().response().asString();
String responseIndex1 = given().urlEncodingEnabled(true)
String responseIndex1 = given().urlEncodingEnabled(false)
.when().get("pushnotification/queuing/queues/" + queueName + "/1")
.then().extract().response().asString();
String responseIndex2 = given().urlEncodingEnabled(true)
String responseIndex2 = given().urlEncodingEnabled(false)
.when().get("pushnotification/queuing/queues/" + queueName + "/2")
.then().extract().response().asString();

Expand Down Expand Up @@ -147,7 +147,7 @@ public void testReducedPropagationQueueingStrategy(TestContext context) {
.then().assertThat()
.body("queues", hasItem(queueName))
.body("queues", not(hasItem(managerQueue)));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + queueName)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + queueName)
.then().assertThat()
.body(queueName, hasSize(3));
when().get("pushnotification/queuing/locks/")
Expand All @@ -158,10 +158,10 @@ public void testReducedPropagationQueueingStrategy(TestContext context) {
// after 5s an unlocked manager queue with a single queue item should exist and the original queue should be empty
// and its lock should have been deleted
Awaitility.await().untilAsserted(() -> when().get("pushnotification/queuing/queues/").then().assertThat().body("queues", hasItem(managerQueue)));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + managerQueue)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + managerQueue)
.then().assertThat()
.body(managerQueue, hasSize(1));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + queueName)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + queueName)
.then().assertThat()
.body(queueName, empty());

Expand All @@ -181,7 +181,7 @@ public void testReducedPropagationQueueingStrategy(TestContext context) {
.then().assertThat()
.body("queues", hasItem(queueName))
.body("queues", hasItem(managerQueue));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + queueName)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + queueName)
.then().assertThat()
.body(queueName, hasSize(2));
when().get("pushnotification/queuing/locks/")
Expand All @@ -193,10 +193,10 @@ public void testReducedPropagationQueueingStrategy(TestContext context) {
// and its lock should have been deleted
TestUtils.waitSomeTime(5);
Awaitility.await().untilAsserted(() -> when().get("pushnotification/queuing/queues/").then().assertThat().body("queues", hasItem(managerQueue)));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + managerQueue)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + managerQueue)
.then().assertThat()
.body(managerQueue, hasSize(1));
given().urlEncodingEnabled(true).when().get("pushnotification/queuing/queues/" + queueName)
given().urlEncodingEnabled(false).when().get("pushnotification/queuing/queues/" + queueName)
.then().assertThat()
.body(queueName, empty());

Expand Down

0 comments on commit 231a50b

Please # to comment.