Skip to content

Commit 685476b

Browse files
Neon-Whiteshirady
andcommitted
Implement log analyzer
Co-authored-by: shirady <[email protected]> Signed-off-by: Ben <[email protected]>
1 parent 15f7a29 commit 685476b

File tree

7 files changed

+446
-3
lines changed

7 files changed

+446
-3
lines changed

doc/diagnostic-tools.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
[NooBaa Operator](../README.md) /
2+
# Diagnostic Tools
3+
This document explains and elaborates on the diagnostic tools provided by the NooBaa CLI when the `diagnostics` parameter is used. These tools are designed to help the user get a comprehensive overview of their system's status, as well as troubleshooting problems.
4+
5+
## Log Analysis
6+
The log analyzer (`log-analysis`) lets the user search for strings in the logs of all NooBaa pods and containers, including `--previous` ones. It provides a clear and easy-to-use report with the number of times the searched string was found, alongside the first and last occurrence timestamps to provide an idea of the time window that the searched string applies to.
7+
The first (and only) positional parameter expects to receive the search string; if no positional parameter is provided, the tool will prompt the user to enter the search string.
8+
9+
The analyzer supports several options to allow for more advanced queries:
10+
- `-i, --case-insensitive` - Allows the user to search for a string in a case-insensitive manner (similar to `grep -i`)
11+
- `--fuzzy` - Activates fuzzy-matching, finding matches for any cases where the search string is a subset of a log line (even if not sequentially; e.g. when used with the -i parameter, “s3error” would find “s3 error”, “S3Error”, and “s3-error”)
12+
- `--noobaa-time` - By default, the tool uses Kubernetes timestamps, since in some cases, certain NooBaa log lines may not have timestamps. The NooBaa timestamps are at an offset of 5~20ms from the Kubernetes ones, thus it is recommended to use one type of timestamp consistently.
13+
- `--prefer-line` - When used in conjunction with `--noobaa-time`, will print a log line instead of an error when no timestamp is present in the line
14+
- `--tail` - Tells the tool to fetch only the last N lines of the logs (similar to `minikube logs --tail N`)
15+
- `-v, --verbose` - Prints every matching log line
16+
- `-w, --whole-string` - Activates whole-string matching, yielding results only if the search string appears in a log line while surrounded by non-word characters; e.g. "Reconcile" will match with "BucketClass Reconcile..." but not "ReconcileObject" (similar to `grep -w`)
17+
18+
### Example:
19+
In this example, the tool is used to find case-insensitive, fuzzy occurrences of "s3error" in the last 1,000 lines -
20+
```bash
21+
$ nb diagnostics log-analysis --tail 1000 -i --fuzzy s3error
22+
INFO[0000]
23+
INFO[0000] ✨────────────────────────────────────────────✨
24+
INFO[0000] Collecting and analyzing pod logs -
25+
INFO[0000] Search string: s3error
26+
INFO[0000] Case insensitivity: true
27+
INFO[0000] Match whole string: false
28+
INFO[0000] From the last 1000 lines
29+
INFO[0000] Using Kubernetes timestamps
30+
INFO[0000] Found occurrences will be printed below
31+
INFO[0000] in the format <pod name>:<container name>
32+
INFO[0000] ✨────────────────────────────────────────────✨
33+
INFO[0000] Analyzing noobaa-core-0:core
34+
INFO[0001] Hits: 411
35+
INFO[0001] Earliest appearance: 2024-12-11T09:04:05.245904744Z
36+
INFO[0001] Latest appearance: 2024-12-11T09:11:51.054808004Z
37+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
38+
INFO[0001] Analyzing noobaa-core-0:noobaa-log-processor
39+
INFO[0001] No occurrences found
40+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
41+
INFO[0001] Analyzing noobaa-db-pg-0:db
42+
INFO[0001] No occurrences found
43+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
44+
INFO[0001] Analyzing noobaa-default-backing-store-noobaa-pod-08270bcd:noobaa-agent
45+
INFO[0001] Hits: 111
46+
INFO[0001] Earliest appearance: 2024-12-11T08:36:42.050234365Z
47+
INFO[0001] Latest appearance: 2024-12-11T09:11:20.498970755Z
48+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
49+
INFO[0001] Analyzing noobaa-endpoint-7995576ddc-tq9p4:endpoint
50+
INFO[0001] Hits: 6
51+
INFO[0001] Earliest appearance: 2024-12-11T08:32:04.879477461Z
52+
INFO[0001] Latest appearance: 2024-12-11T08:36:27.793515138Z
53+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
54+
INFO[0001] Analyzing noobaa-operator-68f66b987b-dz4xw:noobaa-operator
55+
INFO[0001] Hits: 10
56+
INFO[0001] Earliest appearance: 2024-12-11T09:10:43.972246776Z
57+
INFO[0001] Latest appearance: 2024-12-11T09:11:50.359484454Z
58+
INFO[0001] ──────────────────────────────────────────────────────────────────────────────────
59+
```
60+
61+
## Resource Analysis
62+
TODO
63+
64+
## Diagnostic Information Collection
65+
TODO
66+
67+
## System Reports
68+
TODO

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/kedacore/keda/v2 v2.7.0
2929
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1
3030
github.com/libopenstorage/secrets v0.0.0-20240416031220-a17cf7f72c6c
31+
github.com/lithammer/fuzzysearch v1.1.8
3132
github.com/marstr/randname v0.0.0-20200428202425-99aca53a2176
3233
github.com/onsi/ginkgo/v2 v2.21.0
3334
github.com/onsi/gomega v1.35.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,8 @@ github.com/libopenstorage/operator v0.0.0-20200725001727-48d03e197117/go.mod h1:
718718
github.com/libopenstorage/stork v1.3.0-beta1.0.20200630005842-9255e7a98775/go.mod h1:qBSzYTJVHlOMg5RINNiHD1kBzlasnrc2uKLPZLgu1Qs=
719719
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
720720
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
721+
github.com/lithammer/fuzzysearch v1.1.8 h1:/HIuJnjHuXS8bKaiTMeeDlW2/AyIWk2brx1V8LFgLN4=
722+
github.com/lithammer/fuzzysearch v1.1.8/go.mod h1:IdqeyBClc3FFqSzYq/MXESsS4S0FsZ5ajtkr5xPLts4=
721723
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
722724
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
723725
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=

