Skip to content

Commit c020711

Browse files
authored
Changes for end to end testing and debug logs (#46)
1 parent 86085ef commit c020711

File tree

14 files changed

+86
-73
lines changed

14 files changed

+86
-73
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/adapters/backend/mod.rs

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
use std::ops::Deref;
22
use std::sync::Arc;
33

4-
use super::{
5-
BoxedIngress, BoxedMonitor, BoxedPlatform, IngressBuilder, MonitorBuilder, PlatformBuilder,
6-
StatusCode,
7-
};
4+
use super::{BoxedIngress, BoxedMonitor, BoxedPlatform, StatusCode};
85
use crate::Cli;
96
use crate::fs::UserCreds;
10-
use crate::{artifacts::LambdaZip, fs::Session, metrics::ResponseStatusCode};
7+
use crate::{fs::Session, metrics::ResponseStatusCode};
118
use chrono::DateTime;
129
use miette::miette;
1310
use miette::{IntoDiagnostic, Result, bail};
@@ -203,30 +200,6 @@ impl BackendClient {
203200
Ok(response.deployment.id)
204201
}
205202

206-
/// Given the workspace name and the application name, fetch
207-
/// the configuration of the application.
208-
pub async fn fetch_config(
209-
&self,
210-
workspace: &str,
211-
application_name: &str,
212-
artifact: LambdaZip,
213-
) -> Result<ApplicationConfig> {
214-
// • First, we have to exchange the workspace name for it's id.
215-
let workspace = self.get_workspace_by_name(workspace).await?;
216-
// • Then, we can do the same with the application name.
217-
let application = self
218-
.get_application_by_name(workspace.id, application_name)
219-
.await?;
220-
let ingress_conf = *application.ingress;
221-
let platform_conf = *application.platform;
222-
let monitor_conf = *application.monitor;
223-
Ok(ApplicationConfig {
224-
platform: PlatformBuilder::new(platform_conf, artifact).build().await,
225-
ingress: IngressBuilder::new(ingress_conf).build().await,
226-
monitor: MonitorBuilder::new(monitor_conf).build().await,
227-
})
228-
}
229-
230203
/// This fuction logs the user into the backend by exchanging these credentials
231204
/// with the backend server.
232205
pub async fn exchange_creds(&self, email: &str, password: &str) -> Result<Session> {
@@ -292,7 +265,7 @@ impl BackendClient {
292265
}
293266

294267
/// Return information about the workspace given its name.
295-
async fn get_workspace_by_name(&self, name: &str) -> Result<WorkspaceSummary> {
268+
pub(crate) async fn get_workspace_by_name(&self, name: &str) -> Result<WorkspaceSummary> {
296269
self.is_authenicated()?;
297270

298271
// let mut workspaces = list_workspaces(&self.conf, Some(name))
@@ -321,7 +294,7 @@ impl BackendClient {
321294
// isntead of having to filter by name.
322295
/// Given the id of the workspace containing the application, and the application's
323296
/// name, fetch the application's information.
324-
async fn get_application_by_name(
297+
pub(crate) async fn get_application_by_name(
325298
&self,
326299
workspace_id: WorkspaceId,
327300
name: &str,
@@ -416,7 +389,7 @@ impl From<LoginSuccess> for UserCreds {
416389
}
417390
}
418391

419-
mod deploy_meta;
392+
pub mod deploy_meta;
420393

421394
#[cfg(test)]
422395
mod tests {

src/adapters/ingresses/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{Shutdownable, WholePercent};
77
/// dispatched.
88
pub type BoxedIngress = Box<dyn Ingress + Send + Sync>;
99

10-
pub(super) use builder::IngressBuilder;
10+
pub(crate) use builder::IngressBuilder;
1111

1212
/// Ingresses are responsible for (1) controlling how much traffic the canary
1313
/// gets (hence the name ingress, since it functions like a virtual LB) and

src/adapters/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub use ingresses::*;
55
pub use monitors::*;
66
pub use platforms::*;
77

8-
mod backend;
8+
pub mod backend;
99
/// Contains the trait definition and ingress implementations. Ingresses are responsible
1010
/// for actuating changes to traffic.
1111
mod ingresses;

src/adapters/monitors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub type StatusCode = CategoricalObservation<5, ResponseStatusCode>;
1717
// and there may not be a generic parameter on the Monitor type anymore.
1818
pub type BoxedMonitor = Box<dyn Monitor<Item = StatusCode> + Send + Sync>;
1919

20-
pub(super) use builder::MonitorBuilder;
20+
pub(crate) use builder::MonitorBuilder;
2121

2222
#[async_trait]
2323
pub trait Monitor: Shutdownable {

src/adapters/platforms/lambda.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use async_trait::async_trait;
22
use bon::bon;
3+
use chrono::format;
34
use miette::{IntoDiagnostic as _, Result, miette};
45

56
use crate::{
@@ -51,14 +52,19 @@ impl Platform for LambdaPlatform {
5152
let res = self
5253
.client
5354
.update_function_code()
55+
.publish(true)
5456
.function_name(&self.name)
5557
.zip_file(zip_file.clone())
5658
.send()
5759
.await
5860
.into_diagnostic()?;
5961

60-
self.arn = res.function_arn().map(|s| s.to_string());
62+
let function_arn = res
63+
.function_arn()
64+
.map(ToString::to_string)
65+
.ok_or(miette!("Couldn't get ARN of deployed lambda"))?;
6166

67+
self.arn = Some(function_arn);
6268
self.arn
6369
.clone()
6470
.ok_or_else(|| miette!("No ARN returned from AWS"))

src/cmd/run.rs

Lines changed: 48 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
use std::path::PathBuf;
22

3-
use crate::adapters::{ApplicationConfig, DeploymentMetadata};
3+
use crate::adapters::backend::{ApplicationId, WorkspaceId};
4+
use crate::adapters::{
5+
ApplicationConfig, DeploymentMetadata, IngressBuilder, MonitorBuilder, PlatformBuilder,
6+
};
47
use crate::fs::{FileSystem, SessionFile};
58
use crate::subsystems::CONTROLLER_SUBSYSTEM_NAME;
69
use crate::{
710
Cli, ControllerSubsystem, adapters::BackendClient, artifacts::LambdaZip, config::RunSubcommand,
811
};
9-
use miette::{IntoDiagnostic, Result};
12+
use miette::Result;
1013
use tokio::runtime::Runtime;
1114
use tokio::time::Duration;
1215
use tokio_graceful_shutdown::{IntoSubsystem as _, SubsystemBuilder, Toplevel};
@@ -21,8 +24,8 @@ const DEFAULT_SHUTDOWN_TIMEOUT: u64 = 5000;
2124
pub struct Run {
2225
_terminal: Terminal,
2326
artifact_path: PathBuf,
24-
workspace: String,
25-
application: String,
27+
workspace_name: String,
28+
application_name: String,
2629
backend: BackendClient,
2730
}
2831

@@ -37,41 +40,53 @@ impl Run {
3740
_terminal: terminal,
3841
backend,
3942
artifact_path: args.artifact_path,
40-
workspace: args.workspace,
41-
application: args.application,
43+
workspace_name: args.workspace,
44+
application_name: args.application,
4245
})
4346
}
4447

4548
pub fn dispatch(self) -> Result<()> {
49+
dbg!("Executing the `run` command...");
4650
let rt = Runtime::new().unwrap();
4751
let _guard = rt.enter();
4852
rt.block_on(async {
49-
// • First, we have to load the artifact.
50-
// This lets us fail fast in the case where the artifact
51-
// doesn't exist or we don't have permission to read the file.
53+
// First, we have to load the artifact.
54+
// This lets us fail fast in the case where the artifact
55+
// doesn't exist or we don't have permission to read the file.
56+
dbg!("Loading the lambda artifact...");
5257
let artifact = LambdaZip::load(&self.artifact_path).await?;
53-
// • Now, we have to load the application's configuration
54-
// from the backend. We have the name of the workspace and
55-
// application, but we need to look up the details.
56-
let conf = self
58+
// We need to convert our workspace and application names into the full workspace and application object
59+
dbg!("Loading workspace and application...");
60+
let workspace = self
61+
.backend
62+
.get_workspace_by_name(&self.workspace_name)
63+
.await?;
64+
let application = self
5765
.backend
58-
.fetch_config(&self.workspace, &self.application, artifact)
66+
.get_application_by_name(workspace.id, &self.application_name)
5967
.await?;
60-
let ApplicationConfig {
61-
ingress,
62-
platform,
63-
monitor,
64-
} = conf;
68+
// Now, we have to load the application's configuration
69+
// from the backend. We have the name of the workspace and
70+
// application, but we need to look up the details.
71+
dbg!("Loading application conf...");
72+
let conf = ApplicationConfig {
73+
platform: PlatformBuilder::new(*application.platform, artifact)
74+
.build()
75+
.await,
76+
ingress: IngressBuilder::new(*application.ingress).build().await,
77+
monitor: MonitorBuilder::new(*application.monitor).build().await,
78+
};
6579

6680
// Create a new deployment.
67-
let metadata = self.create_deployment().await?;
81+
let metadata = self.create_deployment(workspace.id, application.id).await?;
6882

6983
// Build the ControllerSubsystem using the boxed objects.
84+
dbg!("Building controller...");
7085
let controller = ControllerSubsystem::builder()
7186
.backend(self.backend)
72-
.monitor(monitor)
73-
.ingress(ingress)
74-
.platform(platform)
87+
.monitor(conf.monitor)
88+
.ingress(conf.ingress)
89+
.platform(conf.platform)
7590
.meta(metadata)
7691
.build();
7792

@@ -90,21 +105,21 @@ impl Run {
90105
})
91106
}
92107

93-
async fn create_deployment(&self) -> Result<DeploymentMetadata> {
94-
// TODO: This `.parse().into_diagnostic()?` code is awful. Once
95-
// we settle on the type of WorkspaceId and ApplicationId,
96-
// we can clean it up instead of using the raw types.
108+
async fn create_deployment(
109+
&self,
110+
workspace_id: WorkspaceId,
111+
application_id: ApplicationId,
112+
) -> Result<DeploymentMetadata> {
113+
dbg!("Creating new deployment...");
97114
let deployment_id = self
98115
.backend
99-
.new_deployment(
100-
self.workspace.parse().into_diagnostic()?,
101-
self.application.parse().into_diagnostic()?,
102-
)
116+
.new_deployment(workspace_id, application_id)
103117
.await?;
104118

119+
dbg!("Creating new deployment metadata...");
105120
let meta = DeploymentMetadata::builder()
106-
.workspace_id(self.workspace.parse().into_diagnostic()?)
107-
.application_id(self.application.parse().into_diagnostic()?)
121+
.workspace_id(workspace_id)
122+
.application_id(application_id)
108123
.deployment_id(deployment_id)
109124
.build();
110125
Ok(meta)

src/subsystems/controller/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl ControllerSubsystem {
4141
platform: BoxedPlatform,
4242
meta: DeploymentMetadata,
4343
) -> Self {
44+
dbg!("Creating a new controller subsystem...");
4445
Self {
4546
backend,
4647
monitor,
@@ -54,6 +55,7 @@ impl ControllerSubsystem {
5455
#[async_trait]
5556
impl IntoSubsystem<Report> for ControllerSubsystem {
5657
async fn run(self, subsys: SubsystemHandle) -> Result<()> {
58+
dbg!("Running the controller subsystem...");
5759
let ingress_subsystem = IngressSubsystem::new(self.ingress);
5860
let ingress_handle = ingress_subsystem.handle();
5961

src/subsystems/controller/monitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl IntoSubsystem<Report> for MonitorController<StatusCode> {
151151
// Let's emit them to our output stream.
152152
self.sender.send(batch).await.unwrap();
153153
} else {
154+
dbg!("Shutting down in monitor");
154155
// The stream has been closed. Shut down.
155156
subsys.request_local_shutdown();
156157
}

src/subsystems/ingress/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ impl IntoSubsystem<Report> for IngressSubsystem {
9696
if let Some(mail) = mail {
9797
self.respond_to_mail(mail).await;
9898
} else {
99+
dbg!("Stream closed in ingress");
99100
return self.shutdown().await;
100101
}
101102
}

0 commit comments

Comments
 (0)