Skip to content

Commit

Permalink
Promtail: Remove noisy error message when cleaning up filesystem watc…
Browse files Browse the repository at this point in the history
…hes which are already removed. (#8086)

**What this PR does / why we need it**:

Promtail will emit an error message when trying to remove filesystem
watches which do not exist, this PR squelches those error messages
thanks to some updates in the underlying fsnotify lib which allow
checking for this exact error.

**Which issue(s) this PR fixes**:
Fixes #3874 

**Special notes for your reviewer**:

**Checklist**
- [x] Reviewed the `CONTRIBUTING.md` guide
- [ ] Documentation added
- [ ] Tests updated
- [ ] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`

Signed-off-by: Edward Welch <edward.welch@grafana.com>
  • Loading branch information
slim-bean committed Jan 11, 2023
1 parent 6fcc4a2 commit f8e582a
Show file tree
Hide file tree
Showing 23 changed files with 9 additions and 2,337 deletions.
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/file/filetarget.go
Expand Up @@ -7,12 +7,12 @@ import (
"time"

"github.com/bmatcuk/doublestar"
"github.com/fsnotify/fsnotify"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
fsnotify "gopkg.in/fsnotify.v1"

"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/client"
Expand Down
2 changes: 1 addition & 1 deletion clients/pkg/promtail/targets/file/filetarget_test.go
Expand Up @@ -9,11 +9,11 @@ import (
"testing"
"time"

"github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.uber.org/atomic"
"gopkg.in/fsnotify.v1"

"github.com/go-kit/log"

Expand Down
7 changes: 5 additions & 2 deletions clients/pkg/promtail/targets/file/filetargetmanager.go
Expand Up @@ -8,16 +8,17 @@ import (
"sync"

"github.com/bmatcuk/doublestar"
"github.com/fsnotify/fsnotify"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/kubernetes"
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/relabel"
"gopkg.in/fsnotify.v1"

"github.com/grafana/loki/clients/pkg/logentry/stages"
"github.com/grafana/loki/clients/pkg/promtail/api"
Expand Down Expand Up @@ -155,7 +156,9 @@ func (tm *FileTargetManager) watchTargetEvents(ctx context.Context) {
}
case fileTargetEventWatchStop:
if err := tm.watcher.Remove(event.path); err != nil {
level.Error(tm.log).Log("msg", " failed to remove directory from watcher", "error", err)
if !errors.Is(err, fsnotify.ErrNonExistentWatch) {
level.Error(tm.log).Log("msg", " failed to remove directory from watcher", "error", err)
}
}
}
case <-ctx.Done():
Expand Down
Expand Up @@ -7,14 +7,14 @@ import (
"testing"
"time"

"github.com/fsnotify/fsnotify"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/go-kit/log"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/discovery"
"github.com/prometheus/prometheus/discovery/targetgroup"
"gopkg.in/fsnotify.v1"

"github.com/grafana/loki/clients/pkg/promtail/api"
"github.com/grafana/loki/clients/pkg/promtail/client/fake"
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Expand Up @@ -106,14 +106,14 @@ require (
google.golang.org/api v0.102.0
google.golang.org/grpc v1.50.1
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
inet.af/netaddr v0.0.0-20211027220019-c74959edd3b6
k8s.io/klog v1.0.0
)

require (
github.com/fsnotify/fsnotify v1.6.0
github.com/heroku/x v0.0.50
github.com/prometheus/alertmanager v0.24.0
github.com/prometheus/common/sigv4 v0.1.0
Expand Down Expand Up @@ -182,7 +182,6 @@ require (
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
github.com/envoyproxy/protoc-gen-validate v0.6.13 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Expand Up @@ -2097,7 +2097,6 @@ gopkg.in/cheggaaa/pb.v1 v1.0.25/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qS
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fatih/pool.v2 v2.0.0/go.mod h1:8xVGeu1/2jr2wm5V9SPuMht2H5AEmf5aFMGSQixtjTY=
gopkg.in/fsnotify.v1 v1.2.1/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/fsnotify/fsnotify.v1 v1.4.7 h1:XNNYLJHt73EyYiCZi6+xjupS9CpvmiDgjPTAjrBlQbo=
gopkg.in/fsnotify/fsnotify.v1 v1.4.7/go.mod h1:Fyux9zXlo4rWoMSIzpn9fDAYjalPqJ/K1qJ27s+7ltE=
Expand Down
5 changes: 0 additions & 5 deletions vendor/gopkg.in/fsnotify.v1/.editorconfig

This file was deleted.

6 changes: 0 additions & 6 deletions vendor/gopkg.in/fsnotify.v1/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions vendor/gopkg.in/fsnotify.v1/.travis.yml

This file was deleted.

52 changes: 0 additions & 52 deletions vendor/gopkg.in/fsnotify.v1/AUTHORS

This file was deleted.

0 comments on commit f8e582a

Please sign in to comment.