add monitoring and ntfy

This commit is contained in:
tahahawa 2025-07-09 00:12:39 -04:00
parent 9fe586532f
commit 753c3eb9d5

View File

@ -1,5 +1,6 @@
use std::{path::PathBuf, sync::Arc};
use base64::{Engine as _, engine::general_purpose};
use harmony::{
data::Id,
inventory::Inventory,
@ -9,11 +10,17 @@ use harmony::{
ApplicationScore, RustWebFramework, RustWebapp,
features::{ContinuousDelivery, Monitoring},
},
monitoring::{
alert_channel::webhook_receiver::WebhookReceiver,
kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore,
ntfy::ntfy::NtfyScore,
},
tenant::TenantScore,
},
score::Score,
topology::{
K8sAnywhereTopology, Url,
tenant::{ResourceLimits, TenantConfig, TenantNetworkPolicy},
tenant::{ResourceLimits, TenantConfig, TenantManager, TenantNetworkPolicy},
},
};
@ -36,6 +43,17 @@ async fn main() {
},
};
let topology = K8sAnywhereTopology::from_env();
// topology
// .provision_tenant(&tenant.config)
// .await
// .expect("couldn't provision tenant");
let mut maestro = Maestro::initialize(Inventory::autoload(), topology)
.await
.unwrap();
let application = Arc::new(RustWebapp {
name: "harmony-example-rust-webapp".to_string(),
domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()),
@ -43,21 +61,59 @@ async fn main() {
framework: Some(RustWebFramework::Leptos),
});
let ntfy = NtfyScore {
namespace: tenant.clone().config.name,
};
let ntfy_default_auth_username = "harmony";
let ntfy_default_auth_password = "harmony";
let ntfy_default_auth_header = format!(
"Basic {}",
general_purpose::STANDARD.encode(format!(
"{ntfy_default_auth_username}:{ntfy_default_auth_password}"
))
);
let ntfy_default_auth_param = general_purpose::STANDARD
.encode(ntfy_default_auth_header)
.rsplit("=")
.collect::<Vec<&str>>()[0]
.to_string();
let ntfy_receiver = WebhookReceiver {
name: "ntfy-webhook".to_string(),
url: Url::Url(
url::Url::parse(
format!(
"http://ntfy.{}.svc.cluster.local/rust-web-app?auth={ntfy_default_auth_param}",
tenant.clone().config.name
)
.as_str(),
)
.unwrap(),
),
};
let alerting_score = HelmPrometheusAlertingScore {
receivers: vec![Box::new(ntfy_receiver)],
rules: vec![],
service_monitors: vec![],
};
let app = ApplicationScore {
features: vec![
Box::new(ContinuousDelivery {
application: application.clone(),
}),
Box::new(Monitoring {}),
// TODO add monitoring, backups, multisite ha, etc
}), // TODO add monitoring, backups, multisite ha, etc
],
application,
};
let topology = K8sAnywhereTopology::from_env();
let mut maestro = Maestro::initialize(Inventory::autoload(), topology)
.await
.unwrap();
maestro.register_all(vec![Box::new(tenant), Box::new(app)]);
maestro.register_all(vec![
Box::new(tenant),
Box::new(ntfy),
Box::new(alerting_score),
Box::new(app),
]);
harmony_cli::init(maestro, None).await.unwrap();
}