Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kralicky committed May 10, 2024
1 parent 8444bd2 commit 8cd8fea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
14 changes: 8 additions & 6 deletions pkg/envoy/resource_monitor_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ func (s *sharedResourceMonitor) ApplyBootstrapConfig(bootstrap *envoy_config_boo
}

var (
monitorInitialTickDuration = 1 * time.Second
monitorMaxTickDuration = 5 * time.Second
monitorMinTickDuration = 250 * time.Millisecond
monitorInitialTickDelay = 1 * time.Second
monitorMaxTickInterval = 5 * time.Second
monitorMinTickInterval = 250 * time.Millisecond
)

func (s *sharedResourceMonitor) Run(ctx context.Context, envoyPid int) error {
Expand Down Expand Up @@ -293,7 +293,7 @@ func (s *sharedResourceMonitor) Run(ctx context.Context, envoyPid int) error {

// the envoy default interval for the builtin heap monitor is 1s

tick := time.NewTimer(monitorInitialTickDuration)
tick := time.NewTimer(monitorInitialTickDelay)
var lastValue string
for {
select {
Expand All @@ -312,7 +312,7 @@ func (s *sharedResourceMonitor) Run(ctx context.Context, envoyPid int) error {
}

saturationStr := fmt.Sprintf("%.6f", saturation)
nextInterval := (monitorMaxTickDuration - (time.Duration(float64(monitorMaxTickDuration-monitorMinTickDuration) * saturation))).
nextInterval := (monitorMaxTickInterval - (time.Duration(float64(monitorMaxTickInterval-monitorMinTickInterval) * saturation))).
Round(time.Millisecond)

if saturationStr != lastValue {
Expand Down Expand Up @@ -690,7 +690,9 @@ func (w *memoryLimitWatcher) Watch(ctx context.Context) error {
w.watches.Add(1)
closeWatch := sync.OnceFunc(func() {
log.Debug(ctx).Str("file", w.limitFilePath).Msg("stopping watch")
syscall.InotifyRmWatch(fd, uint32(wd))
if _, err := syscall.InotifyRmWatch(fd, uint32(wd)); err != nil {
log.Error(ctx).Err(err).Msg("failed to remove watch")
}
closeInotify()
w.watches.Done()
})
Expand Down
19 changes: 10 additions & 9 deletions pkg/envoy/resource_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import (
"testing/fstest"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/pomerium/pomerium/config"
"github.com/pomerium/pomerium/config/envoyconfig"
"github.com/pomerium/pomerium/config/envoyconfig/filemgr"
"github.com/pomerium/pomerium/internal/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -549,14 +550,14 @@ func (d *pathOverrideDriver) Path(name string, path CgroupFilePath) string {

func TestSharedResourceMonitor(t *testing.T) {
// set shorter intervals for testing
var prevInitial, prevMin, prevMax time.Duration
monitorInitialTickDuration, prevInitial = 0, monitorInitialTickDuration
monitorMaxTickDuration, prevMax = 100*time.Millisecond, monitorMaxTickDuration
monitorMinTickDuration, prevMin = 10*time.Millisecond, monitorMinTickDuration
var prevInitialDelay, prevMinInterval, prevMaxInterval time.Duration
monitorInitialTickDelay, prevInitialDelay = 0, monitorInitialTickDelay
monitorMaxTickInterval, prevMaxInterval = 100*time.Millisecond, monitorMaxTickInterval
monitorMinTickInterval, prevMinInterval = 10*time.Millisecond, monitorMinTickInterval
t.Cleanup(func() {
monitorInitialTickDuration = prevInitial
monitorMaxTickDuration = prevMax
monitorMinTickDuration = prevMin
monitorInitialTickDelay = prevInitialDelay
monitorMaxTickInterval = prevMaxInterval
monitorMinTickInterval = prevMinInterval
})

testEnvoyPid := 99
Expand Down

0 comments on commit 8cd8fea

Please sign in to comment.