mirror of
https://github.com/prometheus/prometheus
synced 2024-12-25 07:52:28 +00:00
delete empty targets sets to avoid memory leaks
This commit is contained in:
parent
abfd9f1920
commit
cabce21b70
@ -179,8 +179,16 @@ func (m *Manager) allGroups() map[string][]*targetgroup.Group {
|
||||
m.actionCh <- func(ctx context.Context) {
|
||||
tSetsAll := map[string][]*targetgroup.Group{}
|
||||
for pkey, tsets := range m.targets {
|
||||
del := true
|
||||
for _, tg := range tsets {
|
||||
tSetsAll[pkey.setName] = append(tSetsAll[pkey.setName], tg)
|
||||
if len(tg.Targets) != 0 {
|
||||
tSetsAll[pkey.setName] = append(tSetsAll[pkey.setName], tg)
|
||||
del = false
|
||||
}
|
||||
}
|
||||
// Delete the empty map for this target set to avoid memory leaks.
|
||||
if del {
|
||||
delete(m.targets, pkey)
|
||||
}
|
||||
}
|
||||
tSets <- tSetsAll
|
||||
|
@ -649,6 +649,57 @@ func TestDiscoveryManagerSyncCalls(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Single TP update with an empty group to check for memory leaks",
|
||||
updates: map[string][]update{
|
||||
"tp1": {
|
||||
{
|
||||
targetGroups: []targetgroup.Group{
|
||||
{
|
||||
Source: "tp1_group1",
|
||||
Targets: []model.LabelSet{{"__instance__": "1"}},
|
||||
},
|
||||
{
|
||||
Source: "tp1_group2",
|
||||
Targets: []model.LabelSet{{"__instance__": "2"}},
|
||||
},
|
||||
},
|
||||
interval: 30,
|
||||
},
|
||||
{
|
||||
targetGroups: []targetgroup.Group{
|
||||
{
|
||||
Source: "tp1_group1",
|
||||
Targets: []model.LabelSet{{"__instance__": "3"}},
|
||||
},
|
||||
{
|
||||
Source: "tp1_group2",
|
||||
Targets: nil,
|
||||
},
|
||||
},
|
||||
interval: 10,
|
||||
},
|
||||
},
|
||||
},
|
||||
expectedTargets: [][]*targetgroup.Group{
|
||||
{
|
||||
{
|
||||
Source: "tp1_group1",
|
||||
Targets: []model.LabelSet{{"__instance__": "1"}},
|
||||
},
|
||||
{
|
||||
Source: "tp1_group2",
|
||||
Targets: []model.LabelSet{{"__instance__": "2"}},
|
||||
},
|
||||
},
|
||||
{
|
||||
{
|
||||
Source: "tp1_group1",
|
||||
Targets: []model.LabelSet{{"__instance__": "3"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for testIndex, testCase := range testCases {
|
||||
|
Loading…
Reference in New Issue
Block a user