Add support for Strimzi Metrics Reporter to the Strimzi Kafka Bridge#11708
Conversation
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
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"}) |
There was a problem hiding this comment.
Nit: let put this right after enableMetrics, like the get/set methods.
| ? StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER | ||
| : "disabled"; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
| 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"); |
There was a problem hiding this comment.
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())); |
| public void testWithJmxPrometheusExporterNotIsMetricsEnabled() { | ||
| JmxPrometheusExporterModel model = new JmxPrometheusExporterModel( | ||
| new KafkaBridgeSpecBuilder() | ||
| .withMetricsConfig(new JmxPrometheusExporterMetricsBuilder() |
There was a problem hiding this comment.
Here you can use withNewJmxPrometheusExporterMetricsConfig.
| } | ||
|
|
||
| @ParallelTest | ||
| public void testWithJmxPrometheusExporterIsMetricsEnabled() { |
There was a problem hiding this comment.
As metricsEnable is deprecated, we don't need to create any new test.
| } | ||
|
|
||
| @ParallelTest | ||
| public void testWithJmxPrometheusExporterNotIsMetricsEnabled() { |
There was a problem hiding this comment.
The name is very confusing. What about testWithPrometheusJmxExporter?
|
|
||
| assertThat(configuration, isEquivalent( | ||
| "bridge.id=my-bridge", | ||
| "bridge.metrics=jmxPrometheusExporter", |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
replace /opt/strimzi/custom-config/metrics-config.json with KafkaBridgeCluster.KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT + JmxPrometheusExporterModel.CONFIG_MAP_KEY.
abfb9c0 to
df30841
Compare
|
@OwenCorrigan76 you also need to update |
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
df30841 to
b94669f
Compare
| .build(); | ||
| KafkaBridgeCluster kbc = KafkaBridgeCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, resource, SHARED_ENV_PROVIDER); | ||
| assertThat((JmxPrometheusExporterModel) (kbc.metrics()), is(nullValue())); | ||
| assertThat((kbc.metrics()), is(nullValue())); |
There was a problem hiding this comment.
Nit: you should also remove the extra parentheses here.
Signed-off-by: OwenCorrigan76 <owencorrigan76@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
| ? JmxPrometheusExporterMetrics.TYPE_JMX_EXPORTER | ||
| : metrics instanceof StrimziMetricsReporterModel | ||
| ? StrimziMetricsReporter.TYPE_STRIMZI_METRICS_REPORTER | ||
| : "disabled"; |
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
avoid an additional variable here.
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
6439a72 to
6e6dcc3
Compare
| 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 |
There was a problem hiding this comment.
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.
|
|
||
| @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`.") |
There was a problem hiding this comment.
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.
| return enableMetrics; | ||
| } | ||
|
|
||
| @Deprecated |
There was a problem hiding this comment.
We in general deprecated the getters only. Not the setters.
| } else if (spec.getMetricsConfig() instanceof StrimziMetricsReporter) { | ||
| result.metrics = new StrimziMetricsReporterModel(spec, DEFAULT_METRICS_ALLOW_LIST); | ||
| } else { | ||
| result.isMetricsEnabled = spec.getEnableMetrics(); |
There was a problem hiding this comment.
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.
| // 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); | ||
| } |
There was a problem hiding this comment.
Why exactly do we need two separate ifs here? Seems like it could be easily merged into one.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Why is this code better than this:
| // 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?
There was a problem hiding this comment.
Yep, sorry I didn't get what you mean. Done.
|
|
||
| /** | ||
| * @return Logging Model instance for configuring logging | ||
| * @return Logging Model instance for configuring logging |
There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
Some more spacing can improve the readabilkty a lot ... e.g. ....
| 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; | |
| } |
| */ | ||
| public KafkaBridgeConfigurationBuilder withJmxPrometheusExporter(JmxPrometheusExporterModel model, boolean isMetricsEnabled) { | ||
| if (model != null || isMetricsEnabled) { | ||
| printSectionHeader("Prometheus Jmx Exporter configuration"); |
There was a problem hiding this comment.
| printSectionHeader("Prometheus Jmx Exporter configuration"); | |
| printSectionHeader("Prometheus JMX Exporter configuration"); |
There was a problem hiding this comment.
Please update also https://github.com/strimzi/strimzi-kafka-operator/blob/main/packaging/examples/metrics/kafka-bridge-metrics.yaml as you are deprecating the enableMetrics field.
There was a problem hiding this comment.
Yep. I forgot to add this one, but I have it locally. Added.
|
/azp run regression |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
Signed-off-by: Federico Valeri <fedevaleri@gmail.com>
ppatierno
left a comment
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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>
|
Failed tests seems to be unrelated. |
|
/azp run regression |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Thanks @fvaleri for addressing the comments above. |
…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>


Type of change
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