실패 로그 재전송 로직 수정

This commit is contained in:
2025-09-11 19:59:43 +09:00
parent 90faa7d681
commit 289594716c

View File

@ -90,12 +90,26 @@ type singleLogMarshaller struct {
length int
}
type stringSliceReader struct {
type logSliceReader struct {
src []*singleLogMarshaller
cursor int
}
func (b *stringSliceReader) Read(p []byte) (n int, err error) {
func newLogSliceReader(in []singleLogMarshaller) *logSliceReader {
src := make([]*singleLogMarshaller, len(in))
for i, v := range in {
copylog := new(singleLogMarshaller)
*copylog = v
src[i] = copylog
}
return &logSliceReader{
src: src,
cursor: 0,
}
}
func (b *logSliceReader) Read(p []byte) (n int, err error) {
n = 0
err = nil
@ -140,7 +154,7 @@ func (b *stringSliceReader) Read(p []byte) (n int, err error) {
return
}
func (b *stringSliceReader) printSent() {
func (b *logSliceReader) printSent() {
for _, r := range b.src {
fmt.Print(string(r.content))
}
@ -155,11 +169,11 @@ func (c *Client) sendLoop(ctx context.Context) {
}
}()
failChan := make(chan []*singleLogMarshaller)
var logMarshallers []*singleLogMarshaller
failChan := make(chan []singleLogMarshaller)
var logMarshallers []singleLogMarshaller
sendTick := time.After(time.Minute)
sendfunc := func(logs []*singleLogMarshaller) {
sendfunc := func(logs []singleLogMarshaller) {
if len(logs) == 0 {
return
}
@ -171,7 +185,7 @@ func (c *Client) sendLoop(ctx context.Context) {
}
}()
reader := &stringSliceReader{src: logs, cursor: 0}
reader := newLogSliceReader(logs)
req := osapi.BulkReq{
Body: reader,
Header: c.bulkHeader,
@ -218,7 +232,7 @@ func (c *Client) sendLoop(ctx context.Context) {
return
}
var retry []*singleLogMarshaller
var retry []singleLogMarshaller
for i, item := range respbody.Items {
if item.Create.Status < 300 {
continue
@ -246,11 +260,11 @@ func (c *Client) sendLoop(ctx context.Context) {
}
totalsize := 0
appendLog := func(newlog *singleLogMarshaller) bool {
appendLog := func(newlog singleLogMarshaller) bool {
if totalsize+newlog.length > logbulksize {
go sendfunc(logMarshallers)
totalsize = newlog.length
logMarshallers = []*singleLogMarshaller{newlog}
logMarshallers = []singleLogMarshaller{newlog}
return true
}
@ -288,7 +302,7 @@ func (c *Client) sendLoop(ctx context.Context) {
b, _ := json.Marshal(logDoc)
logtype := []byte(logDoc.Type)
if appendLog(&singleLogMarshaller{
if appendLog(singleLogMarshaller{
singleLogPrepend: c.singleLogPrepend,
singleLogMidpend: c.singleLogMidpend,
singleLogAppend: c.singleLogAppend,