From 29231a759fb297fcf56fca96686f26f215c3f24b Mon Sep 17 00:00:00 2001 From: xeniape Date: Mon, 13 Oct 2025 11:22:50 +0200 Subject: [PATCH 1/3] chore: ensure metrics are correctly exposed --- rust/operator-binary/src/druid_controller.rs | 10 ++++++---- rust/operator-binary/src/service.rs | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/rust/operator-binary/src/druid_controller.rs b/rust/operator-binary/src/druid_controller.rs index e6431f40..8f045bbc 100644 --- a/rust/operator-binary/src/druid_controller.rs +++ b/rust/operator-binary/src/druid_controller.rs @@ -73,10 +73,11 @@ use crate::{ Container, DB_PASSWORD_ENV, DB_USERNAME_ENV, DRUID_CONFIG_DIRECTORY, DS_BUCKET, DeepStorageSpec, DruidClusterStatus, DruidRole, EXTENSIONS_LOADLIST, HDFS_CONFIG_DIRECTORY, JVM_CONFIG, JVM_SECURITY_PROPERTIES_FILE, LOG_CONFIG_DIRECTORY, MAX_DRUID_LOG_FILES_SIZE, - OPERATOR_NAME, RUNTIME_PROPS, RW_CONFIG_DIRECTORY, S3_ACCESS_KEY, S3_ENDPOINT_URL, - S3_PATH_STYLE_ACCESS, S3_SECRET_KEY, STACKABLE_LOG_DIR, ZOOKEEPER_CONNECTION_STRING, - authentication::AuthenticationClassesResolved, authorization::DruidAuthorization, - build_recommended_labels, build_string_list, security::DruidTlsSecurity, v1alpha1, + METRICS_PORT, METRICS_PORT_NAME, OPERATOR_NAME, RUNTIME_PROPS, RW_CONFIG_DIRECTORY, + S3_ACCESS_KEY, S3_ENDPOINT_URL, S3_PATH_STYLE_ACCESS, S3_SECRET_KEY, STACKABLE_LOG_DIR, + ZOOKEEPER_CONNECTION_STRING, authentication::AuthenticationClassesResolved, + authorization::DruidAuthorization, build_recommended_labels, build_string_list, + security::DruidTlsSecurity, v1alpha1, }, discovery::{self, build_discovery_configmaps}, extensions::get_extension_list, @@ -1078,6 +1079,7 @@ fn build_rolegroup_statefulset( .args(vec![main_container_commands.join("\n")]) .add_env_vars(rest_env) .add_container_ports(druid_tls_security.container_ports(role)) + .add_container_port(METRICS_PORT_NAME, METRICS_PORT.into()) // 10s * 30 = 300s to come up .startup_probe(druid_tls_security.get_tcp_socket_probe(30, 10, 30, 3)) // 10s * 1 = 10s to get removed from service diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index 62f25a1f..9927a0cf 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, ObjectLabels}, role_utils::RoleGroupRef, }; @@ -85,6 +85,7 @@ pub fn build_rolegroup_metrics_service( .with_recommended_labels(object_labels) .context(MetadataBuildSnafu)? .with_label(Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?) + .with_annotations(prometheus_annotations()) .build(), spec: Some(ServiceSpec { // Internal communication does not need to be exposed @@ -117,3 +118,18 @@ fn rolegroup_metrics_service_name(role_group_ref_object_name: &str) -> String { pub fn rolegroup_headless_service_name(role_group_ref_object_name: &str) -> String { format!("{role_group_ref_object_name}-{HEADLESS_SERVICE_SUFFIX}") } + +/// 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") +} From 2742b450a0c71b8da5155fe2bbaf606a122cdac8 Mon Sep 17 00:00:00 2001 From: xeniape Date: Mon, 13 Oct 2025 13:14:10 +0200 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82c343d2..fb664702 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file. - Helm: Allow Pod `priorityClassName` to be configured ([#752]). - Add support for `34.0.0` ([#755]). +- Add `prometheus.io/path|port|scheme` annotations to metrics services ([#761]). ### Changed @@ -31,6 +32,7 @@ All notable changes to this project will be documented in this file. [#753]: https://github.com/stackabletech/druid-operator/pull/753 [#755]: https://github.com/stackabletech/druid-operator/pull/755 [#756]: https://github.com/stackabletech/druid-operator/pull/756 +[#761]: https://github.com/stackabletech/druid-operator/pull/761 ## [25.7.0] - 2025-07-23 From d6fb58d943346fdd4155958c3d12822593b3bdff Mon Sep 17 00:00:00 2001 From: xeniape Date: Wed, 15 Oct 2025 14:22:28 +0200 Subject: [PATCH 3/3] small refactoring for service name functions --- rust/operator-binary/src/druid_controller.rs | 9 ++------- rust/operator-binary/src/service.rs | 21 ++------------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/rust/operator-binary/src/druid_controller.rs b/rust/operator-binary/src/druid_controller.rs index 8f045bbc..12186e9d 100644 --- a/rust/operator-binary/src/druid_controller.rs +++ b/rust/operator-binary/src/druid_controller.rs @@ -88,10 +88,7 @@ use crate::{ }, operations::{graceful_shutdown::add_graceful_shutdown_config, pdb::add_pdbs}, product_logging::extend_role_group_config_map, - service::{ - build_rolegroup_headless_service, build_rolegroup_metrics_service, - rolegroup_headless_service_name, - }, + service::{build_rolegroup_headless_service, build_rolegroup_metrics_service}, }; pub const DRUID_CONTROLLER_NAME: &str = "druidcluster"; @@ -1222,9 +1219,7 @@ fn build_rolegroup_statefulset( ), ..LabelSelector::default() }, - service_name: Some(rolegroup_headless_service_name( - &rolegroup_ref.object_name(), - )), + service_name: Some(rolegroup_ref.rolegroup_headless_service_name()), template: pod_template, volume_claim_templates: pvcs, ..StatefulSetSpec::default() diff --git a/rust/operator-binary/src/service.rs b/rust/operator-binary/src/service.rs index 9927a0cf..b985bf20 100644 --- a/rust/operator-binary/src/service.rs +++ b/rust/operator-binary/src/service.rs @@ -12,9 +12,6 @@ use crate::crd::{ DruidRole, METRICS_PORT, METRICS_PORT_NAME, security::DruidTlsSecurity, v1alpha1, }; -const METRICS_SERVICE_SUFFIX: &str = "metrics"; -const HEADLESS_SERVICE_SUFFIX: &str = "headless"; - #[derive(Snafu, Debug)] pub enum Error { #[snafu(display("object is missing metadata to build owner reference"))] @@ -46,9 +43,7 @@ pub fn build_rolegroup_headless_service( Ok(Service { metadata: ObjectMetaBuilder::new() .name_and_namespace(druid) - .name(rolegroup_headless_service_name( - &role_group_ref.object_name(), - )) + .name(role_group_ref.rolegroup_headless_service_name()) .ownerreference_from_resource(druid, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? .with_recommended_labels(object_labels) @@ -77,9 +72,7 @@ pub fn build_rolegroup_metrics_service( Ok(Service { metadata: ObjectMetaBuilder::new() .name_and_namespace(druid) - .name(rolegroup_metrics_service_name( - &role_group_ref.object_name(), - )) + .name(role_group_ref.rolegroup_metrics_service_name()) .ownerreference_from_resource(druid, None, Some(true)) .context(ObjectMissingMetadataForOwnerRefSnafu)? .with_recommended_labels(object_labels) @@ -109,16 +102,6 @@ fn metrics_service_ports() -> Vec { }] } -/// Returns the metrics rolegroup service name `---`. -fn rolegroup_metrics_service_name(role_group_ref_object_name: &str) -> String { - format!("{role_group_ref_object_name}-{METRICS_SERVICE_SUFFIX}") -} - -/// Returns the headless rolegroup service name `---`. -pub fn rolegroup_headless_service_name(role_group_ref_object_name: &str) -> String { - format!("{role_group_ref_object_name}-{HEADLESS_SERVICE_SUFFIX}") -} - /// Common annotations for Prometheus /// /// These annotations can be used in a ServiceMonitor.