Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
19 changes: 8 additions & 11 deletions rust/operator-binary/src/druid_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 17 additions & 18 deletions rust/operator-binary/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@ 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,
};

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"))]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -108,12 +102,17 @@ fn metrics_service_ports() -> Vec<ServicePort> {
}]
}

/// Returns the metrics rolegroup service name `<cluster>-<role>-<rolegroup>-<METRICS_SERVICE_SUFFIX>`.
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 `<cluster>-<role>-<rolegroup>-<HEADLESS_SERVICE_SUFFIX>`.
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 <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
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")
}