@@ -48,6 +48,7 @@ use stackable_operator::{
4848 container:: { EnvVarName , EnvVarSet , new_container_builder} ,
4949 volume:: { ListenerReference , listener_operator_volume_source_builder_build_pvc} ,
5050 } ,
51+ service:: { Scheme , Scraping , prometheus_annotations, prometheus_labels} ,
5152 statefulset:: {
5253 restarter_ignore_configmap_annotations, restarter_ignore_secret_annotations,
5354 } ,
@@ -1300,9 +1301,16 @@ impl<'a> RoleGroupBuilder<'a> {
13001301 pub fn build_headless_service ( & self ) -> Service {
13011302 let metadata = self
13021303 . common_metadata ( self . resource_names . headless_service_name ( ) )
1303- . with_labels ( Self :: prometheus_labels ( ) )
1304- . with_annotations ( Self :: prometheus_annotations (
1305- self . security_mode . tls_server_secret_class ( ) . is_some ( ) ,
1304+ . with_labels ( prometheus_labels ( & Scraping :: Enabled ) )
1305+ . with_annotations ( prometheus_annotations (
1306+ & Scraping :: Enabled ,
1307+ if self . security_mode . tls_server_secret_class ( ) . is_some ( ) {
1308+ & Scheme :: Https
1309+ } else {
1310+ & Scheme :: Http
1311+ } ,
1312+ "/_prometheus/metrics" ,
1313+ & HTTP_PORT ,
13061314 ) )
13071315 . build ( ) ;
13081316
@@ -1336,36 +1344,6 @@ impl<'a> RoleGroupBuilder<'a> {
13361344 }
13371345 }
13381346
1339- /// Common labels for Prometheus
1340- fn prometheus_labels ( ) -> Labels {
1341- Labels :: try_from ( [ ( "prometheus.io/scrape" , "true" ) ] ) . expect ( "should be a valid label" )
1342- }
1343-
1344- /// Common annotations for Prometheus
1345- ///
1346- /// These annotations can be used in a ServiceMonitor.
1347- ///
1348- /// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
1349- fn prometheus_annotations ( tls_on_http_port_enabled : bool ) -> Annotations {
1350- Annotations :: try_from ( [
1351- (
1352- "prometheus.io/path" . to_owned ( ) ,
1353- "/_prometheus/metrics" . to_owned ( ) ,
1354- ) ,
1355- ( "prometheus.io/port" . to_owned ( ) , HTTP_PORT . to_string ( ) ) ,
1356- (
1357- "prometheus.io/scheme" . to_owned ( ) ,
1358- if tls_on_http_port_enabled {
1359- "https" . to_owned ( )
1360- } else {
1361- "http" . to_owned ( )
1362- } ,
1363- ) ,
1364- ( "prometheus.io/scrape" . to_owned ( ) , "true" . to_owned ( ) ) ,
1365- ] )
1366- . expect ( "should be valid annotations" )
1367- }
1368-
13691347 /// Builds the [`listener::v1alpha1::Listener`] for the role group
13701348 ///
13711349 /// The Listener exposes only the HTTP port.
@@ -3416,11 +3394,4 @@ mod tests {
34163394 RoleGroupBuilder :: build_node_role_label ( & node_role) ;
34173395 }
34183396 }
3419-
3420- #[ test]
3421- fn test_prometheus_annotations ( ) {
3422- // Test that the function does not panic on all possible inputs
3423- RoleGroupBuilder :: prometheus_annotations ( false ) ;
3424- RoleGroupBuilder :: prometheus_annotations ( true ) ;
3425- }
34263397}
0 commit comments