diff --git a/Cargo.lock b/Cargo.lock index 857db741..7ac81c32 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1092,7 +1092,7 @@ dependencies = [ [[package]] name = "kubetui" -version = "1.4.2" +version = "1.5.0" dependencies = [ "anyhow", "arboard", diff --git a/Cargo.toml b/Cargo.toml index a34e00d7..b3877dc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kubetui" -version = "1.4.2" +version = "1.5.0" authors = ["kosay "] edition = "2021" license = "MIT" diff --git a/README.md b/README.md index d5a46281..6ecd652e 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ It provides an easy-to-use interface for developers and operators to access impo - [Installation](#installation) - [Features](#features) - [Usage](#usage) +- [Log Query](#log-query) + - [Usage Example](#usage-example) + - [Supported Queries](#supported-queries) + - [Query String Escaping](#query-string-escaping) - [Key Bindings](#key-bindings) - [General](#general) - [Key Map](#key-map) @@ -26,12 +30,12 @@ It provides an easy-to-use interface for developers and operators to access impo -![Demo](./assets/demo.gif) +![Demo](./assets/demo.webp)
Demo slow version -![Demo slow version](./assets/demo-slow.gif) +![Demo slow version](./assets/demo-slow.webp)
@@ -100,6 +104,116 @@ Options: -s, --split-mode Window split mode [possible values: v, h, vertical, horizontal] ``` +## Log Query + +The Log Query feature empowers you to retrieve logs from multiple Pods and their containers. Using regular expressions, selectors, and specified resources, you can precisely define the log retrieval targets. This functionality also allows you to filter logs using regular expressions, providing a powerful and flexible log querying experience. + +### Usage Example + +``` +pod:app container:nginx log:401 +``` + +When entering `?` or `help` in the log query form, the help popup will be displayed. + +### Supported Queries + +| Query | Alias | Description | +| ------------------- | -------------------- | -------------------------------------------------------------------------------------------------------------- | +| pod:\ | pods, po, p | Include Pods that match the regular expression in log retrieval target. | +| !pod:\ | !pods, !po, !p | Exclude Pods that match the regular expression from log retrieval target. Can be defined multiple times. | +| container:\ | containers, co, c | Include containers that match the regular expression in log retrieval target. | +| !container:\ | !containers, !co, !c | Exclude containers that match the regular expression from log retrieval target. Can be defined multiple times. | +| log:\ | logs, lo, l | Retrieve logs that match the regular expression. Can be defined multiple times. | +| !log:\ | !logs, !lo, !l | Exclude logs that match the regular expression. Can be defined multiple times. | +| label:\ | labels | Include Pods with labels matching the selector in log retrieval target. Cannot be specified with resource. | +| field:\ | fields | Include Pods with fields matching the selector in log retrieval target. | +| \/\ | | Include Pods belonging to the specified resource in log retrieval target. Cannot be specified with label. | + +Supported resources: + +| Resource | Alias | +| ----------- | ------------------- | +| pod | po, pods | +| replicaset | rs, replicasets | +| deployment | deploy, deployments | +| statefulset | sts, statefulsets | +| daemonset | ds, daemonsets | +| job | jobs | +| service | svc, services | + +### Query String Escaping + +When including spaces in queries such as `` or ``, enclose the string with `"` or `'`. For example: + +``` +pod:"a b" +label:"environment in (production, qa)" +``` + +If you use `"`, `'`, or `\` within the quoted string, escape them with `\`. For example: + +``` +pod:"a\\b" +``` + +
+Query Syntax + +``` +**Lexer and Parser** + +LOG_QUERIES = QUERY ( " "+ QUERY )* + +QUERY = POD + | EXCLUDE_POD + | CONTAINER + | EXCLUDE_CONTAINER + | LOG + | EXCLUDE_LOG + | LABEL + | FIELD + | SPECIFIED_RESOURCE + +POD = ( "pods" | "pod" | "po" | "p" ) ":" REGEX +EXCLUDE_POD = "!" POD + +CONTAINER = ( "containers" | "container" | "co" | "c" ) ":" REGEX +EXCLUDE_CONTAINER = "!" CONTAINER + +LOG = ( "logs" | "log" | "lo" | "l" ) ":" REGEX +EXCLUDE_LOG = "!" LOG + +REGEX = QUOTED_STRING | UNQUOTED_STRING + +LABEL = ( "labels" | "label" ) ":" SELECTOR +FIELD = ( "fields" | "field" ) ":" SELECTOR + +SELECTOR = QUOTED_STRING | UNQUOTED_STRING + +SPECIFIED_RESOURCE = RESOURCE "/" NAME + +RESOURCE = ( "pods" | "pod" | "po" ) + | ( "replicasets" | "replicaset" | "rs" ) + | ( "deployments" | "deployment" | "deploy" ) + | ( "statefulsets" | "statefulset" | "sts" ) + | ( "daemonsets" | "daemonset" | "ds" ) + | ( "services" | "service" | "svc" ) + | ( "jobs" | "job" ) + +NAME = ALPHANUMERIC ( ALPHANUMERIC | "-" | "." )* ALPHANUMERIC + +UNQUOTED_STRING = ~['" \t\r\n] ( ~[ \t\r\n] )* // without spaces + +QUOTED_STRING = "\"" ESCAPED_STRING "\"" | "'" ESCAPED_STRING "'" + +ESCAPED_STRING = ( ESCAPED_CHAR | ~[\"'] )\* + +ESCAPED_CHAR = "\\" | "\"" | "\'" +``` + +
+ ## Key Bindings ### General @@ -111,6 +225,7 @@ Options: | n | Open the popup for selecting the namespace | | N | Open the popup for selecting multiple namespaces | | c | Open the popup for selecting the context | +| y | Open the popup for yaml | | Tab, Shift+Tab | Change the focus of the view within the active tab | | number | Switch to the tab (number: 1~6) | | ESC | Close the window or terminate the app (when the popup is not open) | diff --git a/assets/demo-slow.gif b/assets/demo-slow.gif deleted file mode 100755 index 65d9a7c6..00000000 Binary files a/assets/demo-slow.gif and /dev/null differ diff --git a/assets/demo-slow.webp b/assets/demo-slow.webp new file mode 100644 index 00000000..8052af24 Binary files /dev/null and b/assets/demo-slow.webp differ diff --git a/assets/demo.gif b/assets/demo.gif deleted file mode 100644 index 7ae79e2b..00000000 Binary files a/assets/demo.gif and /dev/null differ diff --git a/assets/demo.webp b/assets/demo.webp new file mode 100644 index 00000000..40b6d73c Binary files /dev/null and b/assets/demo.webp differ