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

feat(trait): Migrate prometheus trait from microprofile metrics to micrometer #4211

Merged
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
4 changes: 3 additions & 1 deletion docs/modules/ROOT/partials/apis/camel-k-crds.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5482,12 +5482,14 @@ by using the `integration` container name.
The Prometheus trait configures a Prometheus-compatible endpoint. It also creates a `PodMonitor` resource,
so that the endpoint can be scraped automatically, when using the Prometheus operator.

The metrics are exposed using MicroProfile Metrics.
The metrics are exposed using Micrometer Metrics.

WARNING: The creation of the `PodMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus Operator]
custom resource definition to be installed.
You can set `pod-monitor` to `false` for the Prometheus trait to work without the Prometheus Operator.

WARNING: By default the metrics API is not available in JSON

The Prometheus trait is disabled by default.


Expand Down
20 changes: 19 additions & 1 deletion docs/modules/traits/pages/prometheus.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
The Prometheus trait configures a Prometheus-compatible endpoint. It also creates a `PodMonitor` resource,
so that the endpoint can be scraped automatically, when using the Prometheus operator.

The metrics are exposed using MicroProfile Metrics.
The metrics are exposed using Micrometer Metrics.

WARNING: The creation of the `PodMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus Operator]
custom resource definition to be installed.
You can set `pod-monitor` to `false` for the Prometheus trait to work without the Prometheus Operator.

WARNING: By default the metrics API is not available in JSON

The Prometheus trait is disabled by default.


Expand Down Expand Up @@ -45,3 +47,19 @@ The following configuration options are available:
|===

// End of autogenerated code - DO NOT EDIT! (configuration)
== Examples

* To activate the metrics and default scrapping through a new PodMonitor:
+
[source,console]
$ kamel run -t prometheus.enable=true ...

* To activate the metrics when the Prometheus Operator is not available:
+
[source,console]
$ kamel run -t prometheus.enable=true -t pod-monitor=false ...

* To activate the metrics with JSON format available :
+
[source,console]
$ kamel run -t prometheus.enable=true -t builder.properties="quarkus.micrometer.export.json.enabled=true"...
2 changes: 1 addition & 1 deletion e2e/common/traits/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestPrometheusTrait(t *testing.T) {
if err != nil {
assert.Fail(t, err.Error())
}
assert.Contains(t, string(response), "camel.route.exchanges.total")
assert.Contains(t, string(response), "CamelExchangesTotal_total")
})

if ocp && createPodMonitor {
Expand Down
16 changes: 8 additions & 8 deletions e2e/yaks/openshift/monitoring/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.microprofile.metrics.MicroProfileMetricsConstants;
import org.apache.camel.component.micrometer.MicrometerConstants;

import javax.enterprise.context.ApplicationScoped;

Expand Down Expand Up @@ -51,27 +51,27 @@ public void configure() {
.logStackTrace(false)
.logExhausted(false)
.log(LoggingLevel.ERROR, "Failed processing ${body}")
.to("microprofile-metrics:meter:camel-k-example-metrics-redelivery?mark=2")
.to("micrometer:counter:camel-k-example-metrics-redelivery?increment=2")
// The 'error' meter
.to("microprofile-metrics:meter:camel-k-example-metrics-error");
.to("micrometer:counter:camel-k-example-metrics-error");

from("timer:stream?period=1000")
.routeId("unreliable-service")
.setBody(header(Exchange.TIMER_COUNTER).prepend("event #"))
.log("Processing ${body}...")
// The 'generated' meter
.to("microprofile-metrics:meter:camel-k-example-metrics-generated")
.to("micrometer:counter:camel-k-example-metrics-generated")
// TODO: replace with lookup by type as soon as CAMEL-15217 gets fixed
// The 'attempt' meter via @Metered interceptor
// The 'attempt' meter via @Counted interceptor
.bean("service")
.filter(header(Exchange.REDELIVERED))
.log(LoggingLevel.WARN, "Processed ${body} after ${header.CamelRedeliveryCounter} retries")
.setHeader(MicroProfileMetricsConstants.HEADER_METER_MARK, header(Exchange.REDELIVERY_COUNTER))
.setHeader(MicrometerConstants.HEADER_COUNTER_INCREMENT, header(Exchange.REDELIVERY_COUNTER))
// The 'redelivery' meter
.to("microprofile-metrics:meter:camel-k-example-metrics-redelivery")
.to("micrometer:counter:camel-k-example-metrics-redelivery")
.end()
.log("Successfully processed ${body}")
// The 'success' meter
.to("microprofile-metrics:meter:camel-k-example-metrics-success");
.to("micrometer:counter:camel-k-example-metrics-success");
}
}
6 changes: 5 additions & 1 deletion e2e/yaks/openshift/monitoring/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-microprofile-metrics</artifactId>
<artifactId>camel-quarkus-micrometer</artifactId>
<version>${version.camel.quarkus}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@

