Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Move fetch of metrics from endpoint so it too is retried #5143

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.helidon.microprofile.metrics;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import io.helidon.microprofile.tests.junit5.AddConfig;
import io.helidon.microprofile.tests.junit5.HelidonTest;
Expand All @@ -37,7 +38,6 @@
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.fail;

@HelidonTest
@AddConfig(key = "metrics." + MetricsCdiExtension.REST_ENDPOINTS_METRIC_ENABLED_PROPERTY_NAME, value = "true")
Expand Down Expand Up @@ -86,21 +86,23 @@ void checkForAsyncMethodRESTRequestMetric() throws NoSuchMethodException {
// Retrieve metrics again and make sure we see an additional count and added time. Don't bother checking the min and
// max because we'd have to wait up to a minute for those values to change.

JsonObject nextRestRequest = getRESTRequestJSON();

AtomicReference<JsonObject> nextRestRequest = new AtomicReference<>();
try {
// With async endpoints, metrics updates can occur after the server sends the response.
// Retry as needed for a little while for the count to change.
// Retry as needed (including fetching the metrics again) for a little while for the count to change.

assertThatWithRetry("getAsync count value after invocation",
() -> JsonNumber.class.cast(getRESTRequestValueForGetAsyncMethod(nextRestRequest,
"count",
false))
.longValue(),
() -> JsonNumber.class.cast(getRESTRequestValueForGetAsyncMethod(
// Set the reference using fresh metrics and get that newly-set JSON object, then
// extract the 'count' field cast as a number.
nextRestRequest.updateAndGet(old -> getRESTRequestJSON()),
"count",
false))
.longValue(),
is(1L));


getAsyncTime = JsonNumber.class.cast(getRESTRequestValueForGetAsyncMethod(nextRestRequest,
// Reuse (no need to update the atomic reference again) the freshly-fetched metrics JSON.
getAsyncTime = JsonNumber.class.cast(getRESTRequestValueForGetAsyncMethod(nextRestRequest.get(),
"elapsedTime",
false));
assertThat("getAsync elapsedTime value after invocation", getAsyncTime.longValue(), is(greaterThan(0L)));
Expand Down