Skip to content

Commit d737c4e

Browse files
authored
Add metrics service for nifi v2 (#819)
* add metrics service for nifi v2 * adapted changelog * add changelog entry to listener entry * adapt to review
1 parent 010c7b5 commit d737c4e

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ All notable changes to this project will be documented in this file.
77
### Added
88

99
- Add rolling upgrade support for upgrades between NiFi 2 versions ([#771]).
10-
- Added Listener support for NiFi ([#784]).
10+
- BREAKING: Added Listener support for NiFi ([#784], [#819]).
1111
- Adds new telemetry CLI arguments and environment variables ([#782]).
1212
- Use `--file-log-max-files` (or `FILE_LOG_MAX_FILES`) to limit the number of log files kept.
1313
- Use `--file-log-rotation-period` (or `FILE_LOG_ROTATION_PERIOD`) to configure the frequency of rotation.
@@ -69,6 +69,7 @@ All notable changes to this project will be documented in this file.
6969
[#801]: https://github.com/stackabletech/nifi-operator/pull/801
7070
[#808]: https://github.com/stackabletech/nifi-operator/pull/808
7171
[#817]: https://github.com/stackabletech/nifi-operator/pull/817
72+
[#819]: https://github.com/stackabletech/nifi-operator/pull/819
7273

7374
## [25.3.0] - 2025-03-21
7475

rust/operator-binary/src/controller.rs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use crate::{
108108
tls::{KEYSTORE_NIFI_CONTAINER_MOUNT, KEYSTORE_VOLUME_NAME, TRUSTSTORE_VOLUME_NAME},
109109
},
110110
service::{
111-
build_rolegroup_headless_service, build_rolegroup_metrics_service,
111+
build_rolegroup_headless_service, build_rolegroup_metrics_service, metrics_service_port,
112112
rolegroup_headless_service_name,
113113
},
114114
};
@@ -562,22 +562,23 @@ pub async fn reconcile_nifi(
562562
)
563563
.await?;
564564

565-
if resolved_product_image.product_version.starts_with("1.") {
566-
let rg_metrics_service = build_rolegroup_metrics_service(
567-
nifi,
568-
&rolegroup,
569-
role_group_service_recommended_labels,
570-
role_group_service_selector.into(),
571-
)
572-
.context(ServiceConfigurationSnafu)?;
565+
let rg_metrics_service = build_rolegroup_metrics_service(
566+
nifi,
567+
&rolegroup,
568+
role_group_service_recommended_labels,
569+
role_group_service_selector.into(),
570+
vec![metrics_service_port(
571+
&resolved_product_image.product_version,
572+
)],
573+
)
574+
.context(ServiceConfigurationSnafu)?;
573575

574-
cluster_resources
575-
.add(client, rg_metrics_service)
576-
.await
577-
.with_context(|_| ApplyRoleGroupServiceSnafu {
578-
rolegroup: rolegroup.clone(),
579-
})?;
580-
}
576+
cluster_resources
577+
.add(client, rg_metrics_service)
578+
.await
579+
.with_context(|_| ApplyRoleGroupServiceSnafu {
580+
rolegroup: rolegroup.clone(),
581+
})?;
581582

582583
cluster_resources
583584
.add(client, rg_headless_service)

rust/operator-binary/src/service.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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>`.

tests/templates/kuttl/external-access/30-assert.yaml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ status:
1515
readyReplicas: 2
1616
replicas: 2
1717
---
18-
---
1918
apiVersion: policy/v1
2019
kind: PodDisruptionBudget
2120
metadata:
@@ -25,11 +24,23 @@ status:
2524
currentHealthy: 2
2625
disruptionsAllowed: 1
2726
---
28-
---
2927
apiVersion: v1
3028
kind: Service
3129
metadata:
3230
name: test-nifi-node
3331
spec:
3432
type: NodePort # external-unstable
3533
---
34+
apiVersion: v1
35+
kind: Service
36+
metadata:
37+
name: test-nifi-node-default-headless
38+
spec:
39+
type: ClusterIP
40+
---
41+
apiVersion: v1
42+
kind: Service
43+
metadata:
44+
name: test-nifi-node-default-metrics
45+
spec:
46+
type: ClusterIP

0 commit comments

Comments
 (0)