Просмотр исходного кода

Fixed #TASK_QT-9810 更新发送数据方式为zstd

rock 1 год назад
Родитель
Сommit
82ef3b5fe0

+ 2 - 2
Makefile2

@@ -17,12 +17,12 @@ build:
 	CGO_ENABLED=1 go build -gcflags="all=-N -l" -buildvcs=false -o euspace
 c:
 	#docker exec -it 9d928d96d4d0 sh -c 'cd /opt/github/euspace/ebpftracer && sh build.sh${PARAMS}'
-	docker exec -it 3c1a4817a7ed sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
+	docker exec -it 0fec3217d6da sh -c 'cd /opt/github/euspace/ebpftracer && make all ${PARAMS}'
 c-build: c
 
 go-build:
 	#ssh [email protected] 'export https_proxy=http://10.0.22.50:4780 && source ~/.g/env && cd /opt/github/euspace && make -f Makefile2 build'
-	docker exec -it 3c1a4817a7ed bash -c 'cd /opt/github/euspace && source ~/.g/env && make -f Makefile2 build'
+	docker exec -it 0fec3217d6da bash -c 'cd /opt/github/euspace && source ~/.g/env && make -f Makefile2 build'
 go: go-build
 
 run:

+ 20 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/client_apm.go

@@ -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

+ 1 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go

@@ -88,6 +88,7 @@ func NewHTTPConfig(opts ...HTTPOption) Config {
 		cfg = opt.ApplyHTTPOption(cfg)
 	}
 	cfg.Traces.URLPath = cleanPath(cfg.Traces.URLPath, DefaultTracesPath)
+	cfg.Traces.Compression = ZstdCompression
 	return cfg
 }
 

+ 1 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go

@@ -38,6 +38,7 @@ const (
 	// GzipCompression tells the driver to send payloads after
 	// compressing them with gzip.
 	GzipCompression
+	ZstdCompression
 )
 
 // Marshaler describes the kind of message format sent to the collector.

+ 1 - 0
pkg/go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp/options.go

@@ -33,6 +33,7 @@ const (
 	// GzipCompression tells the driver to send payloads after
 	// compressing them with gzip.
 	GzipCompression = Compression(otlpconfig.GzipCompression)
+	ZstdCompression = Compression(otlpconfig.ZstdCompression)
 )
 
 // Option applies an option to the HTTP client.