pkg/diagnostics/collect.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (c *Collector) CollectPodsLogs(listOptions client.ListOptions) {
140140

141141
c.CollectDescribe("pod", pod.Name)
142142

143-
podLogs, _ := util.GetPodLogs(*pod)
143+
podLogs, _ := util.GetPodLogs(*pod, nil, false)
144144
for containerName, containerLog := range podLogs {
145145
targetFile := fmt.Sprintf("%s/%s-%s.log", c.folderName, pod.Name, containerName)
146146
err := util.SaveStreamToFile(containerLog, targetFile)

pkg/diagnostics/diagnostics.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func Cmd() *cobra.Command {
2525
CmdDbDump(),
2626
CmdAnalyze(),
2727
CmdReport(),
28+
CmdLogAnalysis(),
2829
)
2930
return cmd
3031
}
@@ -123,6 +124,25 @@ func CmdAnalyzeResources() *cobra.Command {
123124
return cmd
124125
}
125126

127+
// CmdLogAnalysis returns a CLI command
128+
func CmdLogAnalysis() *cobra.Command {
129+
cmd := &cobra.Command{
130+
Use: "log-analysis",
131+
Short: "Run the log analyzer on all NooBaa pods",
132+
Run: RunLogAnalysis,
133+
}
134+
cmd.Flags().BoolP("verbose", "v", false, "Print every matching log line")
135+
cmd.Flags().Bool("fuzzy", false, "(Experimental) Toggle fuzzy matching for the search string")
136+
cmd.Flags().Int64("tail", 1000, "Number of lines to tail from the logs, minimum 1, default 1000")
137+
cmd.Flags().BoolP("case-insensitive", "i", false, "Toggle search-string case insensitivity (similar to grep's -i flag)")
138+
cmd.Flags().BoolP("whole-string", "w", false, "Match the whole search string as a single word (similar to grep's -w flag)")
139+
cmd.Flags().Bool("prefer-line", false, "Prefer to print the line containing the search string when it doesn't contain a timestamp")
140+
cmd.Flags().Bool("noobaa-time", false, "Use NooBaa-provided timestamps instead of the Kubernetes ones (~10ms earlier than Kubernetes)")
141+
142+
143+
return cmd
144+
}
145+
126146
/////// Deprecated Functions ///////
127147

128148
// CmdDbDumpDeprecated returns a CLI command

0 commit comments

Comments
 (0)