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 @@ -13,6 +13,7 @@
- `EOS_CHECK_MODE` (`--eos-check-mode`) to set the EoS check mode. Currently, only "offline" is supported.
- `EOS_INTERVAL` (`--eos-interval`) to set the interval in which the operator checks if it is EoS.
- `EOS_DISABLED` (`--eos-disabled`) to disable the EoS checker completely.
- Add `prometheus.io/path|port|scheme` annotations to metrics service ([#698]).

### Changed

Expand Down Expand Up @@ -50,6 +51,7 @@
[#692]: https://github.com/stackabletech/airflow-operator/pull/692
[#695]: https://github.com/stackabletech/airflow-operator/pull/695
[#696]: https://github.com/stackabletech/airflow-operator/pull/696
[#698]: https://github.com/stackabletech/airflow-operator/pull/698

## [25.7.0] - 2025-07-23

Expand Down
28 changes: 23 additions & 5 deletions rust/operator-binary/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Labels, ObjectLabels},
role_utils::RoleGroupRef,
};

Expand Down Expand Up @@ -78,17 +78,15 @@ pub fn build_rolegroup_metrics_service(
) -> Result<Service, Error> {
let ports = metrics_service_ports();

let prometheus_label =
Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?;

let metadata = ObjectMetaBuilder::new()
.name_and_namespace(airflow)
.name(rolegroup_metrics_service_name(&rolegroup_ref.object_name()))
.ownerreference_from_resource(airflow, None, Some(true))
.context(ObjectMissingMetadataForOwnerRefSnafu)?
.with_recommended_labels(object_labels)
.context(MetadataBuildSnafu)?
.with_label(prometheus_label)
.with_labels(prometheus_labels())
.with_annotations(prometheus_annotations())
.build();

let service_spec = ServiceSpec {
Expand Down Expand Up @@ -145,3 +143,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