Skip to content

Add support for Strimzi Metrics Reporter to the Strimzi Kafka Bridge#11708

Merged
scholzj merged 10 commits intostrimzi:mainfrom
OwenCorrigan76:Strimzi_Metrics_Reporter_Bridge_Integration
Aug 5, 2025
Merged

Add support for Strimzi Metrics Reporter to the Strimzi Kafka Bridge#11708
scholzj merged 10 commits intostrimzi:mainfrom
OwenCorrigan76:Strimzi_Metrics_Reporter_Bridge_Integration

Conversation

@OwenCorrigan76
Copy link
Copy Markdown
Contributor

Type of change

  • Enhancement / new feature

Description

This patch adds support for the Strimzi Metrics Reporter to Strimzi Kafka Bridge as described by the following proposals:

https://github.com/strimzi/proposals/blob/main/064-prometheus-metrics-reporter.md
https://github.com/strimzi/proposals/blob/main/092-integrate-bridge-with-metrics-reporter.md

Related to #10753

We won’t initially support the CruiseControl component. To make it work, CC should be changed to expose metrics through its HTTP endpoint.

Documentation will be updated in a separate PR.

Checklist

  • Write tests
  • Make sure all tests pass
  • [] Update documentation
  • Try your changes from Pod inside your Kubernetes and OpenShift cluster, not just locally
  • Reference relevant issue(s) and close them after merging
  • Update CHANGELOG.md

Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
@OwenCorrigan76 OwenCorrigan76 added this to the 0.48.0 milestone Jul 31, 2025
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
"replicas", "image", "bootstrapServers", "tls", "authentication", "http", "adminClient", "consumer",
"producer", "resources", "jvmOptions", "logging", "clientRackInitImage", "rack",
"enableMetrics", "livenessProbe", "readinessProbe", "template", "tracing"})
"enableMetrics", "livenessProbe", "metricsConfig", "readinessProbe", "template", "tracing"})
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: let put this right after enableMetrics, like the get/set methods.

Comment on lines +596 to +597
? StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER
: "disabled";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add another level of alignment to these 2 rows to make it more readable?

