|
1 | 1 | use stackable_operator::{ |
2 | 2 | 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 | + }, |
5 | 7 | }; |
6 | 8 |
|
7 | 9 | use crate::{ |
@@ -74,8 +76,13 @@ pub(crate) fn build_server_rolegroup_metrics_service( |
74 | 76 | .metrics_service_name(), |
75 | 77 | role_group_name, |
76 | 78 | ) |
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 | + )) |
79 | 86 | .build(); |
80 | 87 |
|
81 | 88 | let service_spec = ServiceSpec { |
@@ -108,23 +115,3 @@ pub(crate) fn build_server_rolegroup_metrics_service( |
108 | 115 | status: None, |
109 | 116 | } |
110 | 117 | } |
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