Skip to content

Commit

Permalink
Remove Pyroscope scrape loops for no longer active targets (#7082)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev authored Dec 19, 2024
1 parent c11f0c0 commit 57b5bda
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 @@ -15,6 +15,8 @@ Main (unreleased)
- `loki.source.podlogs`: Fixed a bug which prevented clustering from working and caused duplicate logs to be sent.
The bug only happened when no `selector` or `namespace_selector` blocks were specified in the Agent configuration. (@ptodev)

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

### Enhancements

- Upgrade `github.com/goccy/go-json` to v0.10.4, which reduces the memory consumption of an Agent instance by 20MB.
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 @@ -103,6 +103,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(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 57b5bda

Please sign in to comment.