@@ -4,7 +4,7 @@ use std::{
44} ;
55
66use product_config:: types:: PropertyNameKind ;
7- use snafu:: { ResultExt , Snafu } ;
7+ use snafu:: { OptionExt , ResultExt , Snafu } ;
88use stackable_operator:: {
99 builder:: meta:: ObjectMetaBuilder ,
1010 commons:: product_image_selection:: ResolvedProductImage ,
@@ -40,6 +40,12 @@ pub enum Error {
4040 BuildLabel {
4141 source : stackable_operator:: kvp:: LabelError ,
4242 } ,
43+
44+ #[ snafu( display( "missing zookeeper properties file {ZOOKEEPER_PROPERTIES_FILE} in config" ) ) ]
45+ MissingPropertiesFile ,
46+
47+ #[ snafu( display( "missing provider http port key {METRICS_PROVIDER_HTTP_PORT_KEY} in config" ) ) ]
48+ MissingProviderHttpPortKey ,
4349}
4450
4551/// The rolegroup [`Service`] is a headless service that allows internal access to the instances of a certain rolegroup
@@ -106,7 +112,7 @@ pub(crate) fn build_server_rolegroup_metrics_service(
106112 resolved_product_image : & ResolvedProductImage ,
107113 rolegroup_config : & HashMap < PropertyNameKind , BTreeMap < String , String > > ,
108114) -> Result < Service , Error > {
109- let metrics_port = metrics_port_from_rolegroup_config ( rolegroup_config) ;
115+ let metrics_port = metrics_port_from_rolegroup_config ( rolegroup_config) ? ;
110116
111117 let metadata = ObjectMetaBuilder :: new ( )
112118 . name_and_namespace ( zk)
@@ -162,23 +168,25 @@ pub(crate) fn build_server_rolegroup_metrics_service(
162168
163169pub ( crate ) fn metrics_port_from_rolegroup_config (
164170 rolegroup_config : & HashMap < PropertyNameKind , BTreeMap < String , String > > ,
165- ) -> u16 {
171+ ) -> Result < u16 , Error > {
166172 let metrics_port = rolegroup_config
167173 . get ( & PropertyNameKind :: File (
168174 ZOOKEEPER_PROPERTIES_FILE . to_string ( ) ,
169175 ) )
170- . expect ( "{ZOOKEEPER_PROPERTIES_FILE} is present" )
176+ . context ( MissingPropertiesFileSnafu ) ?
171177 . get ( METRICS_PROVIDER_HTTP_PORT_KEY )
172- . expect ( "{METRICS_PROVIDER_HTTP_PORT_KEY} is set" ) ;
178+ . context ( MissingProviderHttpPortKeySnafu ) ? ;
173179
174- match u16:: from_str ( metrics_port) {
180+ let port = match u16:: from_str ( metrics_port) {
175181 Ok ( port) => port,
176182 Err ( err) => {
177183 tracing:: error!( "{err}" ) ;
178184 tracing:: info!( "Defaulting to using {METRICS_PROVIDER_HTTP_PORT} as metrics port." ) ;
179185 METRICS_PROVIDER_HTTP_PORT
180186 }
181- }
187+ } ;
188+
189+ Ok ( port)
182190}
183191
184192/// Common labels for Prometheus
0 commit comments