mirror of
https://gitea.com/gitea/runner.git
synced 2026-11-08 00:00:28 +00:00
enhance(report): add runner.log_report_level for the uploaded runner messages (#1310)
The runner's own messages between steps (not step output) were uploaded to the job log at `log.level`, so raising `log.level` for local debugging also changed what workflow authors see in Gitea, and lowering it hid messages from them. Add `runner.log_report_level` to set that independently. Unset, it still follows `log.level`, so existing setups behave as before. An invalid value is rejected when the config loads. Assisted-by: Codet Assisted-by: Claude Code:claude-opus-5-5 Co-authored-by: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Reviewed-on: https://gitea.com/gitea/runner/pulls/1310 Co-authored-by: Lunny Xiao <[email protected]>
This commit is contained in:
1 parent
42858c61df
commit
9c4c66e70f
6 files changed
+28
-2
No files matched your search
@@ -89,6 +89,7 @@ type Reporter struct {
|
||||
logReportInterval time.Duration
|
||||
logReportMaxLatency time.Duration
|
||||
logBatchSize int
|
||||
logReportLevel logging.Level
|
||||
stateReportInterval time.Duration
|
||||
// closeTimeout bounds each RPC attempt in the final flush, on a context
|
||||
// detached from r.ctx so a server cancel can't abort the acknowledgement.
|
||||
@@ -133,6 +134,7 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
|
||||
logReportInterval: cfg.Runner.LogReportInterval,
|
||||
logReportMaxLatency: cfg.Runner.LogReportMaxLatency,
|
||||
logBatchSize: cfg.Runner.LogReportBatchSize,
|
||||
logReportLevel: logging.GetLevel(),
|
||||
stateReportInterval: cfg.Runner.StateReportInterval,
|
||||
closeTimeout: cfg.Runner.ReportCloseTimeout,
|
||||
logNotify: make(chan struct{}, 1),
|
||||
@@ -146,6 +148,10 @@ func NewReporter(ctx context.Context, cancel context.CancelFunc, client client.C
|
||||
jobLog: openJobLog(cfg.Log.Job, task.Id, time.Now()),
|
||||
}
|
||||
|
||||
if level, err := logging.ParseLevel(cfg.Runner.LogReportLevel); err == nil { // unset keeps log.level
|
||||
rv.logReportLevel = level
|
||||
}
|
||||
|
||||
rv.daemonWait = 6 * rv.effectiveCloseTimeout()
|
||||
|
||||
registerGlobalMasks(rv)
|
||||
@@ -954,9 +960,9 @@ func (r *Reporter) duringSteps() bool {
|
||||
|
||||
// shouldAppendLogRow reports whether a non-raw_output entry should be written
|
||||
// to the job log: only when we are between steps and the entry's level is
|
||||
// within the globally configured log level.
|
||||
// within runner.log_report_level.
|
||||
func (r *Reporter) shouldAppendLogRow(entry logging.Record) bool {
|
||||
return !r.duringSteps() && entry.Level >= logging.GetLevel()
|
||||
return !r.duringSteps() && entry.Level >= r.logReportLevel
|
||||
}
|
||||
|
||||
var stringToResult = map[string]runnerv1.Result{
|
||||
|
||||
@@ -309,7 +309,10 @@ func TestReporter_LogLevelFiltering(t *testing.T) {
|
||||
taskCtx, err := structpb.NewStruct(map[string]any{})
|
||||
require.NoError(t, err)
|
||||
cfg, _ := config.LoadDefault("")
|
||||
cfg.Runner.LogReportLevel = "warn"
|
||||
reporter := NewReporter(ctx, cancel, client, &runnerv1.Task{Context: taskCtx}, cfg)
|
||||
assert.False(t, reporter.shouldAppendLogRow(logging.Record{Level: logging.LevelInfo}))
|
||||
assert.True(t, reporter.shouldAppendLogRow(logging.Record{Level: logging.LevelWarn}))
|
||||
reporter.RunDaemon()
|
||||
defer func() {
|
||||
require.NoError(t, reporter.Close(""))
|
||||
|
||||
Reference in new issue
Block a user