post series concurrency

This commit is contained in:
Ulric Qin 2022-04-14 15:04:23 +08:00
parent 46cd4a21ac
commit e794ca86f3
2 changed files with 9 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package agent
import (
"fmt"
"strings"
"sync"
"time"
"flashcat.cloud/categraf/config"
@ -84,8 +85,13 @@ func postSeries(series []*prompb.TimeSeries) {
return
}
for _, w := range writer.Writers {
w.Write(series)
wg := sync.WaitGroup{}
for key := range writer.Writers {
wg.Add(1)
go func(key string) {
defer wg.Done()
writer.Writers[key].Write(series)
}(key)
}
}

View File

@ -51,7 +51,7 @@ func (w WriterType) Post(req []byte) error {
httpReq.Header.Add("Content-Encoding", "snappy")
httpReq.Header.Set("Content-Type", "application/x-protobuf")
httpReq.Header.Set("User-Agent", "n9e")
httpReq.Header.Set("User-Agent", "categraf")
httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0")
if w.Opts.BasicAuthUser != "" {