Explorar el Código

Feature #TASK_QT-31635 Q4压缩算法对接环境变量

Carl hace 6 meses
padre
commit
968c290288

+ 1 - 0
flags/flags.go

@@ -60,6 +60,7 @@ var (
 	LogsEndpoint       = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL()
 	ProfilesEndpoint   = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL()
 	InsecureSkipVerify = kingpin.Flag("insecure-skip-verify", "whether to skip verifying the certificate or not").Envar("INSECURE_SKIP_VERIFY").Default("false").Bool()
+	TracesCompression  = kingpin.Flag("traces-compression", "Compression algorithm for traces (none|gzip|zstd)").Envar("TRACES_COMPRESSION").Default("zstd").String()
 
 	ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
 	WalDir         = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String()

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

@@ -127,8 +127,11 @@ func WithEnvCompression(n string, fn func(Compression)) func(e *envconfig.EnvOpt
 	return func(e *envconfig.EnvOptionsReader) {
 		if v, ok := e.GetEnvValue(n); ok {
 			cp := NoCompression
-			if v == "gzip" {
+			switch strings.ToLower(v) {
+			case "gzip":
 				cp = GzipCompression
+			case "zstd":
+				cp = ZstdCompression
 			}
 
 			fn(cp)

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

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

+ 20 - 1
tracing/tracing.go

@@ -4,7 +4,7 @@ import (
 	"context"
 	"crypto/tls"
 	"fmt"
-
+	"strings"
 	"sync"
 	"time"
 
@@ -52,6 +52,25 @@ func Init(machineId, hostname, version string) {
 	if endpointUrl.Scheme != "https" {
 		opts = append(opts, otlptracehttp.WithInsecure())
 	}
+	// 设置压缩算法
+	compressionType := "none"
+	if *flags.TracesCompression != "" {
+		switch strings.ToLower(*flags.TracesCompression) {
+		case "gzip":
+			opts = append(opts, otlptracehttp.WithCompression(otlptracehttp.GzipCompression))
+			compressionType = "gzip"
+		case "zstd":
+			opts = append(opts, otlptracehttp.WithCompression(otlptracehttp.ZstdCompression))
+			compressionType = "zstd"
+		case "none", "":
+			// 默认无压缩,不需要设置
+			compressionType = "none"
+		default:
+			klog.Warnf("Unknown compression algorithm: %s, using default (no compression)", *flags.TracesCompression)
+			compressionType = "none"
+		}
+	}
+	klog.Infof("Traces compression: %s", compressionType)
 	client := otlptracehttp.NewClient(opts...)
 	exporter, err := otlptrace.New(context.Background(), client)
 	if err != nil {