Align runtime profiles with plugin-owned records

This commit is contained in:
npc0-hue
2026-09-02 10:22:14 +08:00
parent 6018d8f0fc
commit a027ca70eb
36 changed files with 234 additions and 1590 deletions
+16 -6
View File
@@ -3,7 +3,9 @@ package service
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"io"
"net/url"
"os"
"path/filepath"
@@ -231,16 +233,24 @@ func readLogSegment(path string) (domain.LogBatchRecord, error) {
defer file.Close()
entries := []domain.LogEntry{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
reader := bufio.NewReader(file)
for {
line, readErr := reader.ReadBytes('\n')
if len(line) == 0 && errors.Is(readErr, io.EOF) {
break
}
var entry domain.LogEntry
if err := json.Unmarshal(scanner.Bytes(), &entry); err != nil {
if err := json.Unmarshal(line, &entry); err != nil {
return domain.LogBatchRecord{}, fmt.Errorf("decode log segment %s: %w", filepath.Base(path), err)
}
entries = append(entries, domain.CopyLogEntry(entry))
}
if err := scanner.Err(); err != nil {
return domain.LogBatchRecord{}, fmt.Errorf("read log segment %s: %w", filepath.Base(path), err)
if readErr == nil {
continue
}
if errors.Is(readErr, io.EOF) {
break
}
return domain.LogBatchRecord{}, fmt.Errorf("read log segment %s: %w", filepath.Base(path), readErr)
}
sort.SliceStable(entries, func(i, j int) bool { return entries[i].Seq < entries[j].Seq })
if len(entries) == 0 {