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