if (model != null) {
printSectionHeader("Strimzi Metrics Reporter configuration");
writer.println("bridge.metrics=" + TYPE_STRIMZI_METRICS_REPORTER);
writer.println("kafka.metric.reporters=" + StrimziMetricsReporterConfig.KAFKA_CLASS);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
writer.println("kafka.metric.reporters=" + StrimziMetricsReporterConfig.KAFKA_CLASS);
// the kafka. prefix is required by the Bridge to pass Kafka client configurations
writer.println("kafka.metric.reporters=" + StrimziMetricsReporterConfig.KAFKA_CLASS);

public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) {
if (model != null || isMetricsEnabled) {
printSectionHeader("Prometheus Jmx Exporter configuration");
writer.println("bridge.metrics=jmxPrometheusExporter");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace jmxPrometheusExporter with JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER.

KafkaBridge resource = new KafkaBridgeBuilder(this.resource)
.build();
KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, SHARED_ENV_PROVIDER);
assertThat((JmxPrometheusExporterModel) (kbc.metrics()), is(nullValue()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the cast is needed here?

public void testWithJmxPrometheusExporterNotIsMetricsEnabled() {
JmxPrometheusExporterModel model = new JmxPrometheusExporterModel(
new KafkaBridgeSpecBuilder()
.withMetricsConfig(new JmxPrometheusExporterMetricsBuilder()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can use withNewJmxPrometheusExporterMetricsConfig.

}

@ParallelTest
public void testWithJmxPrometheusExporterIsMetricsEnabled() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As metricsEnable is deprecated, we don't need to create any new test.

}

@ParallelTest
public void testWithJmxPrometheusExporterNotIsMetricsEnabled() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is very confusing. What about testWithPrometheusJmxExporter?


assertThat(configuration, isEquivalent(
"bridge.id=my-bridge",
"bridge.metrics=jmxPrometheusExporter",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace jmxPrometheusExporter with JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER.

"bridge.id=my-bridge",
"bridge.metrics=jmxPrometheusExporter",
"kafka.bootstrap.servers=my-cluster-kafka-bootstrap:9092",
"bridge.metrics.exporter.config.path=/opt/strimzi/custom-config/metrics-config.json",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace /opt/strimzi/custom-config/metrics-config.json with KafkaBridgeCluster.KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY.

@fvaleri fvaleri force-pushed the Strimzi_Metrics_Reporter_Bridge_Integration branch from abfb9c0 to df30841 Compare July 31, 2025 15:36
@fvaleri
Copy link
Copy Markdown
Member

fvaleri commented Jul 31, 2025

Grafana dashboard screenshots:

Screenshot 2025-07-31 at 17-45-50 Strimzi Kafka Bridge - Grafana Screenshot 2025-07-31 at 17-46-08 Strimzi Kafka Bridge - Grafana

@fvaleri
Copy link
Copy Markdown
Member

fvaleri commented Jul 31, 2025

@OwenCorrigan76 you also need to update KafkaBridgeAssemblyOperatorTest#testCreateOrUpdateCreatesCluster with the new Annotations.ANNO_STRIMZI_IO_CONFIGURATION_HASH. Look at the test failure to see what's the new generated hash.

Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
@OwenCorrigan76 OwenCorrigan76 force-pushed the Strimzi_Metrics_Reporter_Bridge_Integration branch from df30841 to b94669f Compare August 1, 2025 13:42
.build();
KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, SHARED_ENV_PROVIDER);
assertThat((JmxPrometheusExporterModel) (kbc.metrics()), is(nullValue()));
assertThat((kbc.metrics()), is(nullValue()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: you should also remove the extra parentheses here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

OwenCorrigan76 and others added 2 commits August 1, 2025 15:35
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
@ppatierno ppatierno requested a review from a team August 4, 2025 10:53
? JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER
: metrics instanceof StrimziMetricsReporterModel
? StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER
: "disabled";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do really love the ternary operator in Java but ... just at one level. I think that the code is not that much readable when it comes to start inserting one inside the other.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Refactored.

writer.println("bridge.metrics=" + JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER);
// if isMetricsEnabled is not used, we pass the path of the config file. If it is used, the bridge will use the fallback config
if (!isMetricsEnabled) {
String configFilePath = KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid an additional variable here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Refactored.

fvaleri added 2 commits August 4, 2025 14:07
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
@fvaleri fvaleri force-pushed the Strimzi_Metrics_Reporter_Bridge_Integration branch from 6439a72 to 6e6dcc3 Compare August 4, 2025 12:27
Comment thread CHANGELOG.md Outdated
The `strimzi.io/node-pools` and `strimzi.io/kraft` annotations are not required anymore and will be ignored if set.
* Make properties `broker.session.timeout.ms`, `broker.heartbeat.interval.ms` and `controller.socket.timeout.ms` configurable
* Add monitoring of custom resources using [kubernetes-state-metrics (KSM)](https://github.com/kubernetes/kube-state-metrics) (see [Strimzi proposal 087](https://github.com/strimzi/proposals/blob/main/087-monitoring-of-custom-resources.md))
* Added support for Strimzi Metrics Reporter to the Kafka Bridge
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add Connect and MM2 here as wlel? Looks like that was missed in the last PR :-/.

You should also add the deprecation of .spec.enableMetrics (in KafkaBridge) to the section below.

Copy link
Copy Markdown
Member

@fvaleri fvaleri Aug 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Added.


@JsonInclude(JsonInclude.Include.NON_NULL)
@Description("Enable the metrics for the Kafka Bridge. Default is false.")
@Description("Enable the metrics for the Kafka Bridge. Default is false. Deprecated, use `spec.metricsConfig`.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you should add the @Deprecated, @DeprecatedProperty(description="...", movedToPath="...") and @PresentInVersions` annotations as well. IIRc that should also automatically generate the docs so you might want to revert the description change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thanks.

return enableMetrics;
}

@Deprecated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We in general deprecated the getters only. Not the setters.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Reverted.

} else if (spec.getMetricsConfig() instanceof StrimziMetricsReporter) {
result.metrics = new StrimziMetricsReporterModel(spec, DEFAULT_METRICS_ALLOW_LIST);
} else {
result.isMetricsEnabled = spec.getEnableMetrics();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bypass this and set it to JMX Exporter with default configuration directly from the cluster operator? Not a strong opinion, just a thought 🤔.

Update: maybe that makes no sense based on the later code. But at least we should rename isMetricsEnabled to something more descriptive to what it does. E.g. isLegacyMetricsConfigurationEnabled or something.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Renamed.

Comment on lines +592 to +608
// mapping the old deprecated enableMetrics to JMX Exporter type
String metricsType;
if ((metrics instanceof JmxPrometheusExporterModel) || isMetricsEnabled) {
metricsType = JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER;
} else {
if (metrics instanceof StrimziMetricsReporterModel) {
metricsType = StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER;
} else {
metricsType = "disabled";
}
}

if (metricsType.equals(JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER)) {
builder.withJmxPrometheusExporter((JmxPrometheusExporterModel) metrics, isMetricsEnabled);
} else if (metricsType.equals(StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER)) {
builder.withStrimziMetricsReporter((StrimziMetricsReporterModel) metrics);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why exactly do we need two separate ifs here? Seems like it could be easily merged into one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mapping part is on a separate block because it was supposed to go away after the JMX exporter deprecation period. I think this plan is still valid, but we have the complication that Cruise Control is not supported, so it may take longer. We could keep this code as it is and open a task for adding Cruise Control support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this code better than this:

Suggested change
// mapping the old deprecated enableMetrics to JMX Exporter type
String metricsType;
if ((metrics instanceof JmxPrometheusExporterModel) || isMetricsEnabled) {
metricsType = JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER;
} else {
if (metrics instanceof StrimziMetricsReporterModel) {
metricsType = StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER;
} else {
metricsType = "disabled";
}
}
if (metricsType.equals(JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER)) {
builder.withJmxPrometheusExporter((JmxPrometheusExporterModel) metrics, isMetricsEnabled);
} else if (metricsType.equals(StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER)) {
builder.withStrimziMetricsReporter((StrimziMetricsReporterModel) metrics);
}
if ((metrics instanceof JmxPrometheusExporterModel) || isLegacyMetricsConfigEnabled)) {
builder.withJmxPrometheusExporter((JmxPrometheusExporterModel) metrics, isLegacyMetricsConfigEnabled);
} else if (metrics instanceof StrimziMetricsReporterModel) {
builder.withStrimziMetricsReporter((StrimziMetricsReporterModel) metrics);
}

Doesn't that do exactly the same?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry I didn't get what you mean. Done.


/**
* @return Logging Model instance for configuring logging
* @return Logging Model instance for configuring logging
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having less various unnecessary whitespace changes would make the review much easier. It is especially wierd if you remove tabs from the Javadocs in one place and use them in new Javadocs in other place.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Reverted.

Comment on lines +383 to +395
public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) {
if (model != null || isMetricsEnabled) {
printSectionHeader("Prometheus Jmx Exporter configuration");
writer.println("bridge.metrics=" + JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER);
// if isMetricsEnabled is not used, we pass the path of the config file. If it is used, the bridge will use the fallback config
if (!isMetricsEnabled) {
writer.println("bridge.metrics.exporter.config.path="
+ KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY);
}
writer.println();
}
return this;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more spacing can improve the readabilkty a lot ... e.g. ....

Suggested change
public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) {
if (model != null || isMetricsEnabled) {
printSectionHeader("Prometheus Jmx Exporter configuration");
writer.println("bridge.metrics=" + JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER);
// if isMetricsEnabled is not used, we pass the path of the config file. If it is used, the bridge will use the fallback config
if (!isMetricsEnabled) {
writer.println("bridge.metrics.exporter.config.path="
+ KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY);
}
writer.println();
}
return this;
}
public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) {
if (model != null || isMetricsEnabled) {
printSectionHeader("Prometheus Jmx Exporter configuration");
writer.println("bridge.metrics=" + JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER);
// if isMetricsEnabled is not used, we pass the path of the config file. If it is used, the bridge will use the fallback config
if (!isMetricsEnabled) {
writer.println("bridge.metrics.exporter.config.path="
+ KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY);
}
writer.println();
}
return this;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

*/
public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) {
if (model != null || isMetricsEnabled) {
printSectionHeader("Prometheus Jmx Exporter configuration");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
printSectionHeader("Prometheus Jmx Exporter configuration");
printSectionHeader("Prometheus JMX Exporter configuration");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. I forgot to add this one, but I have it locally. Added.

@scholzj
Copy link
Copy Markdown
Member

scholzj commented Aug 4, 2025

/azp run regression

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

fvaleri added 2 commits August 5, 2025 10:37
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Copy link
Copy Markdown
Member

@im-konge im-konge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from STs side.

@im-konge im-konge requested a review from a team August 5, 2025 10:07
Copy link
Copy Markdown
Member

@ppatierno ppatierno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one last nit, LGTM. Thanks!

* Configures the JMX Prometheus Metrics Exporter.
*
* @param model JMX Prometheus Metrics Exporter configuration
* @param isLegacyMetricsConfigEnabled Flag which indicates whether the metrics are enabled or not.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should improve "indicates whether the metrics are enabled or not." to be clear they are enabled or not but with the legacy way. Because you can enable them by passing a model != null but the flag as false because you are using the new metrics way.

Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
@fvaleri
Copy link
Copy Markdown
Member

fvaleri commented Aug 5, 2025

Failed tests seems to be unrelated.

@scholzj
Copy link
Copy Markdown
Member

scholzj commented Aug 5, 2025

/azp run regression

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@OwenCorrigan76
Copy link
Copy Markdown
Contributor Author

Thanks @fvaleri for addressing the comments above.

@scholzj scholzj merged commit 45a850c into strimzi:main Aug 5, 2025
22 checks passed
@fvaleri fvaleri deleted the Strimzi_Metrics_Reporter_Bridge_Integration branch August 6, 2025 06:39
@scholzj scholzj added this to Roadmap Aug 23, 2025
@scholzj scholzj moved this to 0.48.0 (Work in Progress) in Roadmap Aug 23, 2025
see-quick pushed a commit to see-quick/strimzi-kafka-operator that referenced this pull request Sep 4, 2025
…trimzi#11708)

Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Co-authored-by: Federico Valeri <fedevaleri@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 0.48.0

Development

Successfully merging this pull request may close these issues.

5 participants