Skip to content

Conversation

@kalleep
Copy link
Contributor

@kalleep kalleep commented Dec 19, 2025

PR Description

Update to latest version that supports more complex patterns.

Check Dependency Review and looked through releases. FilepathGlob is a drop in replacement for what we previously used (Glob) so we are fine to update this.

PathMatch had a change in behavior - previously it would accept either / as separator or platform specific separator. As documented in their change we can use filepath.FromSlash too not break this.

Which issue(s) this PR fixes

fixes: #4423

Notes to the Reviewer

PR Checklist

  • Documentation added
  • Tests updated
  • Config converters updated

@kalleep kalleep requested a review from a team as a code owner December 19, 2025 10:02
@github-actions
Copy link
Contributor

github-actions bot commented Dec 19, 2025

🔍 Dependency Review

github.com/bmatcuk/doublestar v1.3.4 -> v4.9.1 — ⚠️ Needs Review

Summary:

  • This is a major upgrade (v1 -> v4). v4 introduces new, split APIs for Unix-style vs OS-native path behavior and changes to separator handling.
  • Your PR already makes the key changes: updating imports to /v4, switching Glob to FilepathGlob, and normalizing the exclude pattern via filepath.FromSlash.
  • One remaining edge: anywhere you pass a pattern that may contain forward slashes (e.g., from config) into FilepathGlob or PathMatch, you should normalize it with filepath.FromSlash(...) to preserve the pre-upgrade behavior on Windows.

Why:

  • v4 differentiates between “path” (always forward-slash) and “filepath” (OS-native separator) APIs:
    • Path-style: doublestar.Match, doublestar.Glob expect forward slashes.
    • Filepath-style: doublestar.PathMatch, doublestar.FilepathGlob use os.PathSeparator.
  • To keep behavior consistent across platforms when user-supplied patterns use forward slashes, normalize those patterns before calling the filepath-style functions.

Relevant upstream notes (from README/CHANGELOG for v4):

  • New API split for path vs filepath semantics.
  • FilepathGlob was introduced to mirror filepath.Glob semantics (uses OS-native separators).
  • When using FilepathGlob/PathMatch with patterns that include /, normalize with filepath.FromSlash(pattern).

Recommended code updates:

  • Normalize any pattern strings that may contain forward slashes before calling the filepath-style APIs.

Code changes to maintain existing behavior:

  • internal/component/local/file_match/watch.go
@@
-   matches, err := doublestar.FilepathGlob(w.getPath())
+   matches, err := doublestar.FilepathGlob(filepath.FromSlash(w.getPath()))
@@
-           if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), m); match {
+           if match, _ := doublestar.PathMatch(filepath.FromSlash(exclude), m); match {
                continue
            }
  • internal/component/loki/source/file/resolver.go
@@
-           matches, err := doublestar.FilepathGlob(targetPath)
+           matches, err := doublestar.FilepathGlob(filepath.FromSlash(targetPath))
            if err != nil {
                level.Error(s.logger).Log("msg", "failed to resolve target", "error", err)
                continue

Additional checks:

  • Search for any other uses of doublestar.FilepathGlob or doublestar.PathMatch and ensure patterns are normalized if they can contain / from user input.
  • If you ever want cross-platform, forward-slash-only patterns, consider the path-style APIs: doublestar.Glob and doublestar.Match.

Notes

  • The indirect entry for github.com/bmatcuk/doublestar/v4 was removed because it is now a direct dependency; no other dependencies were changed in this diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Alloy local.file_match supporting include/exclude multiple path

1 participant