Skip to content

Commit 458a463

Browse files
committed
chore: swich to v2 prometheus annotations & scraping label
1 parent 798e223 commit 458a463

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

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

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use stackable_operator::{
22
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
3-
kvp::{Annotations, Labels},
4-
v2::types::operator::RoleGroupName,
3+
v2::{
4+
builder::service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
5+
types::operator::RoleGroupName,
6+
},
57
};
68

79
use crate::{
@@ -63,8 +65,13 @@ pub fn build_rolegroup_metrics_service(
6365
druid_role,
6466
role_group_name,
6567
)
66-
.with_labels(prometheus_labels())
67-
.with_annotations(prometheus_annotations())
68+
.with_labels(prometheus_labels(&Scraping::Enabled))
69+
.with_annotations(prometheus_annotations(
70+
&Scraping::Enabled,
71+
&Scheme::Http,
72+
"/metrics",
73+
&METRICS_PORT,
74+
))
6875
.build(),
6976
spec: Some(ServiceSpec {
7077
// Internal communication does not need to be exposed
@@ -91,23 +98,3 @@ fn metrics_service_ports() -> Vec<ServicePort> {
9198
..ServicePort::default()
9299
}]
93100
}
94-
95-
/// The Prometheus scraping label added to the metrics [`Service`].
96-
fn prometheus_labels() -> Labels {
97-
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
98-
}
99-
100-
/// Common annotations for Prometheus
101-
///
102-
/// These annotations can be used in a ServiceMonitor.
103-
///
104-
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
105-
fn prometheus_annotations() -> Annotations {
106-
Annotations::try_from([
107-
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
108-
("prometheus.io/port".to_owned(), METRICS_PORT.to_string()),
109-
("prometheus.io/scheme".to_owned(), "http".to_owned()),
110-
("prometheus.io/scrape".to_owned(), "true".to_owned()),
111-
])
112-
.expect("should be valid annotations")
113-
}

0 commit comments

Comments
 (0)