@@ -69,6 +69,7 @@ pub fn build_rolegroup_metrics_service(
6969 role_group_ref : & RoleGroupRef < v1alpha1:: NifiCluster > ,
7070 object_labels : ObjectLabels < v1alpha1:: NifiCluster > ,
7171 selector : BTreeMap < String , String > ,
72+ ports : Vec < ServicePort > ,
7273) -> Result < Service , Error > {
7374 Ok ( Service {
7475 metadata : ObjectMetaBuilder :: new ( )
@@ -86,7 +87,7 @@ pub fn build_rolegroup_metrics_service(
8687 // Internal communication does not need to be exposed
8788 type_ : Some ( "ClusterIP" . to_string ( ) ) ,
8889 cluster_ip : Some ( "None" . to_string ( ) ) ,
89- ports : Some ( metrics_service_ports ( ) ) ,
90+ ports : Some ( ports ) ,
9091 selector : Some ( selector) ,
9192 publish_not_ready_addresses : Some ( true ) ,
9293 ..ServiceSpec :: default ( )
@@ -104,13 +105,25 @@ fn headless_service_ports() -> Vec<ServicePort> {
104105 } ]
105106}
106107
107- fn metrics_service_ports ( ) -> Vec < ServicePort > {
108- vec ! [ ServicePort {
109- name: Some ( METRICS_PORT_NAME . to_string( ) ) ,
110- port: METRICS_PORT . into( ) ,
111- protocol: Some ( "TCP" . to_string( ) ) ,
112- ..ServicePort :: default ( )
113- } ]
108+ /// Returns the metrics port based on the NiFi version
109+ /// V1: Uses extra port via JMX exporter
110+ /// V2: Uses NiFi HTTP(S) port for metrics
111+ pub fn metrics_service_port ( product_version : & str ) -> ServicePort {
112+ if product_version. starts_with ( "1." ) {
113+ ServicePort {
114+ name : Some ( METRICS_PORT_NAME . to_string ( ) ) ,
115+ port : METRICS_PORT . into ( ) ,
116+ protocol : Some ( "TCP" . to_string ( ) ) ,
117+ ..ServicePort :: default ( )
118+ }
119+ } else {
120+ ServicePort {
121+ name : Some ( HTTPS_PORT_NAME . into ( ) ) ,
122+ port : HTTPS_PORT . into ( ) ,
123+ protocol : Some ( "TCP" . to_string ( ) ) ,
124+ ..ServicePort :: default ( )
125+ }
126+ }
114127}
115128
116129/// Returns the metrics rolegroup service name `<cluster>-<role>-<rolegroup>-<METRICS_SERVICE_SUFFIX>`.
0 commit comments