Skip to content

Commit 3910c64

Browse files
feat: adding feature to analyze kube logs in realtime
1 parent 5830ec7 commit 3910c64

1 file changed

Lines changed: 56 additions & 5 deletions

File tree

src/parsing.go

Lines changed: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func ParseIntent(input string) *CommandSuggestion {
262262
}
263263

264264
// Log analysis patterns
265-
if matched, _ := regexp.MatchString(`(analyze|review|check|summarize|inspect).*(logs?|log files?|pod logs?)`, input); matched {
265+
if matched, _ := regexp.MatchString(`(analyze|review|check|summarize|inspect|perform|debug).*(logs?|log files?|pod logs?)`, input); matched {
266266
// Kubernetes pod log analysis
267267
podRe := regexp.MustCompile(`pod\s+([a-zA-Z0-9-]+)`)
268268
nsRe := regexp.MustCompile(`namespace\s+([a-zA-Z0-9-]+)`)
@@ -297,10 +297,61 @@ func ParseIntent(input string) *CommandSuggestion {
297297
}
298298
}
299299

300-
// Log file analysis pattern
301-
fileRe := regexp.MustCompile(`(?:analyze|review|check|summarize|inspect)[^\n]*?(/[^\s]+\.log)`) // non-greedy match for file path
302-
if m := fileRe.FindStringSubmatch(input); len(m) > 1 {
303-
filePath := m[1]
300+
// Kubernetes pod log analysis patterns - more specific
301+
if matched, _ := regexp.MatchString(`(kubectl|k8s|kubernetes).*(logs?|debug|tail|follow)`, input); matched {
302+
// Extract pod name and namespace
303+
podRe := regexp.MustCompile(`pod\s+([a-zA-Z0-9-]+)`)
304+
nsRe := regexp.MustCompile(`namespace\s+([a-zA-Z0-9-]+)`)
305+
pod := ""
306+
ns := "default"
307+
if m := podRe.FindStringSubmatch(input); len(m) > 1 {
308+
pod = m[1]
309+
}
310+
if m := nsRe.FindStringSubmatch(input); len(m) > 1 {
311+
ns = m[1]
312+
}
313+
314+
// If no specific pod mentioned, try to get pods in namespace
315+
if pod == "" {
316+
return &CommandSuggestion{
317+
Tool: "kubectl",
318+
Command: "kubectl get pods -n " + ns,
319+
Description: "List pods in namespace '" + ns + "' to select one for log analysis.",
320+
Intent: "list_pods_for_logs",
321+
Confidence: 0.9,
322+
AIGenerated: false,
323+
HasDryRun: false,
324+
}
325+
}
326+
327+
// Check if real-time/follow is requested
328+
if strings.Contains(input, "realtime") || strings.Contains(input, "follow") || strings.Contains(input, "tail") || strings.Contains(input, "debug") {
329+
return &CommandSuggestion{
330+
Tool: "kubectl",
331+
Command: "kubectl logs " + pod + " -n " + ns + " -f",
332+
Description: "Follow logs in real-time for pod '" + pod + "' in namespace '" + ns + "'.",
333+
Intent: "analyze_logs_realtime",
334+
Confidence: 0.95,
335+
AIGenerated: false,
336+
HasDryRun: false,
337+
}
338+
}
339+
340+
return &CommandSuggestion{
341+
Tool: "kubectl",
342+
Command: "kubectl logs " + pod + " -n " + ns + " --tail=100",
343+
Description: "Fetch and analyze the last 100 log lines for pod '" + pod + "' in namespace '" + ns + "'.",
344+
Intent: "analyze_logs",
345+
Confidence: 0.95,
346+
AIGenerated: false,
347+
HasDryRun: false,
348+
}
349+
}
350+
351+
// Log file analysis pattern - improved to handle more general paths
352+
fileRe := regexp.MustCompile(`(?:analyze|review|check|summarize|inspect|perform|debug)[^\n]*?(from\s+)?(/[^\s]+)`) // non-greedy match for file path
353+
if m := fileRe.FindStringSubmatch(input); len(m) > 2 {
354+
filePath := m[2] // Use the second group which is the actual path
304355
return &CommandSuggestion{
305356
Tool: "system_admin",
306357
Command: "tail -n 100 " + filePath,

0 commit comments

Comments
 (0)