Skip to content

Commit 9332d15

Browse files
committed
fix: avoid logging no such process errors for process priority (#14655)
1 parent 0f63510 commit 9332d15

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

agent/agent.go

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,11 +1670,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16701670

16711671
score, niceErr := proc.Niceness(a.syscaller)
16721672
if niceErr != nil && !xerrors.Is(niceErr, os.ErrPermission) {
1673-
debouncer.Warn(ctx, "unable to get proc niceness",
1674-
slog.F("cmd", proc.Cmd()),
1675-
slog.F("pid", proc.PID),
1676-
slog.Error(niceErr),
1677-
)
1673+
if !isNoSuchProcessErr(niceErr) {
1674+
debouncer.Warn(ctx, "unable to get proc niceness",
1675+
slog.F("cmd", proc.Cmd()),
1676+
slog.F("pid", proc.PID),
1677+
slog.Error(niceErr),
1678+
)
1679+
}
1680+
16781681
continue
16791682
}
16801683

@@ -1690,12 +1693,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16901693
if niceErr == nil {
16911694
err := proc.SetNiceness(a.syscaller, niceness)
16921695
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1693-
debouncer.Warn(ctx, "unable to set proc niceness",
1694-
slog.F("cmd", proc.Cmd()),
1695-
slog.F("pid", proc.PID),
1696-
slog.F("niceness", niceness),
1697-
slog.Error(err),
1698-
)
1696+
if !isNoSuchProcessErr(err) {
1697+
debouncer.Warn(ctx, "unable to set proc niceness",
1698+
slog.F("cmd", proc.Cmd()),
1699+
slog.F("pid", proc.PID),
1700+
slog.F("niceness", niceness),
1701+
slog.Error(err),
1702+
)
1703+
}
16991704
}
17001705
}
17011706

@@ -1704,12 +1709,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
17041709
oomScoreStr := strconv.Itoa(oomScore)
17051710
err := afero.WriteFile(a.filesystem, fmt.Sprintf("/proc/%d/oom_score_adj", proc.PID), []byte(oomScoreStr), 0o644)
17061711
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1707-
debouncer.Warn(ctx, "unable to set oom_score_adj",
1708-
slog.F("cmd", proc.Cmd()),
1709-
slog.F("pid", proc.PID),
1710-
slog.F("score", oomScoreStr),
1711-
slog.Error(err),
1712-
)
1712+
if !isNoSuchProcessErr(err) {
1713+
debouncer.Warn(ctx, "unable to set oom_score_adj",
1714+
slog.F("cmd", proc.Cmd()),
1715+
slog.F("pid", proc.PID),
1716+
slog.F("score", oomScoreStr),
1717+
slog.Error(err),
1718+
)
1719+
}
17131720
}
17141721
}
17151722
modProcs = append(modProcs, proc)
@@ -2139,3 +2146,7 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21392146
}
21402147
l.messages[msg] = time.Now()
21412148
}
2149+
2150+
func isNoSuchProcessErr(err error) bool {
2151+
return err != nil && strings.Contains(err.Error(), "no such process")
2152+
}

0 commit comments

Comments
 (0)