invert logs

This commit is contained in:
mbecker20
2024-06-15 00:28:04 -07:00
parent 1dc22d01c4
commit 2d3beb708e
5 changed files with 21 additions and 10 deletions
+2 -1
View File
@@ -121,6 +121,7 @@ impl Resolve<SearchLog, User> for State {
deployment,
terms,
combinator,
invert,
}: SearchLog,
user: User,
) -> anyhow::Result<Log> {
@@ -143,7 +144,7 @@ impl Resolve<SearchLog, User> for State {
name,
terms,
combinator,
invert: false,
invert,
})
.await
.context("failed at call to periphery")
+7 -4
View File
@@ -51,14 +51,17 @@ impl Resolve<GetContainerLogSearch> for State {
)]
async fn resolve(
&self,
req: GetContainerLogSearch,
GetContainerLogSearch {
name,
terms,
combinator,
invert,
}: GetContainerLogSearch,
_: (),
) -> anyhow::Result<Log> {
Ok(
docker::container::container_log_search(
&req.name,
&req.terms,
req.combinator,
&name, &terms, combinator, invert,
)
.await,
)
+7 -2
View File
@@ -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 =
+3 -3
View File
@@ -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]
+2
View File
@@ -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;
}
/**