Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Pyroscope scrape loops for no longer active targets #7082

Merged
merged 1 commit into from
Dec 19, 2024
Merged
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
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
Loading