Skip to content

Commit 9f49729

Browse files
authored
fix: avoid logging no such process errors for process priority (#14655)
1 parent 33e896d commit 9f49729

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
@@ -1677,11 +1677,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16771677

16781678
score, niceErr := proc.Niceness(a.syscaller)
16791679
if niceErr != nil && !xerrors.Is(niceErr, os.ErrPermission) {
1680-
debouncer.Warn(ctx, "unable to get proc niceness",
1681-
slog.F("cmd", proc.Cmd()),
1682-
slog.F("pid", proc.PID),
1683-
slog.Error(niceErr),
1684-
)
1680+
if !isNoSuchProcessErr(niceErr) {
1681+
debouncer.Warn(ctx, "unable to get proc niceness",
1682+
slog.F("cmd", proc.Cmd()),
1683+
slog.F("pid", proc.PID),
1684+
slog.Error(niceErr),
1685+
)
1686+
}
1687+
16851688
continue
16861689
}
16871690

@@ -1697,12 +1700,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
16971700
if niceErr == nil {
16981701
err := proc.SetNiceness(a.syscaller, niceness)
16991702
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1700-
debouncer.Warn(ctx, "unable to set proc niceness",
1701-
slog.F("cmd", proc.Cmd()),
1702-
slog.F("pid", proc.PID),
1703-
slog.F("niceness", niceness),
1704-
slog.Error(err),
1705-
)
1703+
if !isNoSuchProcessErr(err) {
1704+
debouncer.Warn(ctx, "unable to set proc niceness",
1705+
slog.F("cmd", proc.Cmd()),
1706+
slog.F("pid", proc.PID),
1707+
slog.F("niceness", niceness),
1708+
slog.Error(err),
1709+
)
1710+
}
17061711
}
17071712
}
17081713

@@ -1711,12 +1716,14 @@ func (a *agent) manageProcessPriority(ctx context.Context, debouncer *logDebounc
17111716
oomScoreStr := strconv.Itoa(oomScore)
17121717
err := afero.WriteFile(a.filesystem, fmt.Sprintf("/proc/%d/oom_score_adj", proc.PID), []byte(oomScoreStr), 0o644)
17131718
if err != nil && !xerrors.Is(err, os.ErrPermission) {
1714-
debouncer.Warn(ctx, "unable to set oom_score_adj",
1715-
slog.F("cmd", proc.Cmd()),
1716-
slog.F("pid", proc.PID),
1717-
slog.F("score", oomScoreStr),
1718-
slog.Error(err),
1719-
)
1719+
if !isNoSuchProcessErr(err) {
1720+
debouncer.Warn(ctx, "unable to set oom_score_adj",
1721+
slog.F("cmd", proc.Cmd()),
1722+
slog.F("pid", proc.PID),
1723+
slog.F("score", oomScoreStr),
1724+
slog.Error(err),
1725+
)
1726+
}
17201727
}
17211728
}
17221729
modProcs = append(modProcs, proc)
@@ -2146,3 +2153,7 @@ func (l *logDebouncer) log(ctx context.Context, level slog.Level, msg string, fi
21462153
}
21472154
l.messages[msg] = time.Now()
21482155
}
2156+
2157+
func isNoSuchProcessErr(err error) bool {
2158+
return err != nil && strings.Contains(err.Error(), "no such process")
2159+
}

0 commit comments

Comments
 (0)