Skip to content

Commit 8387138

Browse files
authored
feat(gateway,deployer): add more tracing events (#500)
* feat(deployer): add more tracing events * feat(gateway): add more tracing events
1 parent 489b925 commit 8387138

File tree

5 files changed

+62
-26
lines changed

5 files changed

+62
-26
lines changed

deployer/src/handlers/mod.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use shuttle_common::project::ProjectName;
1919
use shuttle_common::LogItem;
2020
use tower_http::auth::RequireAuthorizationLayer;
2121
use tower_http::trace::TraceLayer;
22-
use tracing::{debug, debug_span, error, field, trace, Span};
22+
use tracing::{debug, debug_span, error, field, instrument, trace, Span};
2323
use tracing_opentelemetry::OpenTelemetrySpanExt;
2424
use uuid::Uuid;
2525

@@ -121,6 +121,7 @@ pub fn make_router(
121121
.layer(Extension(project_name))
122122
}
123123

124+
#[instrument(skip_all)]
124125
async fn list_services(
125126
Extension(persistence): Extension<Persistence>,
126127
) -> Result<Json<Vec<shuttle_common::models::service::Response>>> {
@@ -134,9 +135,10 @@ async fn list_services(
134135
Ok(Json(services))
135136
}
136137

138+
#[instrument(skip(persistence))]
137139
async fn get_service(
138140
Extension(persistence): Extension<Persistence>,
139-
Path((_project_name, service_name)): Path<(String, String)>,
141+
Path((project_name, service_name)): Path<(String, String)>,
140142
) -> Result<Json<shuttle_common::models::service::Detailed>> {
141143
if let Some(service) = persistence.get_service_by_name(&service_name).await? {
142144
let deployments = persistence
@@ -171,10 +173,11 @@ async fn get_service(
171173
}
172174
}
173175

176+
#[instrument(skip_all, fields(%project_name, %service_name))]
174177
async fn get_service_summary(
175178
Extension(persistence): Extension<Persistence>,
176179
Extension(proxy_fqdn): Extension<FQDN>,
177-
Path((_, service_name)): Path<(String, String)>,
180+
Path((project_name, service_name)): Path<(String, String)>,
178181
) -> Result<Json<shuttle_common::models::service::Summary>> {
179182
if let Some(service) = persistence.get_service_by_name(&service_name).await? {
180183
let deployment = persistence
@@ -201,10 +204,11 @@ async fn get_service_summary(
201204
}
202205
}
203206

207+
#[instrument(skip_all, fields(%project_name, %service_name))]
204208
async fn post_service(
205209
Extension(persistence): Extension<Persistence>,
206210
Extension(deployment_manager): Extension<DeploymentManager>,
207-
Path((_project_name, service_name)): Path<(String, String)>,
211+
Path((project_name, service_name)): Path<(String, String)>,
208212
Query(params): Query<HashMap<String, String>>,
209213
mut stream: BodyStream,
210214
) -> Result<Json<shuttle_common::models::deployment::Response>> {
@@ -243,10 +247,11 @@ async fn post_service(
243247
Ok(Json(deployment.into()))
244248
}
245249

250+
#[instrument(skip_all, fields(%project_name, %service_name))]
246251
async fn delete_service(
247252
Extension(persistence): Extension<Persistence>,
248253
Extension(deployment_manager): Extension<DeploymentManager>,
249-
Path((_project_name, service_name)): Path<(String, String)>,
254+
Path((project_name, service_name)): Path<(String, String)>,
250255
) -> Result<Json<shuttle_common::models::service::Detailed>> {
251256
if let Some(service) = persistence.get_service_by_name(&service_name).await? {
252257
let old_deployments = persistence
@@ -285,9 +290,10 @@ async fn delete_service(
285290
}
286291
}
287292

293+
#[instrument(skip_all, fields(%project_name, %deployment_id))]
288294
async fn get_deployment(
289295
Extension(persistence): Extension<Persistence>,
290-
Path((_project_name, deployment_id)): Path<(String, Uuid)>,
296+
Path((project_name, deployment_id)): Path<(String, Uuid)>,
291297
) -> Result<Json<shuttle_common::models::deployment::Response>> {
292298
if let Some(deployment) = persistence.get_deployment(&deployment_id).await? {
293299
Ok(Json(deployment.into()))
@@ -296,10 +302,11 @@ async fn get_deployment(
296302
}
297303
}
298304

305+
#[instrument(skip_all, fields(%project_name, %deployment_id))]
299306
async fn delete_deployment(
300307
Extension(deployment_manager): Extension<DeploymentManager>,
301308
Extension(persistence): Extension<Persistence>,
302-
Path((_project_name, deployment_id)): Path<(String, Uuid)>,
309+
Path((project_name, deployment_id)): Path<(String, Uuid)>,
303310
) -> Result<Json<shuttle_common::models::deployment::Response>> {
304311
if let Some(deployment) = persistence.get_deployment(&deployment_id).await? {
305312
deployment_manager.kill(deployment.id).await;
@@ -310,9 +317,10 @@ async fn delete_deployment(
310317
}
311318
}
312319

320+
#[instrument(skip_all, fields(%project_name, %deployment_id))]
313321
async fn get_logs(
314322
Extension(persistence): Extension<Persistence>,
315-
Path((_project_name, deployment_id)): Path<(String, Uuid)>,
323+
Path((project_name, deployment_id)): Path<(String, Uuid)>,
316324
) -> Result<Json<Vec<LogItem>>> {
317325
if let Some(deployment) = persistence.get_deployment(&deployment_id).await? {
318326
Ok(Json(
@@ -389,9 +397,10 @@ async fn logs_websocket_handler(mut s: WebSocket, persistence: Persistence, id:
389397
let _ = s.close().await;
390398
}
391399

400+
#[instrument(skip_all, fields(%project_name, %service_name))]
392401
async fn get_secrets(
393402
Extension(persistence): Extension<Persistence>,
394-
Path((_project_name, service_name)): Path<(String, String)>,
403+
Path((project_name, service_name)): Path<(String, String)>,
395404
) -> Result<Json<Vec<secret::Response>>> {
396405
if let Some(service) = persistence.get_service_by_name(&service_name).await? {
397406
let keys = persistence

deployer/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ pub async fn start(
3737
args.artifacts_path,
3838
);
3939

40-
for existing_deployment in persistence.get_all_runnable_deployments().await.unwrap() {
40+
let runnable_deployments = persistence.get_all_runnable_deployments().await.unwrap();
41+
info!(count = %runnable_deployments.len(), "enqueuing runnable deployments");
42+
for existing_deployment in runnable_deployments {
4143
let built = Built {
4244
id: existing_deployment.id,
4345
service_name: existing_deployment.service_name,
@@ -56,7 +58,7 @@ pub async fn start(
5658
);
5759
let make_service = router.into_make_service();
5860

59-
info!("Binding to and listening at address: {}", args.api_address);
61+
info!(address=%args.api_address, "Binding to and listening at address");
6062

6163
axum::Server::bind(&args.api_address)
6264
.serve(make_service)

gateway/src/api/latest.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use shuttle_common::models::error::ErrorKind;
2020
use shuttle_common::models::{project, user};
2121
use tokio::sync::mpsc::Sender;
2222
use tower_http::trace::TraceLayer;
23-
use tracing::{debug, debug_span, field, Span};
23+
use tracing::{debug, debug_span, field, instrument, Span};
2424

2525
use crate::acme::{AcmeClient, CustomDomain};
2626
use crate::auth::{Admin, ScopedUser, User};
@@ -65,6 +65,7 @@ impl StatusResponse {
6565
}
6666
}
6767

68+
#[instrument(skip_all, fields(%account_name))]
6869
async fn get_user(
6970
State(RouterState { service, .. }): State<RouterState>,
7071
Path(account_name): Path<AccountName>,
@@ -75,6 +76,7 @@ async fn get_user(
7576
Ok(AxumJson(user.into()))
7677
}
7778

79+
#[instrument(skip_all, fields(%account_name))]
7880
async fn post_user(
7981
State(RouterState { service, .. }): State<RouterState>,
8082
Path(account_name): Path<AccountName>,
@@ -85,6 +87,7 @@ async fn post_user(
8587
Ok(AxumJson(user.into()))
8688
}
8789

90+
#[instrument(skip(service))]
8891
async fn get_project(
8992
State(RouterState { service, .. }): State<RouterState>,
9093
ScopedUser { scope, .. }: ScopedUser,
@@ -98,6 +101,7 @@ async fn get_project(
98101
Ok(AxumJson(response))
99102
}
100103

104+
#[instrument(skip_all, fields(%project))]
101105
async fn post_project(
102106
State(RouterState { service, sender }): State<RouterState>,
103107
User { name, .. }: User,
@@ -121,6 +125,7 @@ async fn post_project(
121125
Ok(AxumJson(response))
122126
}
123127

128+
#[instrument(skip_all, fields(%project))]
124129
async fn delete_project(
125130
State(RouterState { service, sender }): State<RouterState>,
126131
ScopedUser { scope: project, .. }: ScopedUser,
@@ -149,6 +154,7 @@ async fn delete_project(
149154
Ok(AxumJson(response))
150155
}
151156

157+
#[instrument(skip_all, fields(scope = %scoped_user.scope))]
152158
async fn route_project(
153159
State(RouterState { service, .. }): State<RouterState>,
154160
scoped_user: ScopedUser,
@@ -176,6 +182,7 @@ async fn get_status(State(RouterState { sender, .. }): State<RouterState>) -> Re
176182
.unwrap()
177183
}
178184

185+
#[instrument(skip_all)]
179186
async fn revive_projects(
180187
_: Admin,
181188
State(RouterState { service, sender }): State<RouterState>,
@@ -185,6 +192,7 @@ async fn revive_projects(
185192
.map_err(|_| Error::from_kind(ErrorKind::Internal))
186193
}
187194

195+
#[instrument(skip_all, fields(%email, ?acme_server))]
188196
async fn create_acme_account(
189197
_: Admin,
190198
Extension(acme_client): Extension<AcmeClient>,
@@ -196,6 +204,7 @@ async fn create_acme_account(
196204
Ok(AxumJson(res))
197205
}
198206

207+
#[instrument(skip_all, fields(%project_name, %fqdn))]
199208
async fn request_acme_certificate(
200209
_: Admin,
201210
State(RouterState { service, sender }): State<RouterState>,

gateway/src/main.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::io::{self, Cursor};
1919
use std::path::{Path, PathBuf};
2020
use std::sync::Arc;
2121
use std::time::Duration;
22-
use tracing::{debug, error, info, info_span, trace, warn};
22+
use tracing::{debug, error, info, info_span, trace, warn, Instrument};
2323
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
2424

2525
#[tokio::main(flavor = "multi_thread")]
@@ -122,20 +122,26 @@ async fn start(db: SqlitePool, fs: PathBuf, args: StartArgs) -> io::Result<()> {
122122
"running health checks",
123123
healthcheck.num_projects = projects.len()
124124
);
125-
let _ = span.enter();
126-
for (project_name, _) in projects {
127-
if let Ok(handle) = gateway
128-
.new_task()
129-
.project(project_name)
130-
.and_then(task::check_health())
131-
.send(&sender)
132-
.await
133-
{
134-
// we wait for the check to be done before
135-
// queuing up the next one
136-
handle.await
125+
126+
let gateway = gateway.clone();
127+
let sender = sender.clone();
128+
async move {
129+
for (project_name, _) in projects {
130+
if let Ok(handle) = gateway
131+
.new_task()
132+
.project(project_name)
133+
.and_then(task::check_health())
134+
.send(&sender)
135+
.await
136+
{
137+
// we wait for the check to be done before
138+
// queuing up the next one
139+
handle.await
140+
}
137141
}
138142
}
143+
.instrument(span)
144+
.await;
139145
}
140146
}
141147
}

gateway/src/project.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use once_cell::sync::Lazy;
1919
use rand::distributions::{Alphanumeric, DistString};
2020
use serde::{Deserialize, Serialize};
2121
use tokio::time::{self, timeout};
22-
use tracing::{debug, error};
22+
use tracing::{debug, error, instrument};
2323

2424
use crate::{
2525
ContainerSettings, DockerContext, EndState, Error, ErrorKind, IntoTryState, ProjectName,
@@ -276,6 +276,7 @@ where
276276
type Next = Self;
277277
type Error = Infallible;
278278

279+
#[instrument(skip_all, fields(state = %self.state()))]
279280
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
280281
let previous = self.clone();
281282
let previous_state = previous.state();
@@ -557,6 +558,7 @@ where
557558
type Next = ProjectStarting;
558559
type Error = ProjectError;
559560

561+
#[instrument(skip_all)]
560562
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
561563
let container_name = self.container_name(ctx);
562564
let container = ctx
@@ -593,6 +595,7 @@ where
593595
type Next = ProjectStarted;
594596
type Error = ProjectError;
595597

598+
#[instrument(skip_all)]
596599
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
597600
let container_id = self.container.id.as_ref().unwrap();
598601
ctx.docker()
@@ -642,6 +645,7 @@ where
642645
type Next = ProjectReadying;
643646
type Error = ProjectError;
644647

648+
#[instrument(skip_all)]
645649
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
646650
time::sleep(Duration::from_secs(1)).await;
647651

@@ -688,6 +692,7 @@ where
688692
type Next = Self;
689693
type Error = ProjectError;
690694

695+
#[instrument(skip_all)]
691696
async fn next(mut self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
692697
Ok(self)
693698
}
@@ -781,6 +786,7 @@ where
781786

782787
type Error = ProjectError;
783788

789+
#[instrument(skip_all)]
784790
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
785791
let Self { container } = self;
786792
ctx.docker()
@@ -808,6 +814,7 @@ where
808814
type Next = ProjectStarting;
809815
type Error = ProjectError;
810816

817+
#[instrument(skip_all)]
811818
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
812819
let container = self.container;
813820

@@ -860,6 +867,7 @@ where
860867
type Next = ProjectDestroyed;
861868
type Error = ProjectError;
862869

870+
#[instrument(skip_all)]
863871
async fn next(self, ctx: &Ctx) -> Result<Self::Next, Self::Error> {
864872
let container_id = self.container.id.as_ref().unwrap();
865873
ctx.docker()
@@ -895,6 +903,7 @@ where
895903
type Next = ProjectDestroyed;
896904
type Error = ProjectError;
897905

906+
#[instrument(skip_all)]
898907
async fn next(self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
899908
Ok(self)
900909
}
@@ -980,6 +989,7 @@ where
980989
type Next = Self;
981990
type Error = Infallible;
982991

992+
#[instrument(skip_all)]
983993
async fn next(self, _ctx: &Ctx) -> Result<Self::Next, Self::Error> {
984994
Ok(self)
985995
}

0 commit comments

Comments
 (0)