fix: unjank the demo #85
| @ -1,5 +1,6 @@ | |||||||
| use std::{path::PathBuf, sync::Arc}; | use std::{path::PathBuf, sync::Arc}; | ||||||
| 
 | 
 | ||||||
|  | use base64::{Engine as _, engine::general_purpose}; | ||||||
| use harmony::{ | use harmony::{ | ||||||
|     data::Id, |     data::Id, | ||||||
|     inventory::Inventory, |     inventory::Inventory, | ||||||
| @ -9,11 +10,17 @@ use harmony::{ | |||||||
|             ApplicationScore, RustWebFramework, RustWebapp, |             ApplicationScore, RustWebFramework, RustWebapp, | ||||||
|             features::{ContinuousDelivery, Monitoring}, |             features::{ContinuousDelivery, Monitoring}, | ||||||
|         }, |         }, | ||||||
|  |         monitoring::{ | ||||||
|  |             alert_channel::webhook_receiver::WebhookReceiver, | ||||||
|  |             kube_prometheus::helm_prometheus_alert_score::HelmPrometheusAlertingScore, | ||||||
|  |             ntfy::ntfy::NtfyScore, | ||||||
|  |         }, | ||||||
|         tenant::TenantScore, |         tenant::TenantScore, | ||||||
|     }, |     }, | ||||||
|  |     score::Score, | ||||||
|     topology::{ |     topology::{ | ||||||
|         K8sAnywhereTopology, Url, |         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 { |     let application = Arc::new(RustWebapp { | ||||||
|         name: "harmony-example-rust-webapp".to_string(), |         name: "harmony-example-rust-webapp".to_string(), | ||||||
|         domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()), |         domain: Url::Url(url::Url::parse("https://rustapp.harmony.example.com").unwrap()), | ||||||
| @ -43,21 +61,59 @@ async fn main() { | |||||||
|         framework: Some(RustWebFramework::Leptos), |         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 { |     let app = ApplicationScore { | ||||||
|         features: vec![ |         features: vec![ | ||||||
|             Box::new(ContinuousDelivery { |             Box::new(ContinuousDelivery { | ||||||
|                 application: application.clone(), |                 application: application.clone(), | ||||||
|             }), |             }), // TODO add monitoring, backups, multisite ha, etc
 | ||||||
|             Box::new(Monitoring {}), |  | ||||||
|             // TODO add monitoring, backups, multisite ha, etc
 |  | ||||||
|         ], |         ], | ||||||
|         application, |         application, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let topology = K8sAnywhereTopology::from_env(); |     maestro.register_all(vec![ | ||||||
|     let mut maestro = Maestro::initialize(Inventory::autoload(), topology) |         Box::new(tenant), | ||||||
|         .await |         Box::new(ntfy), | ||||||
|         .unwrap(); |         Box::new(alerting_score), | ||||||
|     maestro.register_all(vec![Box::new(tenant), Box::new(app)]); |         Box::new(app), | ||||||
|  |     ]); | ||||||
|     harmony_cli::init(maestro, None).await.unwrap(); |     harmony_cli::init(maestro, None).await.unwrap(); | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	
Our users have no clue what ntfy or prometheus is, this is leaking Harmony's internals. Alerting is just a feature of the infrastructure that they do not need to know how it is implemented.