diff --git a/crates/stackable-operator/src/v2/role_group_utils.rs b/crates/stackable-operator/src/v2/role_group_utils.rs index 1ce1d025d..bb4bfa552 100644 --- a/crates/stackable-operator/src/v2/role_group_utils.rs +++ b/crates/stackable-operator/src/v2/role_group_utils.rs @@ -97,6 +97,22 @@ impl ResourceNames { .expect("should be a valid Service name") } + pub fn metrics_service_name(&self) -> ServiceName { + const SUFFIX: &str = "-metrics"; + + // compile-time checks + const _: () = assert!( + QualifiedRoleGroupName::MAX_LENGTH + SUFFIX.len() <= ServiceName::MAX_LENGTH, + "The string `---metrics` must not exceed the \ + limit of Service names." + ); + let _ = QualifiedRoleGroupName::IS_RFC_1035_LABEL_NAME; + let _ = QualifiedRoleGroupName::IS_VALID_LABEL_VALUE; + + ServiceName::from_str(&format!("{}{SUFFIX}", self.qualified_role_group_name())) + .expect("should be a valid Service name") + } + pub fn listener_name(&self) -> ListenerName { // compile-time checks const _: () = assert!( @@ -145,6 +161,10 @@ mod tests { ServiceName::from_str_unsafe("test-cluster-data-nodes-ssd-storage-headless"), resource_names.headless_service_name() ); + assert_eq!( + ServiceName::from_str_unsafe("test-cluster-data-nodes-ssd-storage-metrics"), + resource_names.metrics_service_name() + ); assert_eq!( ListenerName::from_str_unsafe("test-cluster-data-nodes-ssd-storage"), resource_names.listener_name()