From 2d3beb708e24d7ce9e8a7377c449e7a2c84eb945 Mon Sep 17 00:00:00 2001 From: mbecker20 Date: Sat, 15 Jun 2024 00:28:04 -0700 Subject: [PATCH] invert logs --- bin/core/src/api/read/deployment.rs | 3 ++- bin/periphery/src/api/container.rs | 11 +++++++---- bin/periphery/src/docker/container.rs | 9 +++++++-- client/core/rs/src/api/read/deployment.rs | 6 +++--- client/core/ts/src/types.ts | 2 ++ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/bin/core/src/api/read/deployment.rs b/bin/core/src/api/read/deployment.rs index ca4e300ac..3df26278e 100644 --- a/bin/core/src/api/read/deployment.rs +++ b/bin/core/src/api/read/deployment.rs @@ -121,6 +121,7 @@ impl Resolve for State { deployment, terms, combinator, + invert, }: SearchLog, user: User, ) -> anyhow::Result { @@ -143,7 +144,7 @@ impl Resolve for State { name, terms, combinator, - invert: false, + invert, }) .await .context("failed at call to periphery") diff --git a/bin/periphery/src/api/container.rs b/bin/periphery/src/api/container.rs index cfb652983..93ffaa8e7 100644 --- a/bin/periphery/src/api/container.rs +++ b/bin/periphery/src/api/container.rs @@ -51,14 +51,17 @@ impl Resolve for State { )] async fn resolve( &self, - req: GetContainerLogSearch, + GetContainerLogSearch { + name, + terms, + combinator, + invert, + }: GetContainerLogSearch, _: (), ) -> anyhow::Result { Ok( docker::container::container_log_search( - &req.name, - &req.terms, - req.combinator, + &name, &terms, combinator, invert, ) .await, ) diff --git a/bin/periphery/src/docker/container.rs b/bin/periphery/src/docker/container.rs index 6b0dc817a..bcf11c3ff 100644 --- a/bin/periphery/src/docker/container.rs +++ b/bin/periphery/src/docker/container.rs @@ -27,13 +27,18 @@ pub async fn container_log_search( container_name: &str, terms: &[String], combinator: SearchCombinator, + invert: bool, ) -> Log { + let maybe_invert = invert.then_some(" -v").unwrap_or_default(); let grep = match combinator { SearchCombinator::Or => { - format!("grep -E '{}'", terms.join("|")) + format!("grep{maybe_invert} -E '{}'", terms.join("|")) } SearchCombinator::And => { - format!("grep -P '^(?=.*{})'", terms.join(")(?=.*")) + format!( + "grep{maybe_invert} -P '^(?=.*{})'", + terms.join(")(?=.*") + ) } }; let command = diff --git a/client/core/rs/src/api/read/deployment.rs b/client/core/rs/src/api/read/deployment.rs index 2d8b93889..f287d1ac3 100644 --- a/client/core/rs/src/api/read/deployment.rs +++ b/client/core/rs/src/api/read/deployment.rs @@ -153,9 +153,9 @@ pub struct SearchLog { /// - `OR`: Include lines that have one or more matches in the terms. #[serde(default)] pub combinator: SearchCombinator, - // /// - // #[serde(default)] - // pub invert: bool, + /// Invert the results, ie return all lines that DON'T match the terms / combinator. + #[serde(default)] + pub invert: bool, } #[typeshare] diff --git a/client/core/ts/src/types.ts b/client/core/ts/src/types.ts index df6b88710..38a9a4985 100644 --- a/client/core/ts/src/types.ts +++ b/client/core/ts/src/types.ts @@ -2195,6 +2195,8 @@ export interface SearchLog { * - `OR`: Include lines that have one or more matches in the terms. */ combinator?: SearchCombinator; + /** Invert the results, ie return all lines that DON'T match the terms / combinator. */ + invert?: boolean; } /**