Skip to content

Commit

Permalink
resolve issue with promtail not scraping target if only path changed …
Browse files Browse the repository at this point in the history
…in a simpler way that dont need mutex to sync threads (#4599)

Signed-off-by: Roger Steneteg <rsteneteg@ea.com>
  • Loading branch information
rsteneteg authored Nov 3, 2021
1 parent 6319af1 commit 3b66d94
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
8 changes: 0 additions & 8 deletions clients/pkg/promtail/targets/file/filetarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,6 @@ func (t *FileTarget) Stop() {
t.handler.Stop()
}

// UpdatePath updates the filetarget path
// returns true if the path was changed
func (t *FileTarget) UpdatePath(path string) bool {
curPath := t.path
t.path = path
return curPath != path
}

// Type implements a Target
func (t *FileTarget) Type() target.TargetType {
return target.FileTargetType
Expand Down
14 changes: 5 additions & 9 deletions clients/pkg/promtail/targets/file/filetargetmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,12 @@ func (s *targetSyncer) sync(groups []*targetgroup.Group) {
}
}

key := labels.String()
key := fmt.Sprintf("%s:%s", path, labels.String())
targets[key] = struct{}{}
if tgt, ok := s.targets[key]; ok {
if tgt.UpdatePath(string(path)) {
level.Debug(s.log).Log("msg", "updating target, path changed", "labels", labels.String())
} else {
dropped = append(dropped, target.NewDroppedTarget("ignoring target, already exists", discoveredLabels))
level.Debug(s.log).Log("msg", "ignoring target, already exists", "labels", labels.String())
s.metrics.failedTargets.WithLabelValues("exists").Inc()
}
if _, ok := s.targets[key]; ok {
dropped = append(dropped, target.NewDroppedTarget("ignoring target, already exists", discoveredLabels))
level.Debug(s.log).Log("msg", "ignoring target, already exists", "labels", labels.String())
s.metrics.failedTargets.WithLabelValues("exists").Inc()
continue
}

Expand Down

0 comments on commit 3b66d94

Please sign in to comment.