From a5d637e0697ec685bf426c6de91d08c1a0824d07 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Mon, 13 Oct 2025 11:40:31 +0200 Subject: [PATCH 1/4] add prometheus annotations to metrics service --- rust/operator-binary/src/service.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index c24548ca..83b0a490 100644 --- a/rust/operator-binary/src/service.rs +++ b/rust/operator-binary/src/service.rs @@ -4,7 +4,7 @@ use snafu::{ResultExt, Snafu}; use stackable_operator::{ builder::meta::ObjectMetaBuilder, k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec}, - kvp::{Label, ObjectLabels}, + kvp::{Annotations, Label, Labels, ObjectLabels}, role_utils::RoleGroupRef, }; @@ -78,9 +78,6 @@ pub fn build_rolegroup_metrics_service( ) -> Result { let ports = metrics_service_ports(); - let prometheus_label = - Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?; - let metadata = ObjectMetaBuilder::new() .name_and_namespace(airflow) .name(rolegroup_metrics_service_name(&rolegroup_ref.object_name())) @@ -88,7 +85,8 @@ pub fn build_rolegroup_metrics_service( .context(ObjectMissingMetadataForOwnerRefSnafu)? .with_recommended_labels(object_labels) .context(MetadataBuildSnafu)? - .with_label(prometheus_label) + .with_labels(prometheus_labels()) + .with_annotations(prometheus_annotations()) .build(); let service_spec = ServiceSpec { @@ -145,3 +143,23 @@ fn metrics_service_ports() -> Vec { ..ServicePort::default() }] } + +/// Common labels for Prometheus +fn prometheus_labels() -> Labels { + Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label") +} + +/// Common annotations for Prometheus +/// +/// These annotations can be used in a ServiceMonitor. +/// +/// see also +fn prometheus_annotations() -> Annotations { + Annotations::try_from([ + ("prometheus.io/path".to_owned(), "/metrics".to_owned()), + ("prometheus.io/port".to_owned(), HTTP_PORT.to_string()), + ("prometheus.io/scheme".to_owned(), "http".to_owned()), + ("prometheus.io/scrape".to_owned(), "true".to_owned()), + ]) + .expect("should be valid annotations") +} From 5158303b1fd45f1886f069e8a76fde41cbc40fb5 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Mon, 13 Oct 2025 11:45:01 +0200 Subject: [PATCH 2/4] clippy --- rust/operator-binary/src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index 83b0a490..7ee6fe58 100644 --- a/rust/operator-binary/src/service.rs +++ b/rust/operator-binary/src/service.rs @@ -4,7 +4,7 @@ use snafu::{ResultExt, Snafu}; use stackable_operator::{ builder::meta::ObjectMetaBuilder, k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec}, - kvp::{Annotations, Label, Labels, ObjectLabels}, + kvp::{Annotations, Labels, ObjectLabels}, role_utils::RoleGroupRef, }; From c13e0fcf9241cfc70c4b815857332ca72f9f84bb Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Mon, 13 Oct 2025 11:46:59 +0200 Subject: [PATCH 3/4] adapted changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 410d2920..b4cae346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - `EOS_CHECK_MODE` (`--eos-check-mode`) to set the EoS check mode. Currently, only "offline" is supported. - `EOS_INTERVAL` (`--eos-interval`) to set the interval in which the operator checks if it is EoS. - `EOS_DISABLED` (`--eos-disabled`) to disable the EoS checker completely. +- Add `prometheus.io/path|port|scheme` annotations to metrics service ([#698]). ### Changed @@ -50,6 +51,7 @@ [#692]: https://github.com/stackabletech/airflow-operator/pull/692 [#695]: https://github.com/stackabletech/airflow-operator/pull/695 [#696]: https://github.com/stackabletech/airflow-operator/pull/696 +[#698]: https://github.com/stackabletech/airflow-operator/pull/698 ## [25.7.0] - 2025-07-23 From 58818f118b778f91d92304617523bf886e44a5c1 Mon Sep 17 00:00:00 2001 From: Malte Sander Date: Mon, 13 Oct 2025 12:22:34 +0200 Subject: [PATCH 4/4] fix copy paste --- rust/operator-binary/src/service.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index 7ee6fe58..ff313e7a 100644 --- a/rust/operator-binary/src/service.rs +++ b/rust/operator-binary/src/service.rs @@ -157,7 +157,7 @@ fn prometheus_labels() -> Labels { fn prometheus_annotations() -> Annotations { Annotations::try_from([ ("prometheus.io/path".to_owned(), "/metrics".to_owned()), - ("prometheus.io/port".to_owned(), HTTP_PORT.to_string()), + ("prometheus.io/port".to_owned(), METRICS_PORT.to_string()), ("prometheus.io/scheme".to_owned(), "http".to_owned()), ("prometheus.io/scrape".to_owned(), "true".to_owned()), ])