in cmd/apmtelemetrygen/main.go [103:144]
func newRunCmd() *cobra.Command {
options := &runOptions{Headers: make(map[string]string)}
cmd := cobra.Command{
Use: "run",
Short: "Runs the load generator for APM telemetry data",
RunE: func(cmd *cobra.Command, args []string) error {
logger := getLogger(options.Loglevel)
config, err := options.toEventHandlerParams(logger)
if err != nil {
logger.Fatal("Failed to parse flags", zap.Error(err))
}
lg, err := loadgen.NewEventHandler(config)
if err != nil {
logger.Fatal("Failed to create event handler", zap.Error(err))
}
for i := 0; i < options.Iterations; i++ {
if _, err := lg.SendBatches(cmd.Context()); err != nil {
if !options.IgnoreErrors {
return err
}
logger.Error("Failed to send batches", zap.Error(err))
}
}
return nil
},
}
cmd.Flags().Var(headersFlag(options.Headers), "header", "Extra headers to send. Can be specified multiple times")
cmd.Flags().StringVar(&options.ServerURL, "server-url", "", "Server URL (default http://127.0.0.1:8200)")
cmd.Flags().StringVar(&options.SecretToken, "secret-token", "", "Secret token for APM Server. Managed intake service doesn't support secret token")
cmd.Flags().StringVar(&options.APIKey, "api-key", "", "API key to use for authentication")
cmd.Flags().StringVar(&options.Loglevel, "log-level", "debug", "Specify the log level to use when running this command. Supported values: debug, info, warn, error")
cmd.Flags().StringVar(&options.Protocol, "protocol", "apm/http", "Specify the protocol to use when sending events. Supported values: apm/http, otlp/http")
cmd.Flags().StringVar(&options.Datatype, "data-type", "any", "Specify the data type to use when sending events. Supported values: any, logs, metrics, traces")
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
}