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

CAMEL-20525: camel-micrometer - Rename tag to be Camel specific and m… #13454

Merged
merged 1 commit into from Mar 12, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -65,6 +65,11 @@ public final class MicrometerConstants {
public static final String EVENT_TYPE_TAG = "eventType";
public static final String METRICS_REGISTRY_NAME = "metricsRegistry";

public static final String KIND = "kind";
public static final String KIND_EXCHANGE = "CamelExchangeEvent";
public static final String KIND_ROUTE = "CamelRoute";
public static final String KIND_HISTORY = "CamelMessageHistory";
@Deprecated
public static final String SERVICE_NAME = "serviceName";
public static final String ENDPOINT_NAME = "endpointName";

Expand Down
Expand Up @@ -28,8 +28,9 @@
import org.apache.camel.support.EventNotifierSupport;
import org.apache.camel.support.service.ServiceHelper;

import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_EXCHANGE;
import static org.apache.camel.component.micrometer.MicrometerConstants.METRICS_REGISTRY_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;

public abstract class AbstractMicrometerEventNotifier<T extends CamelEvent> extends EventNotifierSupport
implements CamelContextAware {
Expand Down Expand Up @@ -99,7 +100,7 @@ protected void doStart() throws Exception {
registryService.setMeterRegistry(getMeterRegistry());
registryService.setPrettyPrint(isPrettyPrint());
registryService.setDurationUnit(getDurationUnit());
registryService.setMatchingTags(Tags.of(SERVICE_NAME, registryService.getClass().getSimpleName()));
registryService.setMatchingTags(Tags.of(KIND, KIND_EXCHANGE));
camelContext.addService(registryService);
// ensure registry service is started
ServiceHelper.startService(registryService);
Expand Down
Expand Up @@ -30,13 +30,14 @@
import static org.apache.camel.component.micrometer.MicrometerConstants.ENDPOINT_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.FAILED_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_EXCHANGE;
import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;

public interface MicrometerExchangeEventNotifierNamingStrategy {

Predicate<Meter.Id> EVENT_NOTIFIERS
= id -> MicrometerEventNotifierService.class.getSimpleName().equals(id.getTag(SERVICE_NAME));
= id -> KIND_EXCHANGE.equals(id.getTag(KIND));

/**
* Default naming strategy that uses micrometer naming convention.
Expand Down Expand Up @@ -73,15 +74,15 @@ default Tags getTags(ExchangeEvent event, Endpoint endpoint) {
if (routeId != null) {
return Tags.of(
CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
KIND, KIND_EXCHANGE,
EVENT_TYPE_TAG, event.getClass().getSimpleName(),
ROUTE_ID_TAG, routeId,
ENDPOINT_NAME, uri,
FAILED_TAG, Boolean.toString(event.getExchange().isFailed()));
} else {
return Tags.of(
CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
KIND, KIND_EXCHANGE,
EVENT_TYPE_TAG, event.getClass().getSimpleName(),
ENDPOINT_NAME, uri,
FAILED_TAG, Boolean.toString(event.getExchange().isFailed()));
Expand All @@ -92,12 +93,12 @@ default Tags getInflightExchangesTags(ExchangeEvent event, Endpoint endpoint) {
if (event.getExchange().getFromRouteId() != null) {
return Tags.of(
CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
KIND, KIND_EXCHANGE,
ROUTE_ID_TAG, event.getExchange().getFromRouteId());
} else {
return Tags.of(
CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName());
KIND, KIND_EXCHANGE);
}
}
}
Expand Up @@ -29,12 +29,13 @@
import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RELOADED;
import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTES_RUNNING;
import static org.apache.camel.component.micrometer.MicrometerConstants.EVENT_TYPE_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_ROUTE;

public interface MicrometerRouteEventNotifierNamingStrategy {

Predicate<Meter.Id> EVENT_NOTIFIERS
= id -> MicrometerEventNotifierService.class.getSimpleName().equals(id.getTag(SERVICE_NAME));
= id -> KIND_ROUTE.equals(id.getTag(KIND));

/**
* Default naming strategy that uses micrometer naming convention.
Expand Down Expand Up @@ -93,7 +94,7 @@ default String formatName(String name) {

default Tags getTags(CamelContext camelContext) {
return Tags.of(
SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
KIND, KIND_ROUTE,
CAMEL_CONTEXT_TAG, camelContext.getName(),
EVENT_TYPE_TAG, RouteEvent.class.getSimpleName());
}
Expand Down
Expand Up @@ -35,8 +35,9 @@
import org.apache.camel.support.PatternHelper;
import org.apache.camel.support.service.ServiceSupport;

import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_HISTORY;
import static org.apache.camel.component.micrometer.MicrometerConstants.METRICS_REGISTRY_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;

/**
* A factory to setup and use {@link MicrometerMessageHistory} as message history implementation.
Expand Down Expand Up @@ -168,8 +169,7 @@ protected void doStart() throws Exception {
messageHistoryService.setMeterRegistry(getMeterRegistry());
messageHistoryService.setPrettyPrint(isPrettyPrint());
messageHistoryService.setDurationUnit(getDurationUnit());
messageHistoryService
.setMatchingTags(Tags.of(SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName()));
messageHistoryService.setMatchingTags(Tags.of(KIND, KIND_HISTORY));
camelContext.addService(messageHistoryService);
}
} catch (Exception e) {
Expand Down
Expand Up @@ -26,17 +26,18 @@

import static org.apache.camel.component.micrometer.MicrometerConstants.CAMEL_CONTEXT_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_MESSAGE_HISTORY_METER_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_HISTORY;
import static org.apache.camel.component.micrometer.MicrometerConstants.NODE_ID_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.ROUTE_ID_TAG;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;

/**
* Provides a strategy to derive a meter name from the route and node
*/
public interface MicrometerMessageHistoryNamingStrategy {

Predicate<Meter.Id> MESSAGE_HISTORIES
= id -> MicrometerMessageHistoryService.class.getSimpleName().equals(id.getTag(SERVICE_NAME));
= id -> KIND_HISTORY.equals(id.getTag(KIND));

/**
* Default naming strategy that uses micrometer naming convention.
Expand All @@ -62,7 +63,7 @@ default String formatName(String name) {
default Tags getTags(Route route, NamedNode node) {
return Tags.of(
CAMEL_CONTEXT_TAG, route.getCamelContext().getName(),
SERVICE_NAME, MicrometerMessageHistoryService.class.getSimpleName(),
KIND, KIND_HISTORY,
ROUTE_ID_TAG, route.getId(),
NODE_ID_TAG, node.getId());
}
Expand Down
Expand Up @@ -39,8 +39,9 @@
import org.apache.camel.util.ObjectHelper;

import static org.apache.camel.component.micrometer.MicrometerConstants.DEFAULT_CAMEL_ROUTE_POLICY_METER_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND;
import static org.apache.camel.component.micrometer.MicrometerConstants.KIND_ROUTE;
import static org.apache.camel.component.micrometer.MicrometerConstants.METRICS_REGISTRY_NAME;
import static org.apache.camel.component.micrometer.MicrometerConstants.SERVICE_NAME;

/**
* A {@link org.apache.camel.spi.RoutePolicy} which gathers statistics and reports them using {@link MeterRegistry}.
Expand Down Expand Up @@ -286,7 +287,7 @@ public void onInit(Route route) {
registryService.setMeterRegistry(getMeterRegistry());
registryService.setPrettyPrint(isPrettyPrint());
registryService.setDurationUnit(getDurationUnit());
registryService.setMatchingTags(Tags.of(SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName()));
registryService.setMatchingTags(Tags.of(KIND, KIND_ROUTE));
route.getCamelContext().addService(registryService);
ServiceHelper.startService(registryService);
}
Expand Down
Expand Up @@ -31,8 +31,7 @@
*/
public interface MicrometerRoutePolicyNamingStrategy {

Predicate<Meter.Id> ROUTE_POLICIES
= id -> MicrometerRoutePolicyService.class.getSimpleName().equals(id.getTag(SERVICE_NAME));
Predicate<Meter.Id> ROUTE_POLICIES = id -> KIND_ROUTE.equals(id.getTag(KIND));

/**
* Default naming strategy that uses micrometer naming convention.
Expand Down Expand Up @@ -87,31 +86,31 @@ default String getLongTaskName(Route route) {
default Tags getTags(Route route) {
return Tags.of(
CAMEL_CONTEXT_TAG, route.getCamelContext().getName(),
SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(),
KIND, KIND_ROUTE,
ROUTE_ID_TAG, route.getId(),
EVENT_TYPE_TAG, "route");
}

default Tags getTags(CamelContext camelContext) {
return Tags.of(
CAMEL_CONTEXT_TAG, camelContext.getName(),
SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(),
KIND, KIND_ROUTE,
ROUTE_ID_TAG, "",
EVENT_TYPE_TAG, "context");
}

default Tags getExchangeStatusTags(Route route) {
return Tags.of(
CAMEL_CONTEXT_TAG, route.getCamelContext().getName(),
SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(),
KIND, KIND_ROUTE,
ROUTE_ID_TAG, route.getId(),
EVENT_TYPE_TAG, "route");
}

default Tags getExchangeStatusTags(CamelContext camelContext) {
return Tags.of(
CAMEL_CONTEXT_TAG, camelContext.getName(),
SERVICE_NAME, MicrometerRoutePolicyService.class.getSimpleName(),
KIND, KIND_ROUTE,
ROUTE_ID_TAG, "",
EVENT_TYPE_TAG, "context");
}
Expand Down
Expand Up @@ -196,6 +196,15 @@ on the `ManagementAgent` object. See more in the xref:jmx.adoc[JMX] documentatio

=== camel-micrometer and camel-metrics

The `camel-micrometer` have renamed tag `serviceName` to `kind` and use naming that indicate that its from Camel:

|===
|**Before** | **After**
| serviceName="MicrometerEventNotifierService" | kind="CamelExchangeEvent"
| serviceName="MicrometerMessageHistoryService" | kind="CamelMessageHistory"
| serviceName="MicrometerRoutePolicyService" | kind="CamelRoute"
|===

Due to Kamelets are changed to act more like a Camel component, and not expose internal details as JMX MBeans, then
micrometer and metrics no longer include statistics for those Kamelet routes.

Expand Down