feat: impl clone_box for ScrapeTarget<CRDPrometheus>

This commit is contained in:
Jean-Gabriel Gill-Couture 2025-10-24 11:39:27 -04:00
parent de761cf538
commit b5c081f596
4 changed files with 14 additions and 6 deletions

View File

@ -87,4 +87,5 @@ pub trait AlertRule<S: AlertSender>: std::fmt::Debug + Send + Sync {
#[async_trait]
pub trait ScrapeTarget<S: AlertSender>: std::fmt::Debug + Send + Sync {
async fn install(&self, sender: &S) -> Result<Outcome, InterpretError>;
fn clone_box(&self) -> Box<dyn ScrapeTarget<S>>;
}

View File

@ -14,8 +14,7 @@ use crate::{
},
score::Score,
topology::{
K8sclient, Topology,
oberservability::monitoring::{AlertReceiver, AlertingInterpret},
oberservability::monitoring::{AlertReceiver, AlertingInterpret, ScrapeTarget}, K8sclient, Topology
},
};
@ -35,6 +34,7 @@ impl<T: Topology + PrometheusMonitoring<CRDPrometheus> + K8sclient + Grafana> Sc
sender: self.sender.clone(),
receivers: self.receivers.clone(),
rules: vec![],
scrape_targets: None,
})
}

View File

@ -15,10 +15,7 @@ use crate::{
prometheus::prometheus::PrometheusMonitoring,
},
topology::{
K8sclient, Topology,
installable::Installable,
k8s::K8sClient,
oberservability::monitoring::{AlertReceiver, AlertSender},
installable::Installable, k8s::K8sClient, oberservability::monitoring::{AlertReceiver, AlertSender, ScrapeTarget}, K8sclient, Topology
},
};
@ -54,6 +51,12 @@ impl Clone for Box<dyn AlertReceiver<CRDPrometheus>> {
}
}
impl Clone for Box<dyn ScrapeTarget<CRDPrometheus>> {
fn clone(&self) -> Self {
self.clone_box()
}
}
impl Serialize for Box<dyn AlertReceiver<CRDPrometheus>> {
fn serialize<S>(&self, _serializer: S) -> Result<S::Ok, S::Error>
where

View File

@ -73,4 +73,8 @@ impl ScrapeTarget<CRDPrometheus> for Server {
self.name.clone()
)))
}
fn clone_box(&self) -> Box<dyn ScrapeTarget<CRDPrometheus>> {
Box::new(self.clone())
}
}