vectordotdev/vector · error

non-utf8 path to pod logs dir is not supported

Error message

non-utf8 path to pod logs dir is not supported

What it means

Panic from `Path::to_str()` in the kubernetes_logs source's path provider. Linux paths are byte strings; `to_str()` returns None when the pod logs directory (extracted from the pod spec, e.g. a custom log-dir annotation or hostPath volume mount under the kubelet logs root) contains bytes that are not valid UTF-8. The source asserts every such path is UTF-8 and panics otherwise, killing the kubernetes_logs path-provider iteration.

Source

Thrown at src/sources/kubernetes_logs/k8s_paths_provider.rs:158

        let escaped_container_name = glob::Pattern::escape(container);
        glob::Pattern::new(&[pod_logs_dir, &escaped_container_name, "**"].join("/")).ok()
    })
}

fn list_pod_log_paths<'a, G, GI>(
    mut glob_impl: G,
    pod: &'a Pod,
) -> impl Iterator<Item = PathBuf> + 'a
where
    G: FnMut(&str) -> GI + 'a,
    GI: Iterator<Item = PathBuf> + 'a,
{
    extract_pod_logs_directory(pod)
        .into_iter()
        .flat_map(move |dir| {
            let dir = dir
                .to_str()
                .expect("non-utf8 path to pod logs dir is not supported");

            // Run the glob to get a list of unfiltered paths.
            let path_iter = glob_impl(
                // We seek to match the paths like
                // `<pod_logs_dir>/<container_name>/<n>.log` - paths managed by
                // the `kubelet` as part of Kubernetes core logging
                // architecture.
                // In some setups, there will also be paths like
                // `<pod_logs_dir>/<hash>.log` - those we want to skip.
                &[dir, "*/*.log*"].join("/"),
            );

            // Extract the containers to exclude, then build patterns from them
            // 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();

View on GitHub (pinned to 3708c39b12)

Solutions

  1. Identify the offending pod: audit pod annotations and volume hostPaths for non-UTF-8 values and fix the annotation/mount
  2. Remove the custom log-dir override so the path derives from the ASCII pod UID under /var/log/pods
  3. If embedding: use `to_string_lossy()` or skip the pod with a warning instead of `expect`

Example fix

// before
let dir = dir
    .to_str()
    .expect("non-utf8 path to pod logs dir is not supported");
// after
let Some(dir) = dir.to_str() else {
    warn!(message = "Skipping pod: logs directory is not valid UTF-8.", path = ?dir);
    return Vec::new().into_iter();
};
Defensive patterns

Strategy: validation

Validate before calling

// Rust: audit pod annotations/mounts before enabling kubernetes_logs
let dir = extract_pod_logs_directory(pod);
if let Some(d) = &dir {
    if d.to_str().is_none() {
        warn!(message = "pod logs dir is not UTF-8; pod will panic the source", pod = %pod_uid);
    }
}

Type guard

fn is_utf8_path(path: &std::path::Path) -> bool {
    path.to_str().is_some()
}

Prevention

When it happens

Trigger: `extract_pod_logs_directory(pod)` returns a PathBuf with non-UTF-8 bytes — e.g. a `vector.dev`-style log-dir annotation or a hostPath mount whose value was written in a legacy locale encoding or contains raw binary characters — and `dir.to_str()` returns None.

Common situations: Rare with stock kubelet directories (namespace/pod-uid/container are ASCII); seen with hand-crafted log-dir annotations, hostPath volumes with non-ASCII bytes, or tools that inject locale-encoded (e.g. Latin-1) strings into pod metadata.

Related errors


AI-assisted analysis of vectordotdev/vector@3708c39b12 (2026-08-20). Data as JSON: /api/errors/c1997064d9ce55f1. Report an issue: GitHub.