Skip to content

Commit 29231a7

Browse files
committed
chore: ensure metrics are correctly exposed
1 parent a6ad574 commit 29231a7

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

rust/operator-binary/src/druid_controller.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ use crate::{
7373
Container, DB_PASSWORD_ENV, DB_USERNAME_ENV, DRUID_CONFIG_DIRECTORY, DS_BUCKET,
7474
DeepStorageSpec, DruidClusterStatus, DruidRole, EXTENSIONS_LOADLIST, HDFS_CONFIG_DIRECTORY,
7575
JVM_CONFIG, JVM_SECURITY_PROPERTIES_FILE, LOG_CONFIG_DIRECTORY, MAX_DRUID_LOG_FILES_SIZE,
76-
OPERATOR_NAME, RUNTIME_PROPS, RW_CONFIG_DIRECTORY, S3_ACCESS_KEY, S3_ENDPOINT_URL,
77-
S3_PATH_STYLE_ACCESS, S3_SECRET_KEY, STACKABLE_LOG_DIR, ZOOKEEPER_CONNECTION_STRING,
78-
authentication::AuthenticationClassesResolved, authorization::DruidAuthorization,
79-
build_recommended_labels, build_string_list, security::DruidTlsSecurity, v1alpha1,
76+
METRICS_PORT, METRICS_PORT_NAME, OPERATOR_NAME, RUNTIME_PROPS, RW_CONFIG_DIRECTORY,
77+
S3_ACCESS_KEY, S3_ENDPOINT_URL, S3_PATH_STYLE_ACCESS, S3_SECRET_KEY, STACKABLE_LOG_DIR,
78+
ZOOKEEPER_CONNECTION_STRING, authentication::AuthenticationClassesResolved,
79+
authorization::DruidAuthorization, build_recommended_labels, build_string_list,
80+
security::DruidTlsSecurity, v1alpha1,
8081
},
8182
discovery::{self, build_discovery_configmaps},
8283
extensions::get_extension_list,
@@ -1078,6 +1079,7 @@ fn build_rolegroup_statefulset(
10781079
.args(vec![main_container_commands.join("\n")])
10791080
.add_env_vars(rest_env)
10801081
.add_container_ports(druid_tls_security.container_ports(role))
1082+
.add_container_port(METRICS_PORT_NAME, METRICS_PORT.into())
10811083
// 10s * 30 = 300s to come up
10821084
.startup_probe(druid_tls_security.get_tcp_socket_probe(30, 10, 30, 3))
10831085
// 10s * 1 = 10s to get removed from service

rust/operator-binary/src/service.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use snafu::{ResultExt, Snafu};
44
use stackable_operator::{
55
builder::meta::ObjectMetaBuilder,
66
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
7-
kvp::{Label, ObjectLabels},
7+
kvp::{Annotations, Label, ObjectLabels},
88
role_utils::RoleGroupRef,
99
};
1010

@@ -85,6 +85,7 @@ pub fn build_rolegroup_metrics_service(
8585
.with_recommended_labels(object_labels)
8686
.context(MetadataBuildSnafu)?
8787
.with_label(Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?)
88+
.with_annotations(prometheus_annotations())
8889
.build(),
8990
spec: Some(ServiceSpec {
9091
// Internal communication does not need to be exposed
@@ -117,3 +118,18 @@ fn rolegroup_metrics_service_name(role_group_ref_object_name: &str) -> String {
117118
pub fn rolegroup_headless_service_name(role_group_ref_object_name: &str) -> String {
118119
format!("{role_group_ref_object_name}-{HEADLESS_SERVICE_SUFFIX}")
119120
}
121+
122+
/// Common annotations for Prometheus
123+
///
124+
/// These annotations can be used in a ServiceMonitor.
125+
///
126+
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
127+
fn prometheus_annotations() -> Annotations {
128+
Annotations::try_from([
129+
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
130+
("prometheus.io/port".to_owned(), METRICS_PORT.to_string()),
131+
("prometheus.io/scheme".to_owned(), "http".to_owned()),
132+
("prometheus.io/scrape".to_owned(), "true".to_owned()),
133+
])
134+
.expect("should be valid annotations")
135+
}

0 commit comments

Comments
 (0)