From daddd97c432a11f464c365f415facf5c08d419b0 Mon Sep 17 00:00:00 2001 From: Eric McBride Date: Wed, 3 Feb 2021 14:24:23 -0600 Subject: [PATCH 1/3] ignore istio logs --- src/kube.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/kube.rs b/src/kube.rs index 0d83c91..42d1d31 100644 --- a/src/kube.rs +++ b/src/kube.rs @@ -16,11 +16,11 @@ use kube_async::{ config, }; +use futures::future; use futures::stream::StreamExt; use k8s_openapi::api::core::v1::{PodSpec, PodStatus}; use once_cell::sync::OnceCell; use serde_json::Value; -use futures::future; type Pod = Object; @@ -92,7 +92,7 @@ pub struct LogRecorderConfig { /// key to search for in the json, prints out the value. Only single key supported #[structopt(long)] json_key: Option, - + /// Dont follow the logs, but gather all of them at once #[structopt(long)] gather: bool, @@ -147,6 +147,9 @@ async fn run_cmd(pod_info: Vec) -> Result<(), Box record(file, output).await?, None => stdout(log_msg).await?, } - return Ok(()) + return Ok(()); } let mut output = current_pods.log_stream(&pod_info.name, &lp).await?.boxed(); From 375c5747304fe4d8b465e245842d5c5599212625 Mon Sep 17 00:00:00 2001 From: Eric McBride Date: Wed, 3 Feb 2021 18:57:26 -0600 Subject: [PATCH 2/3] add time since flag --- src/kube.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/kube.rs b/src/kube.rs index 42d1d31..8811fa3 100644 --- a/src/kube.rs +++ b/src/kube.rs @@ -1,5 +1,6 @@ use colored::*; use rand::seq::SliceRandom; +use std::time::SystemTime; use tokio::fs::{File, OpenOptions}; use tokio::io::AsyncWriteExt; @@ -96,6 +97,10 @@ pub struct LogRecorderConfig { /// Dont follow the logs, but gather all of them at once #[structopt(long)] gather: bool, + + /// Subtract current time from this number in seconds + #[structopt(long)] + time_since: Option, } impl LogRecorderConfig { @@ -197,6 +202,14 @@ async fn run_individual( if LogRecorderConfig::global().gather { lp.follow = false; lp.pretty = true; + if LogRecorderConfig::global().time_since.is_some() { + let now = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + lp.since_seconds = + Some(now.as_secs() as i64 - LogRecorderConfig::global().time_since.unwrap()); + } + let output = current_pods.log(&pod_info.name, &lp).await?; let log_msg = format!("{}: {:?}\n", &log_prefix, &output); match out_file { From da636349ff006dfdf48100223ba49b389cc92e76 Mon Sep 17 00:00:00 2001 From: Eric McBride Date: Wed, 3 Feb 2021 19:00:15 -0600 Subject: [PATCH 3/3] added env --- src/kube.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kube.rs b/src/kube.rs index 8811fa3..a7bde43 100644 --- a/src/kube.rs +++ b/src/kube.rs @@ -99,7 +99,7 @@ pub struct LogRecorderConfig { gather: bool, /// Subtract current time from this number in seconds - #[structopt(long)] + #[structopt(long, env = "WUFEI_TIME_SINCE")] time_since: Option, }