mirror of
https://github.com/moghtech/komodo.git
synced 2026-10-28 00:00:38 +00:00
invert logs
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -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 =
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user