You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2023/12/19 11:43:56 UTC
(camel) 02/07: Experiment
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch mm
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 453f2c36e5a634aa9351a5641784d09bfa4732fe
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 19 06:48:13 2023 +0100
Experiment
---
.../main/camel-main-configuration-metadata.json | 1 +
...rometerExchangeEventNotifierNamingStrategy.java | 23 +++++++++++++-----
.../jbang/core/commands/process/ListMetric.java | 28 +++++++++++++++++++++-
3 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
index d7d8b717315..3a1734b8152 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/main/camel-main-configuration-metadata.json
@@ -173,6 +173,7 @@
{ "name": "camel.lra.localParticipantContextPath", "description": "The context-path for the local participant. Is default \/lra-participant", "sourceType": "org.apache.camel.main.LraConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/lra-participant" },
{ "name": "camel.lra.localParticipantUrl", "description": "The URL for the local participant", "sourceType": "org.apache.camel.main.LraConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.metrics.binders", "description": "Additional Micrometer binders to include such as jvm-memory, processor, jvm-thread, and so forth. Multiple binders can be separated by comma. The following binders currently is available from Micrometer: class-loader, commons-object-pool2, file-descriptor, hystrix-metrics-binder, jvm-compilation, jvm-gc, jvm-heap-pressure, jvm-info, jvm-memory, jvm-thread, log4j2, logback, processor, uptime", "sourceType": "org.apache.camel.main.Metr [...]
+ { "name": "camel.metrics.clearOnReload", "description": "Clear the captured metrics data when Camel is reloading routes such as when using Camel JBang.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.enabled", "description": "To enable Micrometer metrics.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.metrics.enableExchangeEventNotifier", "description": "Set whether to enable the MicrometerExchangeEventNotifier for capturing metrics on exchange processing times.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.enableMessageHistory", "description": "Set whether to enable the MicrometerMessageHistoryFactory for capturing metrics on individual route node processing times. Depending on the number of configured route nodes, there is the potential to create a large volume of metrics. Therefore, this option is disabled by default.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
diff --git a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
index fdaa1c91053..065c7c1c38e 100644
--- a/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
+++ b/components/camel-micrometer/src/main/java/org/apache/camel/component/micrometer/eventnotifier/MicrometerExchangeEventNotifierNamingStrategy.java
@@ -69,12 +69,23 @@ public interface MicrometerExchangeEventNotifierNamingStrategy {
// use sanitized uri to not reveal sensitive information
uri = endpoint.toString();
}
- return Tags.of(
- CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
- SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
- EVENT_TYPE_TAG, event.getClass().getSimpleName(),
- ENDPOINT_NAME, uri,
- FAILED_TAG, Boolean.toString(event.getExchange().isFailed()));
+ String routeId = event.getExchange().getFromRouteId();
+ if (routeId != null) {
+ return Tags.of(
+ CAMEL_CONTEXT_TAG, event.getExchange().getContext().getName(),
+ SERVICE_NAME, MicrometerEventNotifierService.class.getSimpleName(),
+ 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(),
+ EVENT_TYPE_TAG, event.getClass().getSimpleName(),
+ ENDPOINT_NAME, uri,
+ FAILED_TAG, Boolean.toString(event.getExchange().isFailed()));
+ }
}
default Tags getInflightExchangesTags(ExchangeEvent event, Endpoint endpoint) {
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListMetric.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListMetric.java
index 6427b955a08..7b637e99a2d 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListMetric.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/process/ListMetric.java
@@ -19,6 +19,7 @@ package org.apache.camel.dsl.jbang.core.commands.process;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.StringJoiner;
import com.github.freva.asciitable.AsciiTable;
import com.github.freva.asciitable.Column;
@@ -48,6 +49,10 @@ public class ListMetric extends ProcessWatchCommand {
description = "Filter metric by type or name")
String filter;
+ @CommandLine.Option(names = { "--tags" },
+ description = "Show metric tags", defaultValue = "false")
+ boolean tags;
+
@CommandLine.Option(names = { "--custom" },
description = "Only show custom metrics", defaultValue = "false")
boolean custom;
@@ -96,6 +101,7 @@ public class ListMetric extends ProcessWatchCommand {
row.metricName = jo.getString("name");
row.metricDescription = jo.getString("description");
row.metricRouteId = extractRouteId(jo);
+ row.tags = extractTags(jo);
row.count = jo.getDouble("count");
if (custom && row.metricName.startsWith("Camel")) {
@@ -118,6 +124,7 @@ public class ListMetric extends ProcessWatchCommand {
row.metricName = jo.getString("name");
row.metricDescription = jo.getString("description");
row.metricRouteId = extractRouteId(jo);
+ row.tags = extractTags(jo);
row.count = jo.getDouble("count");
row.mean = jo.getDouble("mean");
row.max = jo.getDouble("max");
@@ -143,6 +150,7 @@ public class ListMetric extends ProcessWatchCommand {
row.metricName = jo.getString("name");
row.metricDescription = jo.getString("description");
row.metricRouteId = extractRouteId(jo);
+ row.tags = extractTags(jo);
row.count = jo.getDouble("value");
if (custom && row.metricName.startsWith("Camel")) {
@@ -165,6 +173,7 @@ public class ListMetric extends ProcessWatchCommand {
row.metricName = jo.getString("name");
row.metricDescription = jo.getString("description");
row.metricRouteId = extractRouteId(jo);
+ row.tags = extractTags(jo);
row.count = jo.getDouble("value");
row.mean = jo.getDouble("mean");
row.max = jo.getDouble("max");
@@ -205,7 +214,10 @@ public class ListMetric extends ProcessWatchCommand {
new Column().header("MAX").headerAlign(HorizontalAlign.RIGHT).dataAlign(HorizontalAlign.RIGHT)
.with(r -> getNumber(r.max)),
new Column().header("TOTAL").headerAlign(HorizontalAlign.RIGHT).dataAlign(HorizontalAlign.RIGHT)
- .with(r -> getNumber(r.total)))));
+ .with(r -> getNumber(r.total)),
+ new Column().header("TAGS").visible(tags).dataAlign(HorizontalAlign.LEFT)
+ .maxWidth(60, OverflowBehaviour.NEWLINE)
+ .with(r -> r.tags))));
}
return 0;
@@ -266,6 +278,19 @@ public class ListMetric extends ProcessWatchCommand {
return "";
}
+ private String extractTags(JsonObject jo) {
+ StringJoiner sj = new StringJoiner(" ");
+ List<JsonObject> tags = jo.getCollection("tags");
+ if (tags != null) {
+ for (JsonObject t : tags) {
+ String k = t.getString("key");
+ String v = t.getString("value");
+ sj.add(k + "=" + v);
+ }
+ }
+ return sj.toString();
+ }
+
private static class Row implements Cloneable {
String pid;
String name;
@@ -275,6 +300,7 @@ public class ListMetric extends ProcessWatchCommand {
String metricName;
String metricDescription;
String metricRouteId;
+ String tags;
double count;
double mean;
double max;