vectordotdev/vector · error
the pattern is supposed to always be correct
Error message
the pattern is supposed to always be correct
What it means
Panic from `glob::glob_with(...)` returning a `PatternError`. The pattern is built as `[dir, "*/*.log*"].join("/")`, and glob treats `[`, `]`, `{`, `}`, `*`, `?` as syntax. If the directory portion contains unbalanced or reserved glob metacharacters, the pattern fails to parse and `expect("the pattern is supposed to always be correct")` aborts the kubernetes_logs path provider.
Source
Thrown at src/sources/kubernetes_logs/k8s_paths_provider.rs:190
// and cache the results into a Vec.
let excluded_containers = extract_excluded_containers_for_pod(pod);
let exclusion_patterns: Vec<_> =
build_container_exclusion_patterns(dir, excluded_containers).collect();
// Return paths filtered with container exclusion.
filter_paths(path_iter, exclusion_patterns, false)
})
}
fn real_glob(pattern: &str) -> impl Iterator<Item = PathBuf> + use<> {
glob::glob_with(
pattern,
glob::MatchOptions {
require_literal_separator: true,
..Default::default()
},
)
.expect("the pattern is supposed to always be correct")
.flat_map(|paths| paths.into_iter())
}
fn filter_paths<'a>(
iter: impl Iterator<Item = PathBuf> + 'a,
patterns: impl AsRef<[glob::Pattern]> + 'a,
include: bool,
) -> impl Iterator<Item = PathBuf> + 'a {
iter.filter(move |path| {
let m = patterns.as_ref().iter().any(|pattern| {
pattern.matches_path_with(
path,
glob::MatchOptions {
require_literal_separator: true,
..Default::default()
},
)
});View on GitHub (pinned to 3708c39b12)
Solutions
- Remove glob metacharacters (`* ? [ ] { }`) from the custom pod logs directory path or annotation
- If embedding: escape the directory with `glob::Pattern::escape(dir)` before joining the wildcard suffix
- Upgrade Vector / patch the provider to handle PatternError as a skipped pod instead of a panic
Example fix
// before
let path_iter = glob_impl(&[dir, "*/*.log*"].join("/"));
// after
let pattern = [glob::Pattern::escape(dir), "*/*.log*".to_owned()].join("/");
let path_iter = glob_impl(&pattern); Defensive patterns
Strategy: validation
Validate before calling
// Rust: pre-flight the pattern before handing it to glob
let pattern = [dir, "*/*.log*"].join("/");
if glob::Pattern::new(&pattern).is_err() {
warn!(message = "pod logs dir contains glob metacharacters", dir);
} Type guard
fn glob_safe(dir: &str) -> bool {
glob::Pattern::new(&[dir, "*/*.log*"].join("/")).is_ok()
} Prevention
- Escape directory segments with glob::Pattern::escape before appending wildcards
- Avoid `* ? [ ] { }` in any operator-supplied path that feeds a glob
- Unit-test path providers with adversarial directory names
When it happens
Trigger: A pod logs directory containing glob metacharacters — e.g. an annotation or hostPath like `/data/pods[1]/logs` or `/var/log/{app}/pod` — which makes the joined pattern `<dir>/*/*.log*` unparseable by the glob crate.
Common situations: Custom log-directory annotations using shell-glob-style names (`{...}`, `[...]`, stray `*`). Stock kubelet directories never contain these characters, so this fires only with operator-supplied paths.
Related errors
- non-utf8 path to pod logs dir is not supported
- all json-file keys should be matched
- failed to read glob pattern
- not a valid path
- global log_schema.message_key to be valid path
AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20).
Data as JSON: /api/errors/b1b71d6214763a38.
Report an issue: GitHub.