import java.util.Random;

import io.micrometer.core.annotation.Counted;

import org.apache.camel.Exchange;
import org.apache.camel.RuntimeExchangeException;

import org.eclipse.microprofile.metrics.Gauge;
import org.eclipse.microprofile.metrics.Meter;

import org.eclipse.microprofile.metrics.annotation.Metered;
import org.eclipse.microprofile.metrics.annotation.Metric;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

Expand All @@ -39,7 +35,7 @@
@io.quarkus.arc.Unremovable
public class Service {

@Metered(name = "camel-k-example-metrics-attempt", absolute = true)
@Counted(value = "camel-k-example-metrics-attempt")
public void attempt(Exchange exchange) {
Random rand = new Random();
if (rand.nextDouble() < 0.5) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/camel/v1/trait/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ package trait
// The Prometheus trait configures a Prometheus-compatible endpoint. It also creates a `PodMonitor` resource,
// so that the endpoint can be scraped automatically, when using the Prometheus operator.
//
// The metrics are exposed using MicroProfile Metrics.
// The metrics are exposed using Micrometer Metrics.
//
// WARNING: The creation of the `PodMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus Operator]
// custom resource definition to be installed.
// You can set `pod-monitor` to `false` for the Prometheus trait to work without the Prometheus Operator.
//
// WARNING: By default the metrics API is not available in JSON
//
// The Prometheus trait is disabled by default.
//
// +camel-k:trait=prometheus.
Expand Down
5 changes: 3 additions & 2 deletions pkg/trait/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func (t *prometheusTrait) Configure(e *Environment) (bool, error) {

func (t *prometheusTrait) Apply(e *Environment) error {
if e.IntegrationInPhase(v1.IntegrationPhaseInitialization) {
// Add the Camel Quarkus MP Metrics extension
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, "mvn:org.apache.camel.quarkus:camel-quarkus-microprofile-metrics")
// Add the Camel Quarkus Micrometer extension and micrometer registry for prometheus
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, "mvn:org.apache.camel.quarkus:camel-quarkus-micrometer")
util.StringSliceUniqueAdd(&e.Integration.Status.Dependencies, "mvn:io.micrometer:micrometer-registry-prometheus")
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions resources/traits.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,12 @@ traits:
- OpenShift
description: 'The Prometheus trait configures a Prometheus-compatible endpoint.
It also creates a `PodMonitor` resource, so that the endpoint can be scraped automatically,
when using the Prometheus operator. The metrics are exposed using MicroProfile
Metrics. WARNING: The creation of the `PodMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus
when using the Prometheus operator. The metrics are exposed using Micrometer Metrics.
WARNING: The creation of the `PodMonitor` resource requires the https://github.com/coreos/prometheus-operator[Prometheus
Operator] custom resource definition to be installed. You can set `pod-monitor`
to `false` for the Prometheus trait to work without the Prometheus Operator. The
Prometheus trait is disabled by default.'
to `false` for the Prometheus trait to work without the Prometheus Operator. WARNING:
By default the metrics API is not available in JSON The Prometheus trait is disabled
by default.'
properties:
- name: enabled
type: bool
Expand Down