@@ -3,7 +3,7 @@ use stackable_operator::{
33 builder:: meta:: ObjectMetaBuilder ,
44 commons:: product_image_selection:: ResolvedProductImage ,
55 k8s_openapi:: api:: core:: v1:: { Service , ServicePort , ServiceSpec } ,
6- kvp:: { Label , Labels } ,
6+ kvp:: { Annotations , Labels } ,
77 role_utils:: RoleGroupRef ,
88} ;
99
@@ -90,7 +90,8 @@ pub fn build_rolegroup_metrics_service(
9090 & rolegroup. role_group ,
9191 ) )
9292 . context ( MetadataBuildSnafu ) ?
93- . with_label ( Label :: try_from ( ( "prometheus.io/scrape" , "true" ) ) . context ( LabelBuildSnafu ) ?)
93+ . with_labels ( prometheus_labels ( ) )
94+ . with_annotations ( prometheus_annotations ( ) )
9495 . build ( ) ,
9596 spec : Some ( ServiceSpec {
9697 // Internal communication does not need to be exposed
@@ -139,3 +140,23 @@ fn service_ports() -> Vec<ServicePort> {
139140 ..ServicePort :: default ( )
140141 } ]
141142}
143+
144+ /// Common labels for Prometheus
145+ fn prometheus_labels ( ) -> Labels {
146+ Labels :: try_from ( [ ( "prometheus.io/scrape" , "true" ) ] ) . expect ( "should be a valid label" )
147+ }
148+
149+ /// Common annotations for Prometheus
150+ ///
151+ /// These annotations can be used in a ServiceMonitor.
152+ ///
153+ /// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
154+ fn prometheus_annotations ( ) -> Annotations {
155+ Annotations :: try_from ( [
156+ ( "prometheus.io/path" . to_owned ( ) , "/metrics" . to_owned ( ) ) ,
157+ ( "prometheus.io/port" . to_owned ( ) , METRICS_PORT . to_string ( ) ) ,
158+ ( "prometheus.io/scheme" . to_owned ( ) , "http" . to_owned ( ) ) ,
159+ ( "prometheus.io/scrape" . to_owned ( ) , "true" . to_owned ( ) ) ,
160+ ] )
161+ . expect ( "should be valid annotations" )
162+ }
0 commit comments