Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand All @@ -16,15 +16,15 @@ jobs:
strategy:
fail-fast: false
matrix:
flags: [ '', '-race' ]
flags: ["", "-race"]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: "1.24"
cache: true

- name: Build
Expand All @@ -35,7 +35,21 @@ jobs:
GOFLAGS: ${{ matrix.flags }}
LOG_LEVEL: error
run: |
go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -v -coverpkg=./... ./... -json | tee test-report${{ matrix.flags }}.json
go test -coverprofile=profile${{ matrix.flags }}.out -covermode=atomic -coverpkg=./... ./... -json 2>&1 | tee test-report${{ matrix.flags }}.json
TEST_EXIT_CODE=${PIPESTATUS[0]}
exit $TEST_EXIT_CODE

- name: Fix Test Report
if: always()
run: |
if [ -f test-report${{ matrix.flags }}.json ]; then
# Add final event if missing
if ! tail -1 test-report${{ matrix.flags }}.json | grep -q '"Action":"end"'; then
echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' >> test-report${{ matrix.flags }}.json
fi
else
echo '{"Time":"'$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")'","Action":"end","Package":".","Elapsed":0}' > test-report${{ matrix.flags }}.json
fi

- name: Coverage report
run: |
Expand Down Expand Up @@ -82,15 +96,15 @@ jobs:
strategy:
fail-fast: false
matrix:
flags: [ '', '-race' ]
flags: ["", "-race"]
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: "1.24"
cache: true

- name: Run docker containers
Expand All @@ -101,7 +115,9 @@ jobs:
GOFLAGS: ${{ matrix.flags }}
LOG_LEVEL: error
run: |
go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json | tee test-report-e2e${{ matrix.flags }}.json
go test ./e2e -coverprofile=profile-e2e${{ matrix.flags }}.out -covermode=atomic -tags=e2e_new -timeout=3m -coverpkg=./... -json 2>&1 | tee test-report-e2e${{ matrix.flags }}.json
TEST_EXIT_CODE=${PIPESTATUS[0]}
exit $TEST_EXIT_CODE

- name: Coverage report
run: |
Expand All @@ -110,7 +126,7 @@ jobs:
else
echo "No coverage data generated for ${{ matrix.flags }} tests" > coverage-e2e${{ matrix.flags }}.html
fi

- name: Upload test artifacts
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -161,7 +177,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: "1.24"
cache: true

- name: Lint
Expand All @@ -186,7 +202,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: "1.24"
cache: true

- name: Generate doc
Expand All @@ -210,7 +226,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: "1.24"
cache: true

- name: Download dependencies
Expand Down
2 changes: 1 addition & 1 deletion plugin/input/file/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (w *watcher) notify(e notify.Event, path string) {
return
}

w.logger.Infof("notify %s %s", e, path)
w.logger.Debugf("notify %s %s", e, path)

for _, pattern := range w.paths.Exclude {
match, err := doublestar.PathMatch(pattern, path)
Expand Down
21 changes: 12 additions & 9 deletions plugin/input/file/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"

Expand Down Expand Up @@ -32,7 +33,9 @@ func TestWatcher(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
dir := t.TempDir()
shouldCreate := atomic.Int64{}
var wg sync.WaitGroup
notifyFn := func(_ notify.Event, _ string, _ os.FileInfo) {
defer wg.Done()
shouldCreate.Inc()
}
ctl := metric.NewCtl("test", prometheus.NewRegistry())
Expand Down Expand Up @@ -67,8 +70,7 @@ func TestWatcher(t *testing.T) {
require.NoError(t, err)
err = f2.Close()
require.NoError(t, err)

time.Sleep(10 * time.Millisecond)
wg.Add(1)

f1, err = os.OpenFile(f1Name, os.O_WRONLY, 0o600)
require.NoError(t, err)
Expand All @@ -77,13 +79,11 @@ func TestWatcher(t *testing.T) {
err = f1.Close()
require.NoError(t, err)

time.Sleep(10 * time.Millisecond)

err = os.Remove(f1Name)
require.NoError(t, err)
wg.Add(1)

time.Sleep(10 * time.Millisecond)

wg.Wait()
require.Equal(t, int64(2), shouldCreate.Load())
})
}
Expand Down Expand Up @@ -193,7 +193,10 @@ func TestWatcherPaths(t *testing.T) {

time.Sleep(10 * time.Millisecond)
before := shouldCreate.Load()
w.notify(notify.Create, filename)

resolvedFilename, err := resolvePathLinks(filename)
require.NoError(t, err)
w.notify(notify.Create, resolvedFilename)
after := shouldCreate.Load()

isNotified := after-before != 0
Expand All @@ -216,9 +219,9 @@ func TestCommonPathPrefix(t *testing.T) {

func TestResolvePathLinks(t *testing.T) {
a := assert.New(t)
originalDir := t.TempDir()
originalDir, _ := resolvePathLinks(t.TempDir())

dirWithLink := t.TempDir()
dirWithLink, _ := resolvePathLinks(t.TempDir())
dirLink := filepath.Join(dirWithLink, "symlink")
err := os.Symlink(originalDir, dirLink)
if err != nil {
Expand Down
Loading