fixes for some comments
Some checks failed
Run Check Script / check (pull_request) Failing after -30s
Some checks failed
Run Check Script / check (pull_request) Failing after -30s
This commit is contained in:
parent
cbbe52fe9b
commit
ca05c67a8e
@ -20,8 +20,6 @@ use harmony::{
|
||||
topology::{K8sAnywhereTopology, Url},
|
||||
};
|
||||
|
||||
use harmony_macros::http_scheme;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let discord_receiver = DiscordWebhook {
|
||||
@ -47,33 +45,23 @@ async fn main() {
|
||||
|
||||
let service_monitor_endpoint = ServiceMonitorEndpoint {
|
||||
port: Some("80".to_string()),
|
||||
target_port: None,
|
||||
bearer_token_file: None,
|
||||
interval: None,
|
||||
path: "/metrics".to_string(),
|
||||
scheme: http_scheme!("http"),
|
||||
tls_config: None,
|
||||
metric_relabelings: vec![],
|
||||
relabelings: vec![],
|
||||
scheme: HTTPScheme::HTTP,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let service_monitor = ServiceMonitor {
|
||||
name: "test-service-monitor".to_string(),
|
||||
additional_labels: None,
|
||||
job_label: None,
|
||||
target_labels: vec![],
|
||||
pod_target_labels: vec![],
|
||||
selector: Selector {
|
||||
match_labels: HashMap::new(),
|
||||
match_expressions: vec![MatchExpression {
|
||||
key: "test".to_string(),
|
||||
operator: "In".to_string(),
|
||||
operator: Operator::In,
|
||||
values: vec!["test-service".to_string()],
|
||||
}],
|
||||
},
|
||||
namespace_selector: None,
|
||||
endpoints: vec![service_monitor_endpoint],
|
||||
fallback_scrape_protocol: None,
|
||||
..Default::default()
|
||||
};
|
||||
let alerting_score = HelmPrometheusAlertingScore {
|
||||
receivers: vec![Box::new(discord_receiver)],
|
||||
|
@ -54,6 +54,22 @@ pub struct AlertGroup {
|
||||
pub groups: Vec<AlertManagerRuleGroup>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum HTTPScheme {
|
||||
#[serde(rename = "http")]
|
||||
HTTP,
|
||||
#[serde(rename = "https")]
|
||||
HTTPS,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub enum Operator {
|
||||
In,
|
||||
NotIn,
|
||||
Exists,
|
||||
DoesNotExist,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct PrometheusConfigValues {
|
||||
@ -116,7 +132,7 @@ pub struct ServiceMonitorEndpoint {
|
||||
|
||||
// ## HTTP scheme to use for scraping
|
||||
// ##
|
||||
pub scheme: String,
|
||||
pub scheme: HTTPScheme,
|
||||
|
||||
// ## TLS configuration to use when scraping the endpoint
|
||||
// ##
|
||||
@ -146,7 +162,7 @@ pub struct ServiceMonitorEndpoint {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MatchExpression {
|
||||
pub key: String,
|
||||
pub operator: String,
|
||||
pub operator: Operator,
|
||||
pub values: Vec<String>,
|
||||
}
|
||||
|
||||
@ -201,3 +217,38 @@ pub struct ServiceMonitor {
|
||||
// # ref: https://github.com/prometheus-operator/prometheus-operator/blob/main/Documentation/api-reference/api.md#monitoring.coreos.com/v1.ScrapeProtocol
|
||||
pub fallback_scrape_protocol: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for ServiceMonitor {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: Default::default(),
|
||||
additional_labels: Default::default(),
|
||||
job_label: Default::default(),
|
||||
target_labels: Default::default(),
|
||||
pod_target_labels: Default::default(),
|
||||
selector: Selector {
|
||||
match_labels: HashMap::new(),
|
||||
match_expressions: vec![],
|
||||
},
|
||||
namespace_selector: Default::default(),
|
||||
endpoints: Default::default(),
|
||||
fallback_scrape_protocol: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ServiceMonitorEndpoint {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
port: Some("80".to_string()),
|
||||
target_port: Default::default(),
|
||||
bearer_token_file: Default::default(),
|
||||
interval: Default::default(),
|
||||
path: "/metrics".to_string(),
|
||||
scheme: HTTPScheme::HTTP,
|
||||
tls_config: Default::default(),
|
||||
metric_relabelings: Default::default(),
|
||||
relabelings: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,26 +133,6 @@ pub fn ingress_path(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that a string is a valid http scheme
|
||||
/// Panics if not http or https
|
||||
#[proc_macro]
|
||||
pub fn http_scheme(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as LitStr);
|
||||
let scheme_str = input.value();
|
||||
|
||||
if scheme_str.to_lowercase() == "http" {
|
||||
let expanded = quote! {(#scheme_str.to_lowercase().to_string()) };
|
||||
return TokenStream::from(expanded);
|
||||
}
|
||||
|
||||
if scheme_str.to_lowercase() == "https" {
|
||||
let expanded = quote! {(#scheme_str.to_lowercase().to_string()) };
|
||||
return TokenStream::from(expanded);
|
||||
}
|
||||
|
||||
panic!("Invalid HTTP scheme")
|
||||
}
|
||||
|
||||
#[proc_macro]
|
||||
pub fn cidrv4(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as LitStr);
|
||||
|
Loading…
Reference in New Issue
Block a user