diff --git a/.chloggen/telemetrygen_allow_failed.yaml b/.chloggen/telemetrygen_allow_failed.yaml new file mode 100644 index 0000000000000..2fc9bd724141e --- /dev/null +++ b/.chloggen/telemetrygen_allow_failed.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# 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: Add --allow-export-failures flag to telemetrygen to continue running when export operations fail (instead of terminating) + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [42135] + +# (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: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] diff --git a/cmd/telemetrygen/internal/common/config.go b/cmd/telemetrygen/internal/common/config.go index 9e03a4045adb3..f9a436e79fa70 100644 --- a/cmd/telemetrygen/internal/common/config.go +++ b/cmd/telemetrygen/internal/common/config.go @@ -87,6 +87,9 @@ type Config struct { // OTLP mTLS configuration ClientAuth ClientAuth + + // Export behavior configuration + AllowExportFailures bool } type ClientAuth struct { @@ -195,6 +198,9 @@ func (c *Config) CommonFlags(fs *pflag.FlagSet) { fs.BoolVar(&c.ClientAuth.Enabled, "mtls", c.ClientAuth.Enabled, "Whether to require client authentication for mTLS") fs.StringVar(&c.ClientAuth.ClientCertFile, "client-cert", c.ClientAuth.ClientCertFile, "Client certificate file") fs.StringVar(&c.ClientAuth.ClientKeyFile, "client-key", c.ClientAuth.ClientKeyFile, "Client private key file") + + // Export behavior configuration + fs.BoolVar(&c.AllowExportFailures, "allow-export-failures", c.AllowExportFailures, "Whether to continue running when export operations fail (instead of terminating)") } // SetDefaults is here to mirror the defaults for flags above, @@ -218,4 +224,5 @@ func (c *Config) SetDefaults() { c.ClientAuth.Enabled = false c.ClientAuth.ClientCertFile = "" c.ClientAuth.ClientKeyFile = "" + c.AllowExportFailures = false } diff --git a/cmd/telemetrygen/pkg/logs/logs.go b/cmd/telemetrygen/pkg/logs/logs.go index 24d8c2a29f436..2b5af9bf0bbec 100644 --- a/cmd/telemetrygen/pkg/logs/logs.go +++ b/cmd/telemetrygen/pkg/logs/logs.go @@ -84,6 +84,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error { index: i, traceID: c.TraceID, spanID: c.SpanID, + allowFailures: c.AllowExportFailures, } exp, err := expF() if err != nil { diff --git a/cmd/telemetrygen/pkg/logs/worker.go b/cmd/telemetrygen/pkg/logs/worker.go index 5de019e099ca0..c16ce6f61edff 100644 --- a/cmd/telemetrygen/pkg/logs/worker.go +++ b/cmd/telemetrygen/pkg/logs/worker.go @@ -35,6 +35,7 @@ type worker struct { index int // worker index traceID string // traceID string spanID string // spanID string + allowFailures bool // whether to continue on export failures } func (w worker) simulateLogs(res *resource.Resource, exporter sdklog.Exporter, telemetryAttributes []attribute.KeyValue) { @@ -80,7 +81,11 @@ func (w worker) simulateLogs(res *resource.Resource, exporter sdklog.Exporter, t } if err := exporter.Export(context.Background(), logs); err != nil { - w.logger.Fatal("exporter failed", zap.Error(err)) + if w.allowFailures { + w.logger.Error("exporter failed, continuing due to --allow-export-failures", zap.Error(err)) + } else { + w.logger.Fatal("exporter failed", zap.Error(err)) + } } i++ diff --git a/cmd/telemetrygen/pkg/metrics/metrics.go b/cmd/telemetrygen/pkg/metrics/metrics.go index 1fa809c88c5bb..503f9770fa664 100644 --- a/cmd/telemetrygen/pkg/metrics/metrics.go +++ b/cmd/telemetrygen/pkg/metrics/metrics.go @@ -82,6 +82,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error { logger: logger.With(zap.Int("worker", i)), index: i, clock: &realClock{}, + allowFailures: c.AllowExportFailures, } exp, err := expF() if err != nil { diff --git a/cmd/telemetrygen/pkg/metrics/worker.go b/cmd/telemetrygen/pkg/metrics/worker.go index 69f3850199556..5da27fec88827 100644 --- a/cmd/telemetrygen/pkg/metrics/worker.go +++ b/cmd/telemetrygen/pkg/metrics/worker.go @@ -33,6 +33,7 @@ type worker struct { logger *zap.Logger // logger index int // worker index clock Clock // clock + allowFailures bool // whether to continue on export failures } // We use a 15-element bounds slice for histograms below, so there must be 16 buckets here. @@ -173,7 +174,11 @@ func (w worker) simulateMetrics(res *resource.Resource, exporter sdkmetric.Expor } if err := exporter.Export(context.Background(), &rm); err != nil { - w.logger.Fatal("exporter failed", zap.Error(err)) + if w.allowFailures { + w.logger.Error("exporter failed, continuing due to --allow-export-failures", zap.Error(err)) + } else { + w.logger.Fatal("exporter failed", zap.Error(err)) + } } i++ diff --git a/cmd/telemetrygen/pkg/traces/traces.go b/cmd/telemetrygen/pkg/traces/traces.go index 1756db53aa122..933d16cb8801c 100644 --- a/cmd/telemetrygen/pkg/traces/traces.go +++ b/cmd/telemetrygen/pkg/traces/traces.go @@ -152,6 +152,7 @@ func run(c *Config, logger *zap.Logger) error { logger: logger.With(zap.Int("worker", i)), loadSize: c.LoadSize, spanDuration: c.SpanDuration, + allowFailures: c.AllowExportFailures, } go w.simulateTraces(telemetryAttributes) diff --git a/cmd/telemetrygen/pkg/traces/worker.go b/cmd/telemetrygen/pkg/traces/worker.go index 108fb9bd9c8ed..2a0213a97bbcf 100644 --- a/cmd/telemetrygen/pkg/traces/worker.go +++ b/cmd/telemetrygen/pkg/traces/worker.go @@ -35,6 +35,7 @@ type worker struct { loadSize int // desired minimum size in MB of string data for each generated trace spanDuration time.Duration // duration of generated spans logger *zap.Logger + allowFailures bool // whether to continue on export failures } const (