Skip to content

Commit c0d6569

Browse files
committed
chore: tidy up metrics ports and use consts
1 parent 5fe88d4 commit c0d6569

File tree

5 files changed

+35
-30
lines changed

5 files changed

+35
-30
lines changed

rust/operator-binary/src/config/jvm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use stackable_operator::{
55
};
66

77
use crate::crd::{
8-
JVM_SECURITY_PROPERTIES_FILE, LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE, LoggingFramework,
9-
METRICS_PORT, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR,
8+
JMX_METRICS_PORT, JVM_SECURITY_PROPERTIES_FILE, LOG4J_CONFIG_FILE, LOGBACK_CONFIG_FILE,
9+
LoggingFramework, STACKABLE_CONFIG_DIR, STACKABLE_LOG_CONFIG_DIR,
1010
v1alpha1::{
1111
ZookeeperCluster, ZookeeperConfig, ZookeeperConfigFragment, ZookeeperServerRoleConfig,
1212
},
@@ -39,7 +39,7 @@ fn construct_jvm_args(
3939
let jvm_args = vec![
4040
format!("-Djava.security.properties={STACKABLE_CONFIG_DIR}/{JVM_SECURITY_PROPERTIES_FILE}"),
4141
format!(
42-
"-javaagent:/stackable/jmx/jmx_prometheus_javaagent.jar={METRICS_PORT}:/stackable/jmx/server.yaml"
42+
"-javaagent:/stackable/jmx/jmx_prometheus_javaagent.jar={JMX_METRICS_PORT}:/stackable/jmx/server.yaml"
4343
),
4444
match logging_framework {
4545
LoggingFramework::LOG4J => {

rust/operator-binary/src/crd/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ pub const OPERATOR_NAME: &str = "zookeeper.stackable.tech";
5151
pub const ZOOKEEPER_PROPERTIES_FILE: &str = "zoo.cfg";
5252
pub const JVM_SECURITY_PROPERTIES_FILE: &str = "security.properties";
5353

54+
pub const ZOOKEEPER_SERVER_PORT_NAME: &str = "zk";
55+
pub const ZOOKEEPER_LEADER_PORT_NAME: &str = "zk-leader";
5456
pub const ZOOKEEPER_LEADER_PORT: u16 = 2888;
57+
pub const ZOOKEEPER_ELECTION_PORT_NAME: &str = "zk-election";
5558
pub const ZOOKEEPER_ELECTION_PORT: u16 = 3888;
5659

57-
pub const METRICS_PORT_NAME: &str = "metrics";
58-
pub const METRICS_PORT: u16 = 9505;
60+
pub const JMX_METRICS_PORT_NAME: &str = "metrics";
61+
pub const JMX_METRICS_PORT: u16 = 9505;
5962
pub const METRICS_PROVIDER_HTTP_PORT_KEY: &str = "metricsProvider.httpPort";
63+
pub const METRICS_PROVIDER_HTTP_PORT_NAME: &str = "native-metrics";
6064
pub const METRICS_PROVIDER_HTTP_PORT: u16 = 7000;
6165

6266
pub const STACKABLE_DATA_DIR: &str = "/stackable/data";

rust/operator-binary/src/discovery.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use stackable_operator::{
1010
};
1111

1212
use crate::{
13-
crd::{ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
13+
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
1414
utils::build_recommended_labels,
1515
};
1616

@@ -75,7 +75,7 @@ pub fn build_discovery_configmap(
7575
let name = owner.name_unchecked();
7676
let namespace = owner.namespace().context(NoNamespaceSnafu)?;
7777

78-
let listener_addresses = listener_addresses(&listener, "zk")?;
78+
let listener_addresses = listener_addresses(&listener, ZOOKEEPER_SERVER_PORT_NAME)?;
7979

8080
// Write a connection string of the format that Java ZooKeeper client expects:
8181
// "{host1}:{port1},{host2:port2},.../{chroot}"

rust/operator-binary/src/listener.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use stackable_operator::{
77
};
88

99
use crate::{
10-
crd::{ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
10+
crd::{ZOOKEEPER_SERVER_PORT_NAME, ZookeeperRole, security::ZookeeperSecurity, v1alpha1},
1111
utils::build_recommended_labels,
1212
zk_controller::ZK_CONTROLLER_NAME,
1313
};
@@ -85,11 +85,10 @@ pub fn role_listener_name(zk: &v1alpha1::ZookeeperCluster, zk_role: &ZookeeperRo
8585
format!("{zk}-{zk_role}", zk = zk.name_any())
8686
}
8787

88-
// We only use the http port here and intentionally omit
89-
// the metrics one.
88+
// We only use the server port here and intentionally omit the metrics one.
9089
fn listener_ports(zookeeper_security: &ZookeeperSecurity) -> Vec<listener::v1alpha1::ListenerPort> {
9190
vec![listener::v1alpha1::ListenerPort {
92-
name: "zk".to_string(),
91+
name: ZOOKEEPER_SERVER_PORT_NAME.to_string(),
9392
port: zookeeper_security.client_port().into(),
9493
protocol: Some("TCP".to_string()),
9594
}]

rust/operator-binary/src/zk_controller.rs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,14 @@ use crate::{
7676
command::create_init_container_command_args,
7777
config::jvm::{construct_non_heap_jvm_args, construct_zk_server_heap_env},
7878
crd::{
79-
DOCKER_IMAGE_BASE_NAME, JVM_SECURITY_PROPERTIES_FILE, MAX_PREPARE_LOG_FILE_SIZE,
80-
MAX_ZK_LOG_FILES_SIZE, METRICS_PORT, METRICS_PORT_NAME, METRICS_PROVIDER_HTTP_PORT,
81-
METRICS_PROVIDER_HTTP_PORT_KEY, STACKABLE_CONFIG_DIR, STACKABLE_DATA_DIR,
79+
DOCKER_IMAGE_BASE_NAME, JMX_METRICS_PORT, JMX_METRICS_PORT_NAME,
80+
JVM_SECURITY_PROPERTIES_FILE, MAX_PREPARE_LOG_FILE_SIZE, MAX_ZK_LOG_FILES_SIZE,
81+
METRICS_PROVIDER_HTTP_PORT, METRICS_PROVIDER_HTTP_PORT_KEY,
82+
METRICS_PROVIDER_HTTP_PORT_NAME, STACKABLE_CONFIG_DIR, STACKABLE_DATA_DIR,
8283
STACKABLE_LOG_CONFIG_DIR, STACKABLE_LOG_DIR, STACKABLE_RW_CONFIG_DIR,
83-
ZOOKEEPER_ELECTION_PORT, ZOOKEEPER_LEADER_PORT, ZOOKEEPER_PROPERTIES_FILE, ZookeeperRole,
84+
ZOOKEEPER_ELECTION_PORT, ZOOKEEPER_ELECTION_PORT_NAME, ZOOKEEPER_LEADER_PORT,
85+
ZOOKEEPER_LEADER_PORT_NAME, ZOOKEEPER_PROPERTIES_FILE, ZOOKEEPER_SERVER_PORT_NAME,
86+
ZookeeperRole,
8487
security::{self, ZookeeperSecurity},
8588
v1alpha1::{self, ZookeeperServerRoleConfig},
8689
},
@@ -693,15 +696,13 @@ fn build_server_rolegroup_headless_service(
693696
cluster_ip: Some("None".to_string()),
694697
ports: Some(vec![
695698
ServicePort {
696-
// TODO (@NickLarsenNZ): Use a const
697-
name: Some("zk-leader".to_string()),
699+
name: Some(ZOOKEEPER_LEADER_PORT_NAME.to_string()),
698700
port: ZOOKEEPER_LEADER_PORT as i32,
699701
protocol: Some("TCP".to_string()),
700702
..ServicePort::default()
701703
},
702704
ServicePort {
703-
// TODO (@NickLarsenNZ): Use a const
704-
name: Some("zk-election".to_string()),
705+
name: Some(ZOOKEEPER_ELECTION_PORT_NAME.to_string()),
705706
port: ZOOKEEPER_ELECTION_PORT as i32,
706707
protocol: Some("TCP".to_string()),
707708
..ServicePort::default()
@@ -757,15 +758,14 @@ fn build_server_rolegroup_metrics_service(
757758
cluster_ip: Some("None".to_string()),
758759
ports: Some(vec![
759760
ServicePort {
760-
name: Some(METRICS_PORT_NAME.to_string()),
761-
port: METRICS_PORT.into(),
761+
name: Some(JMX_METRICS_PORT_NAME.to_string()),
762+
port: JMX_METRICS_PORT as i32,
762763
protocol: Some("TCP".to_string()),
763764
..ServicePort::default()
764765
},
765766
ServicePort {
766-
// TODO (@NickLarsenNZ): Use a const: METRICS_PROVIDER_HTTP_PORT_NAME
767-
name: Some("native-metrics".to_string()),
768-
port: metrics_port_from_rolegroup_config(rolegroup_config).into(),
767+
name: Some(METRICS_PROVIDER_HTTP_PORT_NAME.to_string()),
768+
port: metrics_port_from_rolegroup_config(rolegroup_config) as i32,
769769
protocol: Some("TCP".to_string()),
770770
..ServicePort::default()
771771
},
@@ -983,13 +983,15 @@ fn build_server_rolegroup_statefulset(
983983
period_seconds: Some(1),
984984
..Probe::default()
985985
})
986-
// TODO (@NickLarsenNZ): Use consts for the port names (since they are used in multiple places)
987-
.add_container_port("zk", zookeeper_security.client_port().into())
988-
.add_container_port("zk-leader", ZOOKEEPER_LEADER_PORT as i32)
989-
.add_container_port("zk-election", ZOOKEEPER_ELECTION_PORT as i32)
990-
.add_container_port("metrics", 9505)
991986
.add_container_port(
992-
"native-metrics",
987+
ZOOKEEPER_SERVER_PORT_NAME,
988+
zookeeper_security.client_port() as i32,
989+
)
990+
.add_container_port(ZOOKEEPER_LEADER_PORT_NAME, ZOOKEEPER_LEADER_PORT as i32)
991+
.add_container_port(ZOOKEEPER_ELECTION_PORT_NAME, ZOOKEEPER_ELECTION_PORT as i32)
992+
.add_container_port(JMX_METRICS_PORT_NAME, 9505)
993+
.add_container_port(
994+
METRICS_PROVIDER_HTTP_PORT_NAME,
993995
metrics_port_from_rolegroup_config(server_config).into(),
994996
)
995997
.add_volume_mount("data", STACKABLE_DATA_DIR)

0 commit comments

Comments
 (0)