feat: support glob pattern matching in collect-on-failure paths#142
feat: support glob pattern matching in collect-on-failure paths#142
Conversation
Allow paths in collect config to use shell glob patterns (*, ?, []) so users can match multiple folders/files flexibly, e.g. /skywalking/logs* or /tmp/*.hprof. Patterns are expanded inside the container via sh before copying. Non-glob paths behave exactly as before. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds shell-style glob expansion for cleanup.collect.on: failure paths, expanding patterns inside the target pod/container before copying files out, so users can collect multiple matching logs/dumps without enumerating them.
Changes:
- Expand glob patterns inside Kind pods via
kubectl exec ... sh -c ...prior tokubectl cp. - Expand glob patterns inside Compose containers via
docker exec ... sh -c ...prior todocker cp. - Add unit tests for
containsGloband no-glob passthrough for the expansion helpers.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| internal/components/collector/kind.go | Adds containsGlob + expandPodGlob and uses them when collecting pod files. |
| internal/components/collector/compose.go | Adds expandContainerGlob and uses it when collecting container files. |
| internal/components/collector/collector_test.go | Adds tests for glob detection and no-glob passthrough behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… handling - Add validateGlobPattern to reject patterns with shell-unsafe characters (prevents shell injection via single quotes, $(), backticks, ;, |, &) - Use `|| true` in sh -c so no-match produces empty stdout instead of non-zero exit, reaching the intended "matched no files" error path - Add `--` to ls to prevent patterns starting with `-` being treated as flags - Add unit tests for pattern validation Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Include stderr in error returns for glob expansion (both Kind/Compose) - Smarter bracket detection: only treat [x] as glob when ] follows [ with content between them, so literal brackets don't trigger glob expansion - Disallow spaces in glob patterns since shell commands are unquoted - Add test cases for bracket edge cases (app[1].log vs app[].log) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cmd := fmt.Sprintf("kubectl --kubeconfig %s -n %s exec %s", kubeConfigPath, namespace, podName) | ||
| if container != "" { | ||
| cmd += fmt.Sprintf(" -c %s", container) | ||
| } | ||
| cmd += fmt.Sprintf(" -- sh -c 'ls -d -- %s 2>/dev/null || true'", pattern) |
There was a problem hiding this comment.
This command is built via string interpolation and executed through util.ExecuteCommand (which runs bash -ec). Only the glob pattern is validated, but kubeConfigPath (and to a lesser extent container) are still unquoted, which can break when paths contain spaces and leaves room for shell-injection if config inputs are attacker-controlled. Also, 2>/dev/null || true suppresses real errors (e.g., permission denied / missing ls) and can incorrectly report “matched no files”; consider a safer expansion approach that distinguishes “no matches” from other failures and avoids shell parsing issues (e.g., robust quoting/escaping or passing args without an outer shell).
Summary
*,?,[]) forpathsin collect-on-failure configsh -c 'ls -d <pattern>'before copyingExample usage
Pattern rules (standard shell glob)
*/tmp/*.hprofmatches/tmp/dump.hprof,/tmp/heap.hprof?/var/log/app-?.logmatchesapp-a.log,app-1.log[...]/var/log/app-[abc].logmatchesapp-a.log,app-b.log,app-c.logTest plan
containsGlobwith various patternsexpandPodGlob/expandContainerGlobpassthrough (no glob)🤖 Generated with Claude Code