Skip to content

Commit 94ce2bb

Browse files
committed
fix: replace promethues annotations and label with v2 helper
1 parent d415c59 commit 94ce2bb

1 file changed

Lines changed: 11 additions & 24 deletions

File tree

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

rust/operator-binary/src/zk_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::{common::Port, operator::RoleGroupName},
3+
v2::{
4+
builder::service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
5+
types::operator::RoleGroupName,
6+
},
57
};
68

79
use crate::{
@@ -74,8 +76,13 @@ pub(crate) fn build_server_rolegroup_metrics_service(
7476
.metrics_service_name(),
7577
role_group_name,
7678
)
77-
.with_labels(prometheus_labels())
78-
.with_annotations(prometheus_annotations(metrics_port.clone()))
79+
.with_labels(prometheus_labels(&Scraping::Enabled))
80+
.with_annotations(prometheus_annotations(
81+
&Scraping::Enabled,
82+
&Scheme::Http,
83+
"/metrics",
84+
&metrics_port,
85+
))
7986
.build();
8087

8188
let service_spec = ServiceSpec {
@@ -108,23 +115,3 @@ pub(crate) fn build_server_rolegroup_metrics_service(
108115
status: None,
109116
}
110117
}
111-
112-
/// Common labels for Prometheus
113-
fn prometheus_labels() -> Labels {
114-
Labels::try_from([("prometheus.io/scrape", "true")]).expect("should be a valid label")
115-
}
116-
117-
/// Common annotations for Prometheus
118-
///
119-
/// These annotations can be used in a ServiceMonitor.
120-
///
121-
/// see also <https://github.com/prometheus-community/helm-charts/blob/prometheus-27.32.0/charts/prometheus/values.yaml#L983-L1036>
122-
fn prometheus_annotations(metrics_port: Port) -> Annotations {
123-
Annotations::try_from([
124-
("prometheus.io/path".to_owned(), "/metrics".to_owned()),
125-
("prometheus.io/port".to_owned(), metrics_port.to_string()),
126-
("prometheus.io/scheme".to_owned(), "http".to_owned()),
127-
("prometheus.io/scrape".to_owned(), "true".to_owned()),
128-
])
129-
.expect("should be valid annotations")
130-
}

0 commit comments

Comments
 (0)