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

Add Micrometer naming strategy and route policy level configuration options #5951

Merged
merged 1 commit into from
Apr 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/micrometer.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on
Set whether to gather performance information about Camel Thread Pools by injecting an InstrumentedThreadPoolFactory.
| `boolean`
| `false`

|icon:lock[title=Fixed at build time] [[quarkus.camel.metrics.naming-strategy]]`link:#quarkus.camel.metrics.naming-strategy[quarkus.camel.metrics.naming-strategy]`

Controls the naming style to use for metrics. The available values are `default` and `legacy`. `default` uses the default Micrometer naming convention. `legacy` uses the legacy camel-case naming style.
| `org.apache.camel.quarkus.component.micrometer.CamelMicrometerConfig.MetricsNamingStrategy`
| `default`

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

Sets the level of metrics to capture. The available values are `all` ,`context` and `route`. `all` captures metrics for both the camel context and routes. `route` captures metrics for routes only. `context` captures metrics for the camel context only.
| `org.apache.camel.quarkus.component.micrometer.CamelMicrometerConfig.RoutePolicyLevel`
| `all`
|===

[.configuration-legend]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MicrometerInstrumentCoreThreadPoolTest {

Expand All @@ -50,10 +50,10 @@ public class MicrometerInstrumentCoreThreadPoolTest {
public void testInstrumentedThreadPoolFactory() {
ThreadPoolFactory threadPoolFactory = context.getExecutorServiceManager().getThreadPoolFactory();
assertNotNull(threadPoolFactory);
assertTrue(threadPoolFactory instanceof InstrumentedThreadPoolFactory);
assertInstanceOf(InstrumentedThreadPoolFactory.class, threadPoolFactory);
}

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

Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
package org.apache.camel.quarkus.component.micrometer.deployment;

import java.util.List;
import java.util.stream.Collectors;
import java.util.Optional;

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.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyConfiguration;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyNamingStrategy;
import org.apache.camel.component.micrometer.spi.InstrumentedThreadPoolFactory;
import org.apache.camel.impl.engine.DefaultMessageHistoryFactory;
import org.apache.camel.spi.EventNotifier;
Expand All @@ -36,6 +42,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -52,19 +59,49 @@ public class MicrometerMetricsConfigDefaultsTest {
public void testMicrometerMetricsConfiguration() {
List<RoutePolicyFactory> routePolicyFactories = context.getRoutePolicyFactories();
assertEquals(1, routePolicyFactories.size());
assertTrue(routePolicyFactories.get(0) instanceof MicrometerRoutePolicyFactory);
RoutePolicyFactory routePolicyFactory = routePolicyFactories.get(0);
assertInstanceOf(MicrometerRoutePolicyFactory.class, routePolicyFactory);
MicrometerRoutePolicyFactory micrometerRoutePolicyFactory = (MicrometerRoutePolicyFactory) routePolicyFactory;
assertEquals(MicrometerRoutePolicyNamingStrategy.DEFAULT, micrometerRoutePolicyFactory.getNamingStrategy());

MicrometerRoutePolicyConfiguration policyConfiguration = micrometerRoutePolicyFactory.getPolicyConfiguration();
assertTrue(policyConfiguration.isContextEnabled());
assertTrue(policyConfiguration.isRouteEnabled());

MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory();
assertNotNull(messageHistoryFactory);
assertTrue(messageHistoryFactory instanceof DefaultMessageHistoryFactory);
assertInstanceOf(DefaultMessageHistoryFactory.class, messageHistoryFactory);

List<EventNotifier> eventNotifiers = context.getManagementStrategy()
.getEventNotifiers()
.stream()
.filter(eventNotifier -> !eventNotifier.getClass().getName().contains("BaseMainSupport"))
.collect(Collectors.toList());
.toList();
assertEquals(3, eventNotifiers.size());

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

MicrometerExchangeEventNotifier micrometerExchangeEventNotifier = (MicrometerExchangeEventNotifier) optionalExchangeEventNotifier
.get();
assertEquals(MicrometerExchangeEventNotifierNamingStrategy.DEFAULT,
micrometerExchangeEventNotifier.getNamingStrategy());

Optional<EventNotifier> optionalRouteEventNotifier = context.getManagementStrategy()
.getEventNotifiers()
.stream()
.filter(eventNotifier -> eventNotifier.getClass().equals(MicrometerRouteEventNotifier.class))
.findFirst();
assertTrue(optionalRouteEventNotifier.isPresent());

MicrometerRouteEventNotifier micrometerRouteEventNotifier = (MicrometerRouteEventNotifier) optionalRouteEventNotifier
.get();
assertEquals(MicrometerRouteEventNotifierNamingStrategy.DEFAULT, micrometerRouteEventNotifier.getNamingStrategy());

ThreadPoolFactory threadPoolFactory = context.getExecutorServiceManager().getThreadPoolFactory();
assertNotNull(threadPoolFactory);
assertFalse(threadPoolFactory instanceof InstrumentedThreadPoolFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jakarta.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryNamingStrategy;
import org.apache.camel.spi.MessageHistoryFactory;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
Expand All @@ -33,6 +34,8 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -52,10 +55,13 @@ public void testMicroProfileMetricsConfiguration() {

MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory();
assertNotNull(messageHistoryFactory);
assertTrue(messageHistoryFactory instanceof MicrometerMessageHistoryFactory);
assertInstanceOf(MicrometerMessageHistoryFactory.class, messageHistoryFactory);

MicrometerMessageHistoryFactory micrometerMessageHistoryFactory = (MicrometerMessageHistoryFactory) messageHistoryFactory;
assertEquals(MicrometerMessageHistoryNamingStrategy.DEFAULT, micrometerMessageHistoryFactory.getNamingStrategy());
}

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

Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* 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.List;
import java.util.Properties;

import io.quarkus.test.QuarkusUnitTest;
import jakarta.inject.Inject;
import org.apache.camel.CamelContext;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyConfiguration;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
import org.apache.camel.spi.RoutePolicyFactory;
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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

@Inject
CamelContext context;

@Test
void contextRoutePolicy() {
List<RoutePolicyFactory> routePolicyFactories = context.getRoutePolicyFactories();
assertEquals(1, routePolicyFactories.size());
RoutePolicyFactory routePolicyFactory = routePolicyFactories.get(0);
assertInstanceOf(MicrometerRoutePolicyFactory.class, routePolicyFactory);

MicrometerRoutePolicyFactory micrometerRoutePolicyFactory = (MicrometerRoutePolicyFactory) routePolicyFactory;
MicrometerRoutePolicyConfiguration policyConfiguration = micrometerRoutePolicyFactory.getPolicyConfiguration();
assertTrue(policyConfiguration.isContextEnabled());
assertFalse(policyConfiguration.isRouteEnabled());
}

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

Properties props = new Properties();
props.setProperty("quarkus.camel.metrics.route-policy-level", "context");

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 @@ -35,6 +35,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -55,10 +56,10 @@ public void testMicrometerMetricsDisabled() {

MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory();
assertNotNull(messageHistoryFactory);
assertTrue(messageHistoryFactory instanceof DefaultMessageHistoryFactory);
assertInstanceOf(DefaultMessageHistoryFactory.class, messageHistoryFactory);
}

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

Properties props = new Properties();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/*
* 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.List;
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.component.micrometer.eventnotifier.MicrometerExchangeEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifier;
import org.apache.camel.component.micrometer.eventnotifier.MicrometerRouteEventNotifierNamingStrategy;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryFactory;
import org.apache.camel.component.micrometer.messagehistory.MicrometerMessageHistoryNamingStrategy;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyFactory;
import org.apache.camel.component.micrometer.routepolicy.MicrometerRoutePolicyNamingStrategy;
import org.apache.camel.component.micrometer.spi.InstrumentedThreadPoolFactory;
import org.apache.camel.spi.EventNotifier;
import org.apache.camel.spi.MessageHistoryFactory;
import org.apache.camel.spi.RoutePolicyFactory;
import org.apache.camel.spi.ThreadPoolFactory;
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.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

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

@Inject
CamelContext context;

@Test
void legacyNamingPolicy() {
List<RoutePolicyFactory> routePolicyFactories = context.getRoutePolicyFactories();
assertEquals(1, routePolicyFactories.size());
RoutePolicyFactory routePolicyFactory = routePolicyFactories.get(0);
assertInstanceOf(MicrometerRoutePolicyFactory.class, routePolicyFactory);
MicrometerRoutePolicyFactory micrometerRoutePolicyFactory = (MicrometerRoutePolicyFactory) routePolicyFactory;
assertEquals(MicrometerRoutePolicyNamingStrategy.LEGACY, micrometerRoutePolicyFactory.getNamingStrategy());

MessageHistoryFactory messageHistoryFactory = context.getMessageHistoryFactory();
assertNotNull(messageHistoryFactory);
assertInstanceOf(MicrometerMessageHistoryFactory.class, messageHistoryFactory);

MicrometerMessageHistoryFactory micrometerMessageHistoryFactory = (MicrometerMessageHistoryFactory) messageHistoryFactory;
assertEquals(MicrometerMessageHistoryNamingStrategy.LEGACY, micrometerMessageHistoryFactory.getNamingStrategy());

List<EventNotifier> eventNotifiers = context.getManagementStrategy()
.getEventNotifiers()
.stream()
.filter(eventNotifier -> !eventNotifier.getClass().getName().contains("BaseMainSupport"))
.toList();
assertEquals(3, eventNotifiers.size());

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

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

Optional<EventNotifier> optionalRouteEventNotifier = context.getManagementStrategy()
.getEventNotifiers()
.stream()
.filter(eventNotifier -> eventNotifier.getClass().equals(MicrometerRouteEventNotifier.class))
.findFirst();
assertTrue(optionalRouteEventNotifier.isPresent());

MicrometerRouteEventNotifier micrometerRouteEventNotifier = (MicrometerRouteEventNotifier) optionalRouteEventNotifier
.get();
assertEquals(MicrometerRouteEventNotifierNamingStrategy.LEGACY, micrometerRouteEventNotifier.getNamingStrategy());

ThreadPoolFactory threadPoolFactory = context.getExecutorServiceManager().getThreadPoolFactory();
assertNotNull(threadPoolFactory);
assertFalse(threadPoolFactory instanceof InstrumentedThreadPoolFactory);
}

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

Properties props = new Properties();
props.setProperty("quarkus.camel.metrics.naming-strategy", "legacy");
props.setProperty("quarkus.camel.metrics.enable-message-history", "true");

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

return new StringAsset(writer.toString());
}
}
Loading
Loading