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

Workaround AdviceWithRouteBuilder and MicroprofileMetrics conflict #1915

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public MicroProfileMetricsContextCustomizer(CamelMicroProfileMetricsConfig confi
@Override
public void customize(CamelContext camelContext) {
if (config.enableRoutePolicy) {
camelContext.addRoutePolicyFactory(new MicroProfileMetricsRoutePolicyFactory());
MicroProfileMetricsRoutePolicyFactory routePolicyFactory = new MicroProfileMetricsRoutePolicyFactory();
// TODO: Remove this after upgrade to Camel >= 3.6.0
// https://github.com/apache/camel-quarkus/issues/1894
routePolicyFactory.setMetricRegistry(MetricRegistries.get(MetricRegistry.Type.APPLICATION));
camelContext.addRoutePolicyFactory(routePolicyFactory);
}

ManagementStrategy managementStrategy = camelContext.getManagementStrategy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;

import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.AdviceWithRouteBuilder;

@Path("/microprofile-metrics")
@ApplicationScoped
Expand All @@ -32,6 +34,9 @@ public class MicroProfileMetricsResource {
@Inject
ProducerTemplate template;

@Inject
CamelContext context;

@Path("/counter")
@GET
public Response counterIncrement() throws Exception {
Expand Down Expand Up @@ -87,4 +92,13 @@ public Response logMessage() throws Exception {
template.sendBody("log:message", "Test log message");
return Response.ok().build();
}

@Path("/advicewith")
@GET
public Response adviceWith() throws Exception {
AdviceWithRouteBuilder.adviceWith(context, "log", advisor -> {
advisor.replaceFromWith("direct:replaced");
});
return Response.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,8 @@ public void configure() {
.to("microprofile-metrics:timer:camel-quarkus-timer?action=start")
.delay(100)
.to("microprofile-metrics:timer:camel-quarkus-timer?action=stop");

from("direct:log").routeId("log")
.log("Camel Quarkus MicroProfile Metrics");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ public void testMicroProfileMetricsCamelContextEventNotifier() {
assertTrue(getMetricIntValue("camel.context.uptime") > 0);
}

@Test
public void testAdviceWith() {
RestAssured.get("/microprofile-metrics/advicewith")
.then()
.statusCode(200);
assertTrue(getMetricIntValue("camel.route.count") >= 7);
assertTrue(getMetricIntValue("camel.route.running.count") >= 7);
}

private int getMetricIntValue(String metricName, String... tags) {
return getApplicationMetrics().getInt(sanitizeMetricName(metricName, tags));
}
Expand All @@ -139,10 +148,6 @@ private float getMetricFloatValue(String metricName, String... tags) {
return getApplicationMetrics().getFloat(sanitizeMetricName(metricName, tags));
}

private Map<String, Object> getMetricMapValue(String metricName, String... tags) {
return getApplicationMetrics().getMap(sanitizeMetricName(metricName, tags));
}

private String sanitizeMetricName(String metricName, String... tags) {
if (tags.length == 0) {
tags = new String[] { CAMEL_CONTEXT_METRIC_TAG };
Expand Down