Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- Support for the client spooling protocol ([#793]).
- Helm: Allow Pod `priorityClassName` to be configured ([#798]).
- Add support for Trino 477 ([#801]).
- Add `prometheus.io/path|port|scheme` annotations to metrics service ([#807]).

### Changed

Expand All @@ -34,6 +35,7 @@ All notable changes to this project will be documented in this file.
[#796]: https://github.com/stackabletech/trino-operator/pull/796
[#798]: https://github.com/stackabletech/trino-operator/pull/798
[#801]: https://github.com/stackabletech/trino-operator/pull/801
[#807]: https://github.com/stackabletech/trino-operator/pull/807

## [25.7.0] - 2025-07-23

Expand Down
11 changes: 2 additions & 9 deletions rust/operator-binary/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ use crate::{
authentication::resolve_authentication_classes,
catalog,
discovery::{TrinoDiscovery, TrinoDiscoveryProtocol, TrinoPodRef},
rolegroup_headless_service_name, v1alpha1,
v1alpha1,
},
listener::{
LISTENER_VOLUME_DIR, LISTENER_VOLUME_NAME, build_group_listener, build_group_listener_pvc,
Expand Down Expand Up @@ -156,11 +156,6 @@ pub enum Error {
source: stackable_operator::cluster_resources::Error,
},

#[snafu(display("failed to apply global Service"))]
ApplyRoleService {
source: stackable_operator::cluster_resources::Error,
},

#[snafu(display("failed to apply Service for {}", rolegroup))]
ApplyRoleGroupService {
source: stackable_operator::cluster_resources::Error,
Expand Down Expand Up @@ -1394,9 +1389,7 @@ fn build_rolegroup_statefulset(
),
..LabelSelector::default()
},
service_name: Some(rolegroup_headless_service_name(
&role_group_ref.object_name(),
)),
service_name: Some(role_group_ref.rolegroup_headless_service_name()),
template: pod_template,
volume_claim_templates: Some(persistent_volume_claims),
..StatefulSetSpec::default()
Expand Down
17 changes: 1 addition & 16 deletions rust/operator-binary/src/crd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@ pub const MAX_TRINO_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
unit: BinaryMultiple::Mebi,
};

pub const METRICS_SERVICE_SUFFIX: &str = "metrics";
pub const HEADLESS_SERVICE_SUFFIX: &str = "headless";

pub const JVM_HEAP_FACTOR: f32 = 0.8;

pub const DEFAULT_COORDINATOR_GRACEFUL_SHUTDOWN_TIMEOUT: Duration =
Expand Down Expand Up @@ -860,9 +857,7 @@ impl v1alpha1::TrinoCluster {
let ns = ns.clone();
(0..rolegroup.replicas.unwrap_or(0)).map(move |i| TrinoPodRef {
namespace: ns.clone(),
role_group_service_name: rolegroup_headless_service_name(
&role_group_ref.object_name(),
),
role_group_service_name: role_group_ref.rolegroup_headless_service_name(),
pod_name: format!(
"{role_group}-{i}",
role_group = role_group_ref.object_name()
Expand Down Expand Up @@ -963,16 +958,6 @@ impl v1alpha1::TrinoCluster {
}
}

/// Returns the metrics rolegroup service name `<cluster>-<role>-<rolegroup>-<METRICS_SERVICE_SUFFIX>`.
pub 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}")
}

fn extract_role_from_coordinator_config(
fragment: Role<TrinoConfigFragment, TrinoCoordinatorRoleConfig, JavaCommonConfig>,
) -> Role<TrinoConfigFragment, GenericRoleConfig, JavaCommonConfig> {
Expand Down
38 changes: 26 additions & 12 deletions rust/operator-binary/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@ 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,
};

use crate::crd::{
METRICS_PORT, METRICS_PORT_NAME, rolegroup_headless_service_name,
rolegroup_metrics_service_name, v1alpha1,
};
use crate::crd::{METRICS_PORT, METRICS_PORT_NAME, v1alpha1};

#[derive(Snafu, Debug)]
pub enum Error {
Expand Down Expand Up @@ -42,9 +39,7 @@ pub fn build_rolegroup_headless_service(
Ok(Service {
metadata: ObjectMetaBuilder::new()
.name_and_namespace(trino)
.name(rolegroup_headless_service_name(
&role_group_ref.object_name(),
))
.name(role_group_ref.rolegroup_headless_service_name())
.ownerreference_from_resource(trino, None, Some(true))
.context(ObjectMissingMetadataForOwnerRefSnafu)?
.with_recommended_labels(object_labels)
Expand Down Expand Up @@ -73,14 +68,13 @@ pub fn build_rolegroup_metrics_service(
Ok(Service {
metadata: ObjectMetaBuilder::new()
.name_and_namespace(trino)
.name(rolegroup_metrics_service_name(
&role_group_ref.object_name(),
))
.name(role_group_ref.rolegroup_metrics_service_name())
.ownerreference_from_resource(trino, None, Some(true))
.context(ObjectMissingMetadataForOwnerRefSnafu)?
.with_recommended_labels(object_labels)
.context(MetadataBuildSnafu)?
.with_label(Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?)
.with_labels(prometheus_labels())
.with_annotations(prometheus_annotations())
.build(),
spec: Some(ServiceSpec {
// Internal communication does not need to be exposed
Expand Down Expand Up @@ -115,3 +109,23 @@ fn metrics_service_ports() -> Vec<ServicePort> {
..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 <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")
}
Loading