Return step logs strictly in line order (#6999)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
This commit is contained in:
YR Chen
2026-08-14 17:33:47 +02:00
committed by GitHub
co-authored by Claude Opus 5 qwerty287
parent 79489820fa
commit 150fbf0b3c
2 changed files with 36 additions and 1 deletions
+3 -1
View File
@@ -27,9 +27,11 @@ import (
// Too large a value results in `pq: got XX parameters but PostgreSQL only supports 65535 parameters`.
const pgBatchSize = 1000
// LogFind returns the log entries of a step in the order the agent produced
// them, which is the order their line numbers carry.
func (s storage) LogFind(step *model.Step) ([]*model.LogEntry, error) {
var logEntries []*model.LogEntry
return logEntries, s.engine.Asc("id").Where("step_id = ?", step.ID).Find(&logEntries)
return logEntries, s.engine.Asc("line").Where("step_id = ?", step.ID).Find(&logEntries)
}
func (s storage) LogAppend(_ *model.Step, logEntries []*model.LogEntry) error {
+33
View File
@@ -96,3 +96,36 @@ func TestLogAppend(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, _logEntries, len(logEntries)+1)
}
func TestLogFindOrdersByLine(t *testing.T) {
store, closer := newTestStore(t, new(model.Step), new(model.LogEntry))
defer closer()
step := model.Step{
ID: 1,
}
// The first batch is written through a node holding the id cache 4000+,
// the second one through a node holding the lower cache 30+.
assert.NoError(t, store.LogAppend(&step, []*model.LogEntry{
{ID: 4000, StepID: step.ID, Data: []byte("first"), Line: 0, Time: 0},
{ID: 4001, StepID: step.ID, Data: []byte("second"), Line: 1, Time: 10},
}))
assert.NoError(t, store.LogAppend(&step, []*model.LogEntry{
{ID: 30, StepID: step.ID, Data: []byte("third"), Line: 2, Time: 20},
{ID: 31, StepID: step.ID, Data: []byte("fourth"), Line: 3, Time: 30},
}))
logEntries, err := store.LogFind(&step)
assert.NoError(t, err)
lines := make([]int, 0, len(logEntries))
data := make([]string, 0, len(logEntries))
for _, logEntry := range logEntries {
lines = append(lines, logEntry.Line)
data = append(data, string(logEntry.Data))
}
assert.Equal(t, []int{0, 1, 2, 3}, lines)
assert.Equal(t, []string{"first", "second", "third", "fourth"}, data)
}