SearchLog allow for search Or / And the multiple terms

This commit is contained in:
mbecker20
2024-04-12 04:36:10 -07:00
parent 4523f3e112
commit a2d301bfbc
8 changed files with 61 additions and 12 deletions

View File

@@ -130,7 +130,11 @@ impl Resolve<GetLog, User> for State {
impl Resolve<SearchLog, User> for State {
async fn resolve(
&self,
SearchLog { deployment, terms }: SearchLog,
SearchLog {
deployment,
terms,
combinator,
}: SearchLog,
user: User,
) -> anyhow::Result<Log> {
let Deployment {
@@ -148,7 +152,11 @@ impl Resolve<SearchLog, User> for State {
}
let server = Server::get_resource(&server_id).await?;
periphery_client(&server)?
.request(api::container::GetContainerLogSearch { name, terms })
.request(api::container::GetContainerLogSearch {
name,
terms,
combinator,
})
.await
.context("failed at call to periphery")
}

View File

@@ -58,8 +58,12 @@ impl Resolve<GetContainerLogSearch> for State {
_: (),
) -> anyhow::Result<Log> {
Ok(
docker::container::container_log_search(&req.name, &req.terms)
.await,
docker::container::container_log_search(
&req.name,
&req.terms,
req.combinator,
)
.await,
)
}
}

View File

@@ -6,7 +6,7 @@ use monitor_client::entities::{
},
optional_string, to_monitor_name,
update::Log,
EnvironmentVar,
EnvironmentVar, SearchCombinator,
};
use run_command::async_run_command;
use serror::serialize_error_pretty;
@@ -31,11 +31,18 @@ pub async fn container_log(container_name: &str, tail: u64) -> Log {
pub async fn container_log_search(
container_name: &str,
terms: &[String],
combinator: SearchCombinator,
) -> Log {
let command = format!(
"docker logs {container_name} --tail 5000 | grep -E '{}'",
terms.join("|")
);
let grep = match combinator {
SearchCombinator::Or => {
format!("grep -E '{}'", terms.join("|"))
}
SearchCombinator::And => {
format!("grep -P '^(?=.*{})'", terms.join(")(?=.*"))
}
};
let command =
format!("docker logs {container_name} --tail 5000 |& {grep}");
run_monitor_command("get container log grep", command).await
}

View File

@@ -7,9 +7,7 @@ use crate::entities::{
deployment::{
Deployment, DeploymentActionState, DeploymentListItem,
DeploymentQuery, DockerContainerState, DockerContainerStats,
},
update::Log,
I64, U64,
}, update::Log, SearchCombinator, I64, U64
};
use super::MonitorReadRequest;
@@ -104,6 +102,8 @@ pub struct SearchLog {
#[serde(alias = "id", alias = "name")]
pub deployment: String,
pub terms: Vec<String>,
#[serde(default)]
pub combinator: SearchCombinator,
}
#[typeshare]

View File

@@ -379,3 +379,23 @@ pub enum Operation {
UpdateUserPermissions,
UpdateUserPermissionsOnTarget,
}
#[typeshare]
#[derive(
Serialize,
Deserialize,
Debug,
Default,
Display,
EnumString,
PartialEq,
Hash,
Eq,
Clone,
Copy,
)]
pub enum SearchCombinator {
#[default]
Or,
And,
}

View File

@@ -1166,10 +1166,16 @@ export interface GetLog {
tail: U64;
}
export enum SearchCombinator {
Or = "Or",
And = "And",
}
export interface SearchLog {
/** Id or name */
deployment: string;
terms: string[];
combinator?: SearchCombinator;
}
export interface GetDeployedVersion {

View File

@@ -4,6 +4,7 @@ use monitor_client::entities::{
TerminationSignal,
},
update::Log,
SearchCombinator,
};
use resolver_api::derive::Request;
use serde::{Deserialize, Serialize};
@@ -33,6 +34,8 @@ fn default_tail() -> u64 {
pub struct GetContainerLogSearch {
pub name: String,
pub terms: Vec<String>,
#[serde(default)]
pub combinator: SearchCombinator,
}
//

View File

@@ -70,6 +70,7 @@ const DeploymentLogsInner = ({ id }: { id: string }) => {
onKeyDown={(e) => {
if (e.key === "Enter") updateSearch();
}}
className="w-[300px]"
/>
<Button
variant="ghost"