Skip to content

Commit d7c35e6

Browse files
committed
chore: replace promethues label & annotations with op-rs v2 helper
1 parent 0743d01 commit d7c35e6

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

  • rust/operator-binary/src/controller/build/resource

rust/operator-binary/src/controller/build/resource/service.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::collections::BTreeMap;
22

33
use stackable_operator::{
44
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
5-
kvp::{Annotations, Labels},
5+
kvp::Labels,
6+
v2::builder::service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
67
};
78

89
use crate::{
@@ -60,8 +61,13 @@ pub fn build_rolegroup_metrics_service(
6061
.to_string(),
6162
recommended_labels.clone(),
6263
)
63-
.with_labels(prometheus_labels())
64-
.with_annotations(prometheus_annotations())
64+
.with_labels(prometheus_labels(&Scraping::Enabled))
65+
.with_annotations(prometheus_annotations(
66+
&Scraping::Enabled,
67+
&Scheme::Http,
68+
"/metrics",
69+
&METRICS_PORT,
70+
))
6571
.build(),
6672
spec: Some(ServiceSpec {
6773
// Internal communication does not need to be exposed
@@ -96,23 +102,3 @@ fn metrics_service_ports() -> Vec<ServicePort> {
96102
..ServicePort::default()
97103
}]
98104
}
99-
100-
/// Common labels for Prometheus
101-
fn prometheus_labels() -> Labels {
102-
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
103-
}
104-
105-
/// Common annotations for Prometheus
106-
///
107-
/// These annotations can be used in a ServiceMonitor.
108-
///
109-
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
110-
fn prometheus_annotations() -> Annotations {
111-
Annotations::try_from([
112-
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
113-
("prometheus.io/port".to_owned(), METRICS_PORT.to_string()),
114-
("prometheus.io/scheme".to_owned(), "http".to_owned()),
115-
("prometheus.io/scrape".to_owned(), "true".to_owned()),
116-
])
117-
.expect("should be valid annotations")
118-
}

0 commit comments

Comments
 (0)