Skip to content

Commit

Permalink
fix(components): Micrometer Prometheus configurable path
Browse files Browse the repository at this point in the history
  • Loading branch information
squakez committed Nov 12, 2024
1 parent b10284d commit ab8202f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
{ "name": "camel.metrics.enableRouteEventNotifier", "description": "Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and total number of routes running.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.enableRoutePolicy", "description": "Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.namingStrategy", "description": "Controls the name style to use for metrics. Default = uses micrometer naming convention. Legacy = uses the classic naming style (camelCase)", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "default", "enum": [ "default", "legacy" ] },
{ "name": "camel.metrics.path", "description": "The path endpoint used to expose the metrics.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/q\/metrics" },
{ "name": "camel.metrics.routePolicyLevel", "description": "Sets the level of information to capture. all = both context and routes.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "all", "enum": [ "all", "route", "context" ] },
{ "name": "camel.metrics.textFormatVersion", "description": "The text-format version to use with Prometheus scraping. 0.0.4 = text\/plain; version=0.0.4; charset=utf-8 1.0.0 = application\/openmetrics-text; version=1.0.0; charset=utf-8", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.4", "enum": [ "0.0.4", "1.0.0" ] },
{ "name": "camel.opentelemetry.enabled", "description": "To enable OpenTelemetry", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down Expand Up @@ -275,7 +276,7 @@
{ "name": "camel.server.jwtKeystorePath", "description": "Path to the keystore file used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.server.jwtKeystoreType", "description": "Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.server.maxBodySize", "description": "Maximum HTTP body size the embedded HTTP server can accept.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "java.lang.Long" },
{ "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics (default)", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" },
{ "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 },
{ "name": "camel.server.sendEnabled", "description": "Whether to enable sending messages to Camel via HTTP. This makes it possible to use Camel to send messages to Camel endpoint URIs via HTTP.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "enableRoutePolicy": target.setEnableRoutePolicy(property(camelContext, boolean.class, value)); return true;
case "namingstrategy":
case "namingStrategy": target.setNamingStrategy(property(camelContext, java.lang.String.class, value)); return true;
case "path": target.setPath(property(camelContext, java.lang.String.class, value)); return true;
case "routepolicylevel":
case "routePolicyLevel": target.setRoutePolicyLevel(property(camelContext, java.lang.String.class, value)); return true;
case "textformatversion":
Expand All @@ -64,6 +65,7 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "enableRoutePolicy": return boolean.class;
case "namingstrategy":
case "namingStrategy": return java.lang.String.class;
case "path": return java.lang.String.class;
case "routepolicylevel":
case "routePolicyLevel": return java.lang.String.class;
case "textformatversion":
Expand Down Expand Up @@ -91,6 +93,7 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "enableRoutePolicy": return target.isEnableRoutePolicy();
case "namingstrategy":
case "namingStrategy": return target.getNamingStrategy();
case "path": return target.getPath();
case "routepolicylevel":
case "routePolicyLevel": return target.getRoutePolicyLevel();
case "textformatversion":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ public class MicrometerPrometheus extends ServiceSupport implements CamelMetrics
private String textFormatVersion = "0.0.4";
@Metadata
private String binders;
@Metadata(defaultValue = "/q/metrics")
private String path = "/q/metrics";

@Override
public CamelContext getCamelContext() {
Expand Down Expand Up @@ -210,6 +212,17 @@ public void setTextFormatVersion(String textFormatVersion) {
this.textFormatVersion = textFormatVersion;
}

public String getPath() {
return path;
}

/**
* The path endpoint used to expose the metrics.
*/
public void setPath(String path) {
this.path = path;
}

public String getBinders() {
return binders;
}
Expand Down Expand Up @@ -353,7 +366,7 @@ protected void doStart() throws Exception {

if (server != null && server.isMetricsEnabled() && router != null && platformHttpComponent != null) {
setupHttpScraper();
LOG.info("MicrometerPrometheus enabled with HTTP scraping on /q/metrics");
LOG.info("MicrometerPrometheus enabled with HTTP scraping on {}", path);
} else {
LOG.info("MicrometerPrometheus enabled");
}
Expand Down Expand Up @@ -387,7 +400,7 @@ protected void doShutdown() throws Exception {
}

protected void setupHttpScraper() {
Route metrics = router.route("/q/metrics");
Route metrics = router.route(path);
metrics.method(HttpMethod.GET);

final String format
Expand All @@ -413,7 +426,7 @@ public void handle(RoutingContext ctx) {
// use blocking handler as the task can take longer time to complete
metrics.handler(new BlockingHandlerDecorator(handler, true));

platformHttpComponent.addHttpEndpoint("/q/metrics", "GET",
platformHttpComponent.addHttpEndpoint(path, "GET",
null, format, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MetricsConfigurationPropertiesConfigurer extends org.apache.camel.s
map.put("EnableRoutePolicy", boolean.class);
map.put("Enabled", boolean.class);
map.put("NamingStrategy", java.lang.String.class);
map.put("Path", java.lang.String.class);
map.put("RoutePolicyLevel", java.lang.String.class);
map.put("TextFormatVersion", java.lang.String.class);
ALL_OPTIONS = map;
Expand All @@ -54,6 +55,7 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj
case "enabled": target.setEnabled(property(camelContext, boolean.class, value)); return true;
case "namingstrategy":
case "namingStrategy": target.setNamingStrategy(property(camelContext, java.lang.String.class, value)); return true;
case "path": target.setPath(property(camelContext, java.lang.String.class, value)); return true;
case "routepolicylevel":
case "routePolicyLevel": target.setRoutePolicyLevel(property(camelContext, java.lang.String.class, value)); return true;
case "textformatversion":
Expand Down Expand Up @@ -88,6 +90,7 @@ public Class<?> getOptionType(String name, boolean ignoreCase) {
case "enabled": return boolean.class;
case "namingstrategy":
case "namingStrategy": return java.lang.String.class;
case "path": return java.lang.String.class;
case "routepolicylevel":
case "routePolicyLevel": return java.lang.String.class;
case "textformatversion":
Expand All @@ -114,6 +117,7 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) {
case "enabled": return target.isEnabled();
case "namingstrategy":
case "namingStrategy": return target.getNamingStrategy();
case "path": return target.getPath();
case "routepolicylevel":
case "routePolicyLevel": return target.getRoutePolicyLevel();
case "textformatversion":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
{ "name": "camel.metrics.enableRouteEventNotifier", "description": "Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and total number of routes running.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.enableRoutePolicy", "description": "Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": true },
{ "name": "camel.metrics.namingStrategy", "description": "Controls the name style to use for metrics. Default = uses micrometer naming convention. Legacy = uses the classic naming style (camelCase)", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "default", "enum": [ "default", "legacy" ] },
{ "name": "camel.metrics.path", "description": "The path endpoint used to expose the metrics.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/q\/metrics" },
{ "name": "camel.metrics.routePolicyLevel", "description": "Sets the level of information to capture. all = both context and routes.", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "all", "enum": [ "all", "route", "context" ] },
{ "name": "camel.metrics.textFormatVersion", "description": "The text-format version to use with Prometheus scraping. 0.0.4 = text\/plain; version=0.0.4; charset=utf-8 1.0.0 = application\/openmetrics-text; version=1.0.0; charset=utf-8", "sourceType": "org.apache.camel.main.MetricsConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "0.0.4", "enum": [ "0.0.4", "1.0.0" ] },
{ "name": "camel.opentelemetry.enabled", "description": "To enable OpenTelemetry", "sourceType": "org.apache.camel.main.OtelConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down Expand Up @@ -275,7 +276,7 @@
{ "name": "camel.server.jwtKeystorePath", "description": "Path to the keystore file used for JWT tokens validation.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.server.jwtKeystoreType", "description": "Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.).", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String" },
{ "name": "camel.server.maxBodySize", "description": "Maximum HTTP body size the embedded HTTP server can accept.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "java.lang.Long" },
{ "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.metricsEnabled", "description": "Whether to enable metrics. If enabled then you can access metrics on context-path: \/q\/metrics (default)", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
{ "name": "camel.server.path", "description": "Context-path to use for embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "string", "javaType": "java.lang.String", "defaultValue": "\/" },
{ "name": "camel.server.port", "description": "Port to use for binding embedded HTTP server", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "integer", "javaType": "int", "defaultValue": 8080 },
{ "name": "camel.server.sendEnabled", "description": "Whether to enable sending messages to Camel via HTTP. This makes it possible to use Camel to send messages to Camel endpoint URIs via HTTP.", "sourceType": "org.apache.camel.main.HttpServerConfigurationProperties", "type": "boolean", "javaType": "boolean", "defaultValue": "false" },
Expand Down
5 changes: 3 additions & 2 deletions core/camel-main/src/main/docs/main.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ The camel.server supports 23 options, which are listed below.
| *camel.server.jwtKeystorePath* | Path to the keystore file used for JWT tokens validation. | | String
| *camel.server.jwtKeystoreType* | Type of the keystore used for JWT tokens validation (jks, pkcs12, etc.). | | String
| *camel.server.maxBodySize* | Maximum HTTP body size the embedded HTTP server can accept. | | Long
| *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics | false | boolean
| *camel.server.metricsEnabled* | Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics (default) | false | boolean
| *camel.server.path* | Context-path to use for embedded HTTP server | / | String
| *camel.server.port* | Port to use for binding embedded HTTP server | 8080 | int
| *camel.server.sendEnabled* | Whether to enable sending messages to Camel via HTTP. This makes it possible to use Camel to send messages to Camel endpoint URIs via HTTP. | false | boolean
Expand Down Expand Up @@ -464,7 +464,7 @@ The camel.opentelemetry supports 5 options, which are listed below.


=== Camel Micrometer Metrics configurations
The camel.metrics supports 10 options, which are listed below.
The camel.metrics supports 11 options, which are listed below.

[width="100%",cols="2,5,^1,2",options="header"]
|===
Expand All @@ -477,6 +477,7 @@ The camel.metrics supports 10 options, which are listed below.
| *camel.metrics.enableRouteEvent{zwsp}Notifier* | Set whether to enable the MicrometerRouteEventNotifier for capturing metrics on the total number of routes and total number of routes running. | true | boolean
| *camel.metrics.enableRoute{zwsp}Policy* | Set whether to enable the MicrometerRoutePolicyFactory for capturing metrics on route processing times. | true | boolean
| *camel.metrics.namingStrategy* | Controls the name style to use for metrics. Default = uses micrometer naming convention. Legacy = uses the classic naming style (camelCase) | default | String
| *camel.metrics.path* | The path endpoint used to expose the metrics. | /q/metrics | String
| *camel.metrics.routePolicyLevel* | Sets the level of information to capture. all = both context and routes. | all | String
| *camel.metrics.textFormat{zwsp}Version* | The text-format version to use with Prometheus scraping. 0.0.4 = text/plain; version=0.0.4; charset=utf-8 1.0.0 = application/openmetrics-text; version=1.0.0; charset=utf-8 | 0.0.4 | String
|===
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public boolean isMetricsEnabled() {
}

/**
* Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics
* Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics (default)
*/
public void setMetricsEnabled(boolean metricsEnabled) {
this.metricsEnabled = metricsEnabled;
Expand Down Expand Up @@ -447,7 +447,7 @@ public HttpServerConfigurationProperties withJolokiaEnabled(boolean jolokiaEnabl
}

/**
* Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics
* Whether to enable metrics. If enabled then you can access metrics on context-path: /q/metrics (default)
*/
public HttpServerConfigurationProperties withMetricsEnabled(boolean metricsEnabled) {
this.metricsEnabled = metricsEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public class MetricsConfigurationProperties implements BootstrapCloseable {
private String textFormatVersion = "0.0.4";
@Metadata
private String binders;
@Metadata(defaultValue = "/q/metrics")
private String path = "/q/metrics";

public MetricsConfigurationProperties(MainConfigurationProperties parent) {
this.parent = parent;
Expand Down Expand Up @@ -180,6 +182,17 @@ public void setBinders(String binders) {
this.binders = binders;
}

public String getPath() {
return path;
}

/**
* The path endpoint used to expose the metrics.
*/
public void setPath(String path) {
this.path = path;
}

@Override
public void close() {
parent = null;
Expand Down

0 comments on commit ab8202f

Please sign in to comment.