-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
endpointmanager: fix bpf policy pressure getting stuck.
Currently the policy map pressure metric only updates the map pressure metric when a new pressure value that is higher than the current one is set. This means that the metric can only ever go up, so when maps are shrunk (ex. such as after doing an cilium fqdn cache clean) the metric never goes down. This changes the behavior of the metric to maintain a map of map pressure values. When the trigger is invoked, it iterates all values and finds the max - updating the map_pressure gauge for policymaps to the max value. Endpoints that are shut down have their values removed. Signed-off-by: Tom Hadlaw <tom.hadlaw@isovalent.com>
- Loading branch information
1 parent
904ceb3
commit 28ce005
Showing
4 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright Authors of Cilium | ||
|
||
package endpointmanager | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/cilium/cilium/pkg/endpoint" | ||
) | ||
|
||
func TestPolicyMapPressure(t *testing.T) { | ||
assert := assert.New(t) | ||
policyMapPressureMinInterval = 0 | ||
p := newPolicyMapPressure() | ||
p.gauge = &fakeGague{} | ||
assert.Equal(float64(0), p.gauge.(*fakeGague).lastValue) | ||
p.Update(endpoint.PolicyMapPressureEvent{ | ||
EndpointID: 1, | ||
Value: .5, | ||
}) | ||
assertMetricEq := func(expected float64) { | ||
assert.Eventually(func() bool { | ||
return p.gauge.(*fakeGague).lastValue == expected | ||
}, time.Second, 1*time.Millisecond) | ||
} | ||
assertMetricEq(.5) | ||
p.Update(endpoint.PolicyMapPressureEvent{ | ||
EndpointID: 2, | ||
Value: 1, | ||
}) | ||
assertMetricEq(1) | ||
p.Remove(2) | ||
assertMetricEq(.5) | ||
} | ||
|
||
type fakeGague struct { | ||
lastValue float64 | ||
} | ||
|
||
func (f *fakeGague) Set(value float64) { | ||
f.lastValue = value | ||
} |