Skip to content

Commit b6a2bdf

Browse files
committed
chore: use v2 prom scrape label and annotations
1 parent 3a1033d commit b6a2bdf

1 file changed

Lines changed: 19 additions & 28 deletions

File tree

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

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

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ use snafu::{ResultExt, Snafu};
22
use stackable_operator::{
33
builder::meta::ObjectMetaBuilder,
44
k8s_openapi::api::core::v1::{Service, ServicePort, ServiceSpec},
5-
kvp::{Annotations, Label, LabelError},
6-
v2::{builder::meta::ownerreference_from_resource, types::operator::RoleGroupName},
5+
kvp::LabelError,
6+
v2::{
7+
builder::{
8+
meta::ownerreference_from_resource,
9+
service::{Scheme, Scraping, prometheus_annotations, prometheus_labels},
10+
},
11+
types::operator::RoleGroupName,
12+
},
713
};
814

915
use crate::{
@@ -15,9 +21,6 @@ use crate::{
1521

1622
#[derive(Snafu, Debug)]
1723
pub enum Error {
18-
#[snafu(display("failed to build prometheus label"))]
19-
BuildPrometheusLabel { source: LabelError },
20-
2124
#[snafu(display("failed to build object meta data"))]
2225
ObjectMeta {
2326
source: stackable_operator::builder::meta::Error,
@@ -132,29 +135,17 @@ pub(crate) fn rolegroup_metrics_service(
132135
role_group_name.as_ref(),
133136
))
134137
.context(ObjectMetaSnafu)?
135-
.with_label(
136-
Label::try_from(("prometheus.io/scrape", "true"))
137-
.context(BuildPrometheusLabelSnafu)?,
138-
)
139-
.with_annotations(
140-
Annotations::try_from([
141-
("prometheus.io/path".to_owned(), "/prom".to_owned()),
142-
(
143-
"prometheus.io/port".to_owned(),
144-
build::native_metrics_port(cluster, role).to_string(),
145-
),
146-
(
147-
"prometheus.io/scheme".to_owned(),
148-
if cluster.has_https_enabled() {
149-
"https".to_owned()
150-
} else {
151-
"http".to_owned()
152-
},
153-
),
154-
("prometheus.io/scrape".to_owned(), "true".to_owned()),
155-
])
156-
.expect("should be valid annotations"),
157-
)
138+
.with_labels(prometheus_labels(&Scraping::Enabled))
139+
.with_annotations(prometheus_annotations(
140+
&Scraping::Enabled,
141+
if cluster.has_https_enabled() {
142+
&Scheme::Https
143+
} else {
144+
&Scheme::Http
145+
},
146+
"/prom",
147+
&build::native_metrics_port(cluster, role),
148+
))
158149
.build(),
159150
spec: Some(service_spec),
160151
status: None,

0 commit comments

Comments
 (0)