|
|
@@ -8,6 +8,8 @@ import (
|
|
|
. "github.com/coroot/coroot-node-agent/utils/modelse"
|
|
|
"go.opentelemetry.io/otel"
|
|
|
"go.opentelemetry.io/otel/exporters/otlp/otlptrace"
|
|
|
+ "github.com/klauspost/compress/zstd"
|
|
|
+ klog "github.com/sirupsen/logrus"
|
|
|
"io"
|
|
|
"net/http"
|
|
|
"net/url"
|
|
|
@@ -18,6 +20,7 @@ func (d *client) UploadApmTraces(ctx context.Context, rootData []otlptrace.RootD
|
|
|
//pbRequest := &coltracepb.ExportTraceServiceRequest{
|
|
|
// ResourceSpans: protoSpans,
|
|
|
//}
|
|
|
+ klog.Infoln("enter the UploadApmTraces newApmRequest-----")
|
|
|
rawRequest, err := json.Marshal(rootData)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -26,6 +29,7 @@ func (d *client) UploadApmTraces(ctx context.Context, rootData []otlptrace.RootD
|
|
|
ctx, cancel := d.contextWithStop(ctx)
|
|
|
defer cancel()
|
|
|
mapLen := len(rootData)
|
|
|
+ klog.Infoln("enter the UploadApmTraces newApmRequest")
|
|
|
request, err := d.newApmRequest(rawRequest, mapLen, CodeType(codeType))
|
|
|
if err != nil {
|
|
|
return err
|
|
|
@@ -113,11 +117,15 @@ func (d *client) newApmRequest(body []byte, mapLen int, codeType CodeType) (requ
|
|
|
r.Header.Set("DataCount", strconv.Itoa(mapLen))
|
|
|
|
|
|
req := request{Request: r}
|
|
|
+ // icase := ZstdCompression
|
|
|
switch Compression(d.cfg.Compression) {
|
|
|
+ // switch Compression(icase) {
|
|
|
case NoCompression:
|
|
|
r.ContentLength = (int64)(len(body))
|
|
|
req.bodyReader = bodyReader(body)
|
|
|
+ klog.Infoln("enter the NoCompression newApmRequest")
|
|
|
case GzipCompression:
|
|
|
+ klog.Infoln("enter the GzipCompression newApmRequest")
|
|
|
// Ensure the content length is not used.
|
|
|
r.ContentLength = -1
|
|
|
r.Header.Set("Content-Encoding", "gzip")
|
|
|
@@ -137,6 +145,18 @@ func (d *client) newApmRequest(body []byte, mapLen int, codeType CodeType) (requ
|
|
|
}
|
|
|
|
|
|
req.bodyReader = bodyReader(b.Bytes())
|
|
|
+ case ZstdCompression:
|
|
|
+ klog.Infoln("enter the ZstdCompression newApmRequest")
|
|
|
+ r.ContentLength = -1
|
|
|
+ r.Header.Set("Content-Encoding", "zstd")
|
|
|
+ encoder, err := zstd.NewWriter(nil)
|
|
|
+ if err != nil {
|
|
|
+ return req, err
|
|
|
+ }
|
|
|
+ defer encoder.Close()
|
|
|
+
|
|
|
+ compressedData := encoder.EncodeAll(body, make([]byte, 0, len(body)))
|
|
|
+ req.bodyReader = bodyReader(compressedData)
|
|
|
}
|
|
|
|
|
|
return req, nil
|