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 11, 2024
1 parent b10284d commit ff43f29
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,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 @@ -275,7 +275,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
2 changes: 1 addition & 1 deletion 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
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

0 comments on commit ff43f29

Please sign in to comment.