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 diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index c24548ca..ff313e7a 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, 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(), METRICS_PORT.to_string()), + ("prometheus.io/scheme".to_owned(), "http".to_owned()), + ("prometheus.io/scrape".to_owned(), "true".to_owned()), + ]) + .expect("should be valid annotations") +}