Skip to content

Commit

Permalink
apmtelemetrygen: add rewrite flag (#191)
Browse files Browse the repository at this point in the history
add  -rewrite-ids and -rewrite-timestamps flags, to control
disabling rewriting IDs and Timestamps when replaying
canned data.

Useful for troubleshooting metering issue as it removes
any variance from the output.

By default they are set to true to preserve current behavior.
  • Loading branch information
endorama authored Dec 5, 2024
1 parent c64c3c2 commit 2f611fd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cmd/apmtelemetrygen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ func newRunCmd() *cobra.Command {
cmd.Flags().StringVar(&options.EventRate, "event-rate", "0/s", "Must be in the format <number of events>/<time>. <time> is parsed")
cmd.Flags().IntVar(&options.Iterations, "iterations", 1, "The number of times to replay the canned data for")
cmd.Flags().BoolVar(&options.IgnoreErrors, "ignore-errors", false, "Ignore HTTP errors while sending events")
cmd.Flags().BoolVar(&options.RewriteIDs, "rewrite-ids", true, "Enable or disable rewriting IDs of stored events in ouput.")
cmd.Flags().BoolVar(&options.RewriteTimestamps, "rewrite-timestamps", true, "Enable or disable rewriting timestamps of stored events in ouput.")
return &cmd
}

Expand All @@ -152,6 +154,14 @@ type runOptions struct {
EventRate string
Iterations int
IgnoreErrors bool
// Specific if to rewrite IDs in stored events.
// This allows replaying the data with no variance on event IDs.
// Useful for troubleshooting.
RewriteIDs bool
// Specific if to rewrite timestamps in stored events.
// This allows replaying the data with no variance on event timestamps.
// Useful for troubleshooting.
RewriteTimestamps bool
}

func (opts *runOptions) toEventHandlerParams(logger *zap.Logger) (loadgen.EventHandlerParams, error) {
Expand All @@ -173,8 +183,8 @@ func (opts *runOptions) toEventHandlerParams(logger *zap.Logger) (loadgen.EventH
Limiter: loadgen.GetNewLimiter(burst, interval),
Rand: rand.New(rand.NewSource(time.Now().UnixNano())),

RewriteIDs: true,
RewriteTimestamps: true,
RewriteIDs: opts.RewriteIDs,
RewriteTimestamps: opts.RewriteTimestamps,
}, nil
}

Expand Down

0 comments on commit 2f611fd

Please sign in to comment.