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 @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
### Added

- Helm: Allow Pod `priorityClassName` to be configured ([#633]).
- Add `prometheus.io/path|port|scheme` annotations to metrics service ([#641]).

### Fixed

Expand All @@ -18,6 +19,7 @@ All notable changes to this project will be documented in this file.

[#633]: https://github.com/stackabletech/hive-operator/pull/633
[#636]: https://github.com/stackabletech/hive-operator/pull/636
[#641]: https://github.com/stackabletech/hive-operator/pull/641

## [25.7.0] - 2025-07-23

Expand Down
25 changes: 23 additions & 2 deletions rust/operator-binary/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use stackable_operator::{
builder::meta::ObjectMetaBuilder,
commons::product_image_selection::ResolvedProductImage,
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
kvp::{Label, Labels},
kvp::{Annotations, Labels},
role_utils::RoleGroupRef,
};

Expand Down Expand Up @@ -90,7 +90,8 @@ pub fn build_rolegroup_metrics_service(
&rolegroup.role_group,
))
.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 @@ -139,3 +140,23 @@ fn 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