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 diff --git a/rust/operator-binary/src/druid_controller.rs b/rust/operator-binary/src/druid_controller.rs index e6431f40..12186e9d 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, @@ -87,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"; @@ -1078,6 +1076,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 @@ -1220,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 62f25a1f..b985bf20 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, }; @@ -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,14 +72,13 @@ 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) .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 @@ -108,12 +102,17 @@ 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. +/// +/// 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") }