diff --git a/.chloggen/telemetrygen-traces-batch-size-options.yaml b/.chloggen/telemetrygen-traces-batch-size-options.yaml new file mode 100644 index 000000000000..c09da9ee8424 --- /dev/null +++ b/.chloggen/telemetrygen-traces-batch-size-options.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: telemetrygen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds batch option to configure whether to batch traces, and size option to configure minimum size in MB of each trace for load testing. + +# One or more tracking issues related to the change +issues: [9597] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/cmd/telemetrygen/internal/traces/config.go b/cmd/telemetrygen/internal/traces/config.go index 8bd33663ff3b..0579175e1ebf 100644 --- a/cmd/telemetrygen/internal/traces/config.go +++ b/cmd/telemetrygen/internal/traces/config.go @@ -15,6 +15,8 @@ type Config struct { NumTraces int PropagateContext bool ServiceName string + Batch bool + LoadSize int } // Flags registers config flags. @@ -23,4 +25,6 @@ func (c *Config) Flags(fs *pflag.FlagSet) { fs.IntVar(&c.NumTraces, "traces", 1, "Number of traces to generate in each worker (ignored if duration is provided)") fs.BoolVar(&c.PropagateContext, "marshal", false, "Whether to marshal trace context via HTTP headers") fs.StringVar(&c.ServiceName, "service", "telemetrygen", "Service name to use") + fs.BoolVar(&c.Batch, "batch", true, "Whether to batch traces") + fs.IntVar(&c.LoadSize, "size", 0, "Desired minimum size in MB of string data for each trace generated. This can be used to test traces with large payloads, i.e. when testing the OTLP receiver endpoint max receive size.") } diff --git a/cmd/telemetrygen/internal/traces/traces.go b/cmd/telemetrygen/internal/traces/traces.go index 78aaf627d948..5b6011fd6457 100644 --- a/cmd/telemetrygen/internal/traces/traces.go +++ b/cmd/telemetrygen/internal/traces/traces.go @@ -72,13 +72,16 @@ func Start(cfg *Config) error { } }() - ssp := sdktrace.NewBatchSpanProcessor(exp, sdktrace.WithBatchTimeout(time.Second)) - defer func() { - logger.Info("stop the batch span processor") - if tempError := ssp.Shutdown(context.Background()); tempError != nil { - logger.Error("failed to stop the batch span processor", zap.Error(err)) - } - }() + var ssp sdktrace.SpanProcessor + if cfg.Batch { + ssp = sdktrace.NewBatchSpanProcessor(exp, sdktrace.WithBatchTimeout(time.Second)) + defer func() { + logger.Info("stop the batch span processor") + if tempError := ssp.Shutdown(context.Background()); tempError != nil { + logger.Error("failed to stop the batch span processor", zap.Error(err)) + } + }() + } var attributes []attribute.KeyValue // may be overridden by `-otlp-attributes service.name="foo"` @@ -89,7 +92,9 @@ func Start(cfg *Config) error { sdktrace.WithResource(resource.NewWithAttributes(semconv.SchemaURL, attributes...)), ) - tracerProvider.RegisterSpanProcessor(ssp) + if cfg.Batch { + tracerProvider.RegisterSpanProcessor(ssp) + } otel.SetTracerProvider(tracerProvider) if err = Run(cfg, logger); err != nil { @@ -131,6 +136,7 @@ func Run(c *Config, logger *zap.Logger) error { running: running, wg: &wg, logger: logger.With(zap.Int("worker", i)), + loadSize: c.LoadSize, } go w.simulateTraces() diff --git a/cmd/telemetrygen/internal/traces/worker.go b/cmd/telemetrygen/internal/traces/worker.go index d02b34cf384e..4921c8ffd24f 100644 --- a/cmd/telemetrygen/internal/traces/worker.go +++ b/cmd/telemetrygen/internal/traces/worker.go @@ -5,11 +5,13 @@ package traces // import "github.com/open-telemetry/opentelemetry-collector-cont import ( "context" + "fmt" "sync" "sync/atomic" "time" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "go.opentelemetry.io/otel/trace" @@ -25,12 +27,15 @@ type worker struct { limitPerSecond rate.Limit // how many spans per second to generate wg *sync.WaitGroup // notify when done logger *zap.Logger + loadSize int } const ( fakeIP string = "1.2.3.4" fakeSpanDuration = 123 * time.Microsecond + + charactersPerMB = 1024 * 1024 // One character takes up one byte of space, so this number comes from the number of bytes in a megabyte ) func (w worker) simulateTraces() { @@ -44,6 +49,9 @@ func (w worker) simulateTraces() { ), trace.WithSpanKind(trace.SpanKindClient), ) + for j := 0; j < w.loadSize; j++ { + sp.SetAttributes(attribute.String(fmt.Sprintf("load-%v", j), string(make([]byte, charactersPerMB)))) + } childCtx := ctx if w.propagateContext {