3535import io .strimzi .api .kafka .model .common .JvmOptions ;
3636import io .strimzi .api .kafka .model .common .Rack ;
3737import io .strimzi .api .kafka .model .common .authentication .KafkaClientAuthentication ;
38+ import io .strimzi .api .kafka .model .common .metrics .JmxPrometheusExporterMetrics ;
39+ import io .strimzi .api .kafka .model .common .metrics .StrimziMetricsReporter ;
3840import io .strimzi .api .kafka .model .common .template .ContainerTemplate ;
3941import io .strimzi .api .kafka .model .common .template .DeploymentStrategy ;
4042import io .strimzi .api .kafka .model .common .template .DeploymentTemplate ;
4648import io .strimzi .operator .cluster .ClusterOperatorConfig ;
4749import io .strimzi .operator .cluster .model .logging .LoggingModel ;
4850import io .strimzi .operator .cluster .model .logging .SupportsLogging ;
51+ import io .strimzi .operator .cluster .model .metrics .JmxPrometheusExporterModel ;
52+ import io .strimzi .operator .cluster .model .metrics .MetricsModel ;
53+ import io .strimzi .operator .cluster .model .metrics .StrimziMetricsReporterModel ;
54+ import io .strimzi .operator .cluster .model .metrics .SupportsMetrics ;
4955import io .strimzi .operator .cluster .model .securityprofiles .ContainerSecurityProviderContextImpl ;
5056import io .strimzi .operator .cluster .model .securityprofiles .PodSecurityProviderContextImpl ;
5157import io .strimzi .operator .common .Reconciliation ;
6571 * Kafka Bridge model class
6672 */
6773@ SuppressWarnings ({"checkstyle:ClassFanOutComplexity" })
68- public class KafkaBridgeCluster extends AbstractModel implements SupportsLogging {
74+ public class KafkaBridgeCluster extends AbstractModel implements SupportsLogging , SupportsMetrics {
75+ /**
76+ * Default Strimzi Metrics Reporter allow list.
77+ * Check example dashboards compatibility in case of changes to existing regexes.
78+ */
79+ private static final List <String > DEFAULT_METRICS_ALLOW_LIST = List .of (
80+ "kafka_consumer_consumer_metrics.*" ,
81+ "kafka_producer_kafka_metrics_count_count" ,
82+ "kafka_producer_producer_metrics.*"
83+ );
84+
6985 /**
7086 * HTTP port configuration
7187 */
@@ -77,19 +93,17 @@ public class KafkaBridgeCluster extends AbstractModel implements SupportsLogging
7793 protected static final String PASSWORD_VOLUME_MOUNT = "/opt/strimzi/bridge-password/" ;
7894 protected static final String ENV_VAR_KAFKA_INIT_INIT_FOLDER_KEY = "INIT_FOLDER" ;
7995 private static final String KAFKA_BRIDGE_CONFIG_VOLUME_NAME = "kafka-bridge-configurations" ;
80- private static final String KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT = "/opt/strimzi/custom-config/" ;
8196
8297 // Cluster Operator environment variables for custom discovery labels and annotations
8398 protected static final String CO_ENV_VAR_CUSTOM_SERVICE_LABELS = "STRIMZI_CUSTOM_KAFKA_BRIDGE_SERVICE_LABELS" ;
8499 protected static final String CO_ENV_VAR_CUSTOM_SERVICE_ANNOTATIONS = "STRIMZI_CUSTOM_KAFKA_BRIDGE_SERVICE_ANNOTATIONS" ;
85100
86101 // Kafka Bridge configuration keys (EnvVariables)
87102 protected static final String ENV_VAR_PREFIX = "KAFKA_BRIDGE_" ;
88- protected static final String ENV_VAR_KAFKA_BRIDGE_METRICS_ENABLED = "KAFKA_BRIDGE_METRICS_ENABLED" ;
89103 protected static final String ENV_VAR_KAFKA_BRIDGE_TRUSTED_CERTS = "KAFKA_BRIDGE_TRUSTED_CERTS" ;
90104 protected static final String OAUTH_TLS_CERTS_BASE_VOLUME_MOUNT = "/opt/strimzi/oauth-certs/" ;
91105 protected static final String OAUTH_SECRETS_BASE_VOLUME_MOUNT = "/opt/strimzi/oauth/" ;
92-
106+ protected static final String KAFKA_BRIDGE_CONFIG_VOLUME_MOUNT = "/opt/strimzi/custom-config/" ;
93107 protected static final String CO_ENV_VAR_CUSTOM_BRIDGE_POD_LABELS = "STRIMZI_CUSTOM_KAFKA_BRIDGE_LABELS" ;
94108 protected static final String INIT_VOLUME_MOUNT = "/opt/strimzi/init" ;
95109
@@ -106,8 +120,9 @@ public class KafkaBridgeCluster extends AbstractModel implements SupportsLogging
106120 private KafkaBridgeAdminClientSpec kafkaBridgeAdminClient ;
107121 private KafkaBridgeConsumerSpec kafkaBridgeConsumer ;
108122 private KafkaBridgeProducerSpec kafkaBridgeProducer ;
109- private boolean isMetricsEnabled = false ;
123+ private boolean isLegacyMetricsConfigEnabled = false ;
110124 private LoggingModel logging ;
125+ private MetricsModel metrics ;
111126
112127 // Templates
113128 private PodDisruptionBudgetTemplate templatePodDisruptionBudget ;
@@ -151,7 +166,7 @@ private KafkaBridgeCluster(Reconciliation reconciliation, HasMetadata resource,
151166 * @param sharedEnvironmentProvider Shared environment provider
152167 * @return KafkaBridgeCluster instance
153168 */
154- @ SuppressWarnings ({"checkstyle:NPathComplexity" })
169+ @ SuppressWarnings ({"checkstyle:NPathComplexity" , "deprecation" })
155170 public static KafkaBridgeCluster fromCrd (Reconciliation reconciliation ,
156171 KafkaBridge kafkaBridge ,
157172 SharedEnvironmentProvider sharedEnvironmentProvider ) {
@@ -182,7 +197,14 @@ public static KafkaBridgeCluster fromCrd(Reconciliation reconciliation,
182197
183198 result .readinessProbeOptions = ProbeUtils .extractReadinessProbeOptionsOrDefault (spec , ProbeUtils .DEFAULT_HEALTHCHECK_OPTIONS );
184199 result .livenessProbeOptions = ProbeUtils .extractLivenessProbeOptionsOrDefault (spec , ProbeUtils .DEFAULT_HEALTHCHECK_OPTIONS );
185- result .isMetricsEnabled = spec .getEnableMetrics ();
200+
201+ if (spec .getMetricsConfig () instanceof JmxPrometheusExporterMetrics ) {
202+ result .metrics = new JmxPrometheusExporterModel (spec );
203+ } else if (spec .getMetricsConfig () instanceof StrimziMetricsReporter ) {
204+ result .metrics = new StrimziMetricsReporterModel (spec , DEFAULT_METRICS_ALLOW_LIST );
205+ } else {
206+ result .isLegacyMetricsConfigEnabled = spec .getEnableMetrics ();
207+ }
186208
187209 result .setTls (spec .getTls () != null ? spec .getTls () : null );
188210
@@ -312,7 +334,7 @@ protected List<VolumeMount> getVolumeMounts() {
312334
313335 return volumeMountList ;
314336 }
315-
337+
316338 private List <VolumeMount > getInitContainerVolumeMounts () {
317339 List <VolumeMount > volumeMountList = new ArrayList <>();
318340 volumeMountList .add (VolumeUtils .createVolumeMount (INIT_VOLUME_NAME , INIT_VOLUME_MOUNT ));
@@ -396,7 +418,6 @@ private Container createContainer(ImagePullPolicy imagePullPolicy) {
396418
397419 protected List <EnvVar > getEnvVars () {
398420 List <EnvVar > varList = new ArrayList <>();
399- varList .add (ContainerUtils .createEnvVar (ENV_VAR_KAFKA_BRIDGE_METRICS_ENABLED , String .valueOf (isMetricsEnabled )));
400421 varList .add (ContainerUtils .createEnvVar (ENV_VAR_STRIMZI_GC_LOG_ENABLED , String .valueOf (gcLoggingEnabled )));
401422 JvmOptionUtils .javaOptions (varList , jvmOptions );
402423
@@ -555,18 +576,23 @@ public ConfigMap generateBridgeConfigMap(MetricsAndLogging metricsAndLogging) {
555576 // generate the ConfigMap data entries for the metrics and logging configuration
556577 Map <String , String > data = ConfigMapUtils .generateMetricsAndLogConfigMapData (reconciliation , this , metricsAndLogging );
557578 // add the ConfigMap data entry for the bridge HTTP and Kafka clients related configuration
558- data .put (
559- BRIDGE_CONFIGURATION_FILENAME ,
579+ KafkaBridgeConfigurationBuilder builder =
560580 new KafkaBridgeConfigurationBuilder (reconciliation , cluster , bootstrapServers )
561581 .withTracing (tracing )
562582 .withTls (tls )
563583 .withAuthentication (authentication )
564584 .withKafkaAdminClient (kafkaBridgeAdminClient )
565585 .withKafkaProducer (kafkaBridgeProducer )
566586 .withKafkaConsumer (kafkaBridgeConsumer )
567- .withHttp (http , kafkaBridgeProducer , kafkaBridgeConsumer )
568- .build ()
569- );
587+ .withHttp (http , kafkaBridgeProducer , kafkaBridgeConsumer );
588+
589+ if ((metrics instanceof JmxPrometheusExporterModel ) || isLegacyMetricsConfigEnabled ) {
590+ builder .withJmxPrometheusExporter ((JmxPrometheusExporterModel ) metrics , isLegacyMetricsConfigEnabled );
591+ } else if (metrics instanceof StrimziMetricsReporterModel ) {
592+ builder .withStrimziMetricsReporter ((StrimziMetricsReporterModel ) metrics );
593+ }
594+
595+ data .put (BRIDGE_CONFIGURATION_FILENAME , builder .build ());
570596
571597 return ConfigMapUtils
572598 .createConfigMap (
@@ -591,4 +617,11 @@ public int getReplicas() {
591617 public LoggingModel logging () {
592618 return logging ;
593619 }
620+
621+ /**
622+ * @return Metrics Model instance for configuring Prometheus metrics
623+ */
624+ public MetricsModel metrics () {
625+ return metrics ;
626+ }
594627}
0 commit comments