Skip to content

Commit

Permalink
Support base-endpoint-uri-exchange-event-notifier metrics parameter
Browse files Browse the repository at this point in the history
Closes #6960
  • Loading branch information
squakez authored and jamesnetherton committed Feb 11, 2025
1 parent 8678b35 commit c32fc7d
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 4 deletions.
8 changes: 8 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/micrometer.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics
| `boolean`
| `true`

|icon:lock[title=Fixed at build time] [[quarkus.camel.metrics.base-endpoint-uri-exchange-event-notifier]]`link:#quarkus.camel.metrics.base-endpoint-uri-exchange-event-notifier[quarkus.camel.metrics.base-endpoint-uri-exchange-event-notifier]`

Whether to use static or dynamic values for Endpoint Name tags in captured metrics. By default, static values are
used. When using dynamic tags, then a dynamic to (toD) can compute many different endpoint URIs that,
can lead to many tags as the URI is dynamic, so use this with care if setting this option to false.
| `boolean`
| `true`

|icon:lock[title=Fixed at build time] [[quarkus.camel.metrics.enable-route-event-notifier]]`link:#quarkus.camel.metrics.enable-route-event-notifier[quarkus.camel.metrics.enable-route-event-notifier]`

Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and total
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.micrometer.deployment;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Optional;
import java.util.Properties;

import io.quarkus.test.QuarkusUnitTest;
import jakarta.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
import org.apache.camel.spi.EventNotifier;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MicrometerBaseEndpointUriExchangeEventNotifierDisableTest {
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(applicationProperties(), "application.properties"));

@Inject
CamelContext context;

@Test
public void testBaseEndpointURIDisabled() {
Optional<EventNotifier> optionalExchangeEventNotifier = context.getManagementStrategy()
.getEventNotifiers()
.stream()
.filter(eventNotifier -> eventNotifier.getClass().equals(MicrometerExchangeEventNotifier.class))
.findFirst();
assertTrue(optionalExchangeEventNotifier.isPresent());

MicrometerExchangeEventNotifier eventNotifier = (MicrometerExchangeEventNotifier) optionalExchangeEventNotifier.get();
assertFalse(eventNotifier.isBaseEndpointURI());
}

public static Asset applicationProperties() {
Writer writer = new StringWriter();

Properties props = new Properties();
props.setProperty("quarkus.camel.metrics.base-endpoint-uri-exchange-event-notifier", "false");

try {
props.store(writer, "");
} catch (IOException e) {
throw new RuntimeException(e);
}

return new StringAsset(writer.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import jakarta.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategyLegacy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
Expand Down Expand Up @@ -93,7 +93,7 @@ void legacyNamingPolicy() {

MicrometerExchangeEventNotifier micrometerExchangeEventNotifier = (MicrometerExchangeEventNotifier) optionalExchangeEventNotifier
.get();
assertEquals(MicrometerExchangeEventNotifierNamingStrategy.LEGACY,
assertInstanceOf(MicrometerExchangeEventNotifierNamingStrategyLegacy.class,
micrometerExchangeEventNotifier.getNamingStrategy());

Optional<EventNotifier> optionalRouteEventNotifier = context.getManagementStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public interface CamelMicrometerConfig {
@WithDefault("true")
boolean enableExchangeEventNotifier();

/**
* Whether to use static or dynamic values for Endpoint Name tags in captured metrics. By default, static values are
* used. When using dynamic tags, then a dynamic to (toD) can compute many different endpoint URIs that,
* can lead to many tags as the URI is dynamic, so use this with care if setting this option to false.
*
* @asciidoclet
*/
@WithDefault("true")
public boolean baseEndpointURIExchangeEventNotifier();

/**
* Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and total
* number of routes running.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import org.apache.camel.CamelContext;
import org.apache.camel.component.micrometer.MicrometerUtils;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategyDefault;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategyLegacy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
Expand Down Expand Up @@ -92,8 +93,16 @@ public void configure(CamelContext camelContext) {
ManagementStrategy managementStrategy = camelContext.getManagementStrategy();
if (config.enableExchangeEventNotifier()) {
MicrometerExchangeEventNotifier eventNotifier = new MicrometerExchangeEventNotifier();
eventNotifier.setBaseEndpointURI(config.baseEndpointURIExchangeEventNotifier());

if (config.namingStrategy().equals(MetricsNamingStrategy.LEGACY)) {
eventNotifier.setNamingStrategy(MicrometerExchangeEventNotifierNamingStrategy.LEGACY);
eventNotifier.setNamingStrategy(
new MicrometerExchangeEventNotifierNamingStrategyLegacy(
config.baseEndpointURIExchangeEventNotifier()));
} else {
eventNotifier.setNamingStrategy(
new MicrometerExchangeEventNotifierNamingStrategyDefault(
config.baseEndpointURIExchangeEventNotifier()));
}
managementStrategy.addEventNotifier(eventNotifier);
}
Expand Down

0 comments on commit c32fc7d

Please sign in to comment.