Skip to content

Commit

Permalink
Final suggestions commit
Browse files Browse the repository at this point in the history
  • Loading branch information
samuchila committed Jan 31, 2024
1 parent 5b7365b commit 9aa65ce
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
27 changes: 15 additions & 12 deletions api/src/apps/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use futures::StreamExt;
use http_api_problem::{HttpApiProblem, StatusCode};
use multimap::MultiMap;
use regex::Regex;
use rocket::http::hyper::header::CONTENT_DISPOSITION;
use rocket::http::{RawStr, Status};
use rocket::request::{FromRequest, Outcome, Request};
use rocket::response::stream::{Event, EventStream};
Expand Down Expand Up @@ -221,21 +222,12 @@ async fn logs<'r>(
.get_logs(&app_name, service_name, &since, &limit)
.await?;

let content_disposition = if download {
format!(
"attachment; filename=\"{app_name}_{service_name}_{}.txt\"",
Utc::now().format("%Y%m%d_%H%M%S")
)
} else {
format!("inline")
};

Ok(LogsResponse {
log_chunk,
app_name,
service_name,
limit,
content_disposition,
download,
})
}

Expand Down Expand Up @@ -327,7 +319,7 @@ pub struct LogsResponse<'a> {
app_name: AppName,
service_name: &'a str,
limit: Option<usize>,
content_disposition: String,
download: bool,
}

#[derive(FromForm)]
Expand Down Expand Up @@ -376,10 +368,21 @@ impl<'r> Responder<'r, 'static> for LogsResponse<'r> {
),
};

let content_dispositon_value = if self.download {
format!(
"attachment; filename=\"{}_{}_{}.txt\"",
self.app_name,
self.service_name,
Utc::now().format("%Y%m%d_%H%M%S")
)
} else {
format!("inline")
};

let log_lines = log_chunk.log_lines();
Response::build()
.raw_header("Link", format!("<{}>;rel=next", next_logs_url))
.raw_header("Content-Disposition", self.content_disposition)
.raw_header(CONTENT_DISPOSITION.as_str(), content_dispositon_value)
.sized_body(log_lines.len(), Cursor::new(log_lines.clone()))
.ok()
}
Expand Down
8 changes: 3 additions & 5 deletions api/src/infrastructure/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ impl Infrastructure for DockerInfrastructure {
service_name: &'a str,
from: &'a Option<DateTime<FixedOffset>>,
limit: &'a Option<usize>,
stream: bool,
follow: bool,
) -> BoxStream<'a, Result<(DateTime<FixedOffset>, String), failure::Error>> {
stream! {
match self
Expand All @@ -810,10 +810,8 @@ impl Infrastructure for DockerInfrastructure {
log_options.since(since);
}

if stream {
log_options.follow(true);
}

log_options.follow(follow);

let logs = docker
.containers()
.get(&container.id)
Expand Down
2 changes: 1 addition & 1 deletion api/src/infrastructure/dummy_infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl Infrastructure for DummyInfrastructure {
service_name: &'a str,
_from: &'a Option<DateTime<FixedOffset>>,
_limit: &'a Option<usize>,
_stream: bool,
_follow: bool,
) -> BoxStream<'a, Result<(DateTime<FixedOffset>, String), failure::Error>> {
Box::pin(stream::iter(
vec![
Expand Down
2 changes: 1 addition & 1 deletion api/src/infrastructure/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait Infrastructure: Send + Sync {
service_name: &'a str,
from: &'a Option<DateTime<FixedOffset>>,
limit: &'a Option<usize>,
stream: bool,
follow: bool,
) -> BoxStream<'a, Result<(DateTime<FixedOffset>, String), failure::Error>>;

/// Changes the status of a service, for example, the service might me stopped or started.
Expand Down
4 changes: 2 additions & 2 deletions api/src/infrastructure/kubernetes/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl Infrastructure for KubernetesInfrastructure {
service_name: &'a str,
from: &'a Option<DateTime<FixedOffset>>,
limit: &'a Option<usize>,
stream: bool,
follow: bool,
) -> BoxStream<'a, Result<(DateTime<FixedOffset>, String), failure::Error>> {
let Some((_deployment, Some(pod))) =
(match self.get_deployment_and_pod(app_name, service_name).await {
Expand All @@ -591,7 +591,7 @@ impl Infrastructure for KubernetesInfrastructure {
let p = LogParams {
timestamps: true,
since_time: from.map(|from| from.with_timezone(&Utc)),
follow: stream,
follow,
..Default::default()
};
let client = self.client().await?;
Expand Down

0 comments on commit 9aa65ce

Please sign in to comment.