Skip to content

Commit

Permalink
Remove Pyroscope scrape loops for no longer active targets (#1833)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev authored Oct 7, 2024
1 parent 7a7e3ab commit 239ad18
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Main (unreleased)

- Fixed a bug in `import.git` which caused a `"non-fast-forward update"` error message. (@ptodev)

- `pyroscope.scrape` no longer tries to scrape endpoints which are not active targets anymore. (@wildum @mattdurham @dehaansa @ptodev)

### Other changes

- Small fix in UI stylesheet to fit more content into visible table area. (@defanator)
Expand Down
8 changes: 8 additions & 0 deletions internal/component/pyroscope/scrape/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ func (m *Manager) reload() {
wg.Done()
}(m.targetsGroups[setName], groups)
}

for tgName, sp := range m.targetsGroups {
if _, ok := m.targetSets[tgName]; !ok {
sp.stop()
delete(m.targetsGroups, tgName)
}
}

wg.Wait()
}

Expand Down
5 changes: 5 additions & 0 deletions internal/component/pyroscope/scrape/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import (
"github.com/prometheus/prometheus/discovery/targetgroup"
"github.com/prometheus/prometheus/model/labels"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestManager(t *testing.T) {
defer goleak.VerifyNone(t, goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start"))

reloadInterval = time.Millisecond

m := NewManager(Options{}, pyroscope.AppendableFunc(func(ctx context.Context, labels labels.Labels, samples []*pyroscope.RawSample) error {
Expand Down Expand Up @@ -62,6 +65,8 @@ func TestManager(t *testing.T) {
return len(m.TargetsActive()["group2"]) == 10
}, time.Second, 10*time.Millisecond)

require.Equal(t, 1, len(m.targetsGroups))

for _, ts := range m.targetsGroups {
require.Equal(t, 1*time.Second, ts.config.ScrapeInterval)
}
Expand Down

0 comments on commit 239ad18

Please sign in to comment.