Skip to content

Commit 6908de5

Browse files
authored
[cmd/telemetrygen] Add allow failed exports flag (#42136)
#### Description Add --allow-export-failures flag to telemetrygen to continue running when export operations fail (instead of terminating) <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue Fixes #42135
1 parent a6f867b commit 6908de5

File tree

8 files changed

+50
-2
lines changed

8 files changed

+50
-2
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: telemetrygen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add --allow-export-failures flag to telemetrygen to continue running when export operations fail (instead of terminating)
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [42135]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

cmd/telemetrygen/internal/common/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ type Config struct {
8787

8888
// OTLP mTLS configuration
8989
ClientAuth ClientAuth
90+
91+
// Export behavior configuration
92+
AllowExportFailures bool
9093
}
9194

9295
type ClientAuth struct {
@@ -195,6 +198,9 @@ func (c *Config) CommonFlags(fs *pflag.FlagSet) {
195198
fs.BoolVar(&c.ClientAuth.Enabled, "mtls", c.ClientAuth.Enabled, "Whether to require client authentication for mTLS")
196199
fs.StringVar(&c.ClientAuth.ClientCertFile, "client-cert", c.ClientAuth.ClientCertFile, "Client certificate file")
197200
fs.StringVar(&c.ClientAuth.ClientKeyFile, "client-key", c.ClientAuth.ClientKeyFile, "Client private key file")
201+
202+
// Export behavior configuration
203+
fs.BoolVar(&c.AllowExportFailures, "allow-export-failures", c.AllowExportFailures, "Whether to continue running when export operations fail (instead of terminating)")
198204
}
199205

200206
// SetDefaults is here to mirror the defaults for flags above,
@@ -218,4 +224,5 @@ func (c *Config) SetDefaults() {
218224
c.ClientAuth.Enabled = false
219225
c.ClientAuth.ClientCertFile = ""
220226
c.ClientAuth.ClientKeyFile = ""
227+
c.AllowExportFailures = false
221228
}

cmd/telemetrygen/pkg/logs/logs.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error {
8484
index: i,
8585
traceID: c.TraceID,
8686
spanID: c.SpanID,
87+
allowFailures: c.AllowExportFailures,
8788
}
8889
exp, err := expF()
8990
if err != nil {

cmd/telemetrygen/pkg/logs/worker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type worker struct {
3535
index int // worker index
3636
traceID string // traceID string
3737
spanID string // spanID string
38+
allowFailures bool // whether to continue on export failures
3839
}
3940

4041
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
8081
}
8182

8283
if err := exporter.Export(context.Background(), logs); err != nil {
83-
w.logger.Fatal("exporter failed", zap.Error(err))
84+
if w.allowFailures {
85+
w.logger.Error("exporter failed, continuing due to --allow-export-failures", zap.Error(err))
86+
} else {
87+
w.logger.Fatal("exporter failed", zap.Error(err))
88+
}
8489
}
8590

8691
i++

cmd/telemetrygen/pkg/metrics/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func run(c *Config, expF exporterFunc, logger *zap.Logger) error {
8282
logger: logger.With(zap.Int("worker", i)),
8383
index: i,
8484
clock: &realClock{},
85+
allowFailures: c.AllowExportFailures,
8586
}
8687
exp, err := expF()
8788
if err != nil {

cmd/telemetrygen/pkg/metrics/worker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type worker struct {
3333
logger *zap.Logger // logger
3434
index int // worker index
3535
clock Clock // clock
36+
allowFailures bool // whether to continue on export failures
3637
}
3738

3839
// 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
173174
}
174175

175176
if err := exporter.Export(context.Background(), &rm); err != nil {
176-
w.logger.Fatal("exporter failed", zap.Error(err))
177+
if w.allowFailures {
178+
w.logger.Error("exporter failed, continuing due to --allow-export-failures", zap.Error(err))
179+
} else {
180+
w.logger.Fatal("exporter failed", zap.Error(err))
181+
}
177182
}
178183

179184
i++

cmd/telemetrygen/pkg/traces/traces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func run(c *Config, logger *zap.Logger) error {
152152
logger: logger.With(zap.Int("worker", i)),
153153
loadSize: c.LoadSize,
154154
spanDuration: c.SpanDuration,
155+
allowFailures: c.AllowExportFailures,
155156
}
156157

157158
go w.simulateTraces(telemetryAttributes)

cmd/telemetrygen/pkg/traces/worker.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type worker struct {
3535
loadSize int // desired minimum size in MB of string data for each generated trace
3636
spanDuration time.Duration // duration of generated spans
3737
logger *zap.Logger
38+
allowFailures bool // whether to continue on export failures
3839
}
3940

4041
const (

0 commit comments

Comments
 (0)