Skip to content

Commit 3fadda1

Browse files
authored
chore: ensure metrics are correctly exposed (#698)
* add prometheus annotations to metrics service * clippy * adapted changelog * fix copy paste
1 parent 3970d63 commit 3fadda1

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- `EOS_CHECK_MODE` (`--eos-check-mode`) to set the EoS check mode. Currently, only "offline" is supported.
1414
- `EOS_INTERVAL` (`--eos-interval`) to set the interval in which the operator checks if it is EoS.
1515
- `EOS_DISABLED` (`--eos-disabled`) to disable the EoS checker completely.
16+
- Add `prometheus.io/path|port|scheme` annotations to metrics service ([#698]).
1617

1718
### Changed
1819

@@ -50,6 +51,7 @@
5051
[#692]: https://github.com/stackabletech/airflow-operator/pull/692
5152
[#695]: https://github.com/stackabletech/airflow-operator/pull/695
5253
[#696]: https://github.com/stackabletech/airflow-operator/pull/696
54+
[#698]: https://github.com/stackabletech/airflow-operator/pull/698
5355

5456
## [25.7.0] - 2025-07-23
5557

rust/operator-binary/src/service.rs

Lines changed: 23 additions & 5 deletions
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, Labels, ObjectLabels},
88
role_utils::RoleGroupRef,
99
};
1010

@@ -78,17 +78,15 @@ pub fn build_rolegroup_metrics_service(
7878
) -> Result<Service, Error> {
7979
let ports = metrics_service_ports();
8080

81-
let prometheus_label =
82-
Label::try_from(("prometheus.io/scrape", "true")).context(LabelBuildSnafu)?;
83-
8481
let metadata = ObjectMetaBuilder::new()
8582
.name_and_namespace(airflow)
8683
.name(rolegroup_metrics_service_name(&rolegroup_ref.object_name()))
8784
.ownerreference_from_resource(airflow, None, Some(true))
8885
.context(ObjectMissingMetadataForOwnerRefSnafu)?
8986
.with_recommended_labels(object_labels)
9087
.context(MetadataBuildSnafu)?
91-
.with_label(prometheus_label)
88+
.with_labels(prometheus_labels())
89+
.with_annotations(prometheus_annotations())
9290
.build();
9391

9492
let service_spec = ServiceSpec {
@@ -145,3 +143,23 @@ fn metrics_service_ports() -> Vec<ServicePort> {
145143
..ServicePort::default()
146144
}]
147145
}
146+
147+
/// Common labels for Prometheus
148+
fn prometheus_labels() -> Labels {
149+
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
150+
}
151+
152+
/// Common annotations for Prometheus
153+
///
154+
/// These annotations can be used in a ServiceMonitor.
155+
///
156+
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
157+
fn prometheus_annotations() -> Annotations {
158+
Annotations::try_from([
159+
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
160+
("prometheus.io/port".to_owned(), METRICS_PORT.to_string()),
161+
("prometheus.io/scheme".to_owned(), "http".to_owned()),
162+
("prometheus.io/scrape".to_owned(), "true".to_owned()),
163+
])
164+
.expect("should be valid annotations")
165+
}

0 commit comments

Comments
 (0)