func Init()

in loadgen/cmd/otelbench/flags.go [74:201]


func Init() error {
	// Server config
	flag.Func(
		"endpoint",
		"target server endpoint for both otlp and otlphttp exporters (default to value in config yaml), equivalent to setting both -endpoint-otlp and -endpoint-otlphttp",
		func(server string) (err error) {
			if server != "" {
				Config.ServerURLOTLP, err = url.Parse(server)
				Config.ServerURLOTLPHTTP = Config.ServerURLOTLP
			}
			return
		})
	flag.Func(
		"endpoint-otlp",
		"target server endpoint for otlp exporter (default to value in config yaml)",
		func(server string) (err error) {
			if server != "" {
				Config.ServerURLOTLP, err = url.Parse(server)
			}
			return
		})
	flag.Func(
		"endpoint-otlphttp",
		"target server endpoint for otlphttp exporter (default to value in config yaml)",
		func(server string) (err error) {
			if server != "" {
				Config.ServerURLOTLPHTTP, err = url.Parse(server)
			}
			return
		})
	flag.StringVar(&Config.SecretToken, "secret-token", "", "secret token for target server")
	flag.StringVar(&Config.APIKey, "api-key", "", "API key for target server")

	flag.BoolVar(&Config.Insecure, "insecure", false, "disable TLS, ignored by otlphttp exporter (default to value in config yaml)")
	flag.BoolVar(&Config.InsecureSkipVerify, "insecure-skip-verify", false, "skip validating the remote server TLS certificates (default to value in config yaml)")

	flag.Func("header",
		"extra headers in key=value format when sending data to the server. Can be repeated. e.g. -header X-FIRST-HEADER=foo -header X-SECOND-HEADER=bar",
		func(s string) error {
			k, v, ok := strings.Cut(s, "=")
			if !ok {
				return fmt.Errorf("invalid header '%s': format must be key=value", s)
			}
			if len(Config.Headers) == 0 {
				Config.Headers = make(map[string]string)
			}
			Config.Headers[k] = v
			return nil
		},
	)

	flag.StringVar(&Config.CollectorConfigPath, "config", "config.yaml", "path to collector config yaml")

	flag.BoolVar(&Config.ExporterOTLP, "exporter-otlp", true, "benchmark exporter otlp")
	flag.BoolVar(&Config.ExporterOTLPHTTP, "exporter-otlphttp", true, "benchmark exporter otlphttp")

	flag.BoolVar(&Config.Logs, "logs", true, "benchmark logs")
	flag.BoolVar(&Config.Metrics, "metrics", true, "benchmark metrics")
	flag.BoolVar(&Config.Traces, "traces", true, "benchmark traces")

	// `concurrency` is similar to `agents` config in apmbench
	// Each value passed into `concurrency` list will be used as loadgenreceiver `concurrency` config
	Config.ConcurrencyList = []int{1} // default
	flag.Func("concurrency", "comma-separated `list` of concurrency (number of simulated agents) to run each benchmark with",
		func(input string) error {
			var concurrencyList []int
			for _, val := range strings.Split(input, ",") {
				val = strings.TrimSpace(val)
				if val == "" {
					continue
				}
				n, err := strconv.Atoi(val)
				if err != nil || n <= 0 {
					return fmt.Errorf("invalid value %q for -concurrency", val)
				}
				concurrencyList = append(concurrencyList, n)
			}
			sort.Ints(concurrencyList)
			Config.ConcurrencyList = concurrencyList
			return nil
		},
	)

	flag.Func("telemetry-elasticsearch-url", "optional comma-separated `list` of remote Elasticsearch telemetry hosts",
		func(input string) error {
			var urls []string
			for _, val := range strings.Split(input, ",") {
				val = strings.TrimSpace(val)
				if val == "" {
					continue
				}
				urls = append(urls, val)
			}
			Config.Telemetry.ElasticsearchURL = urls
			return nil
		},
	)
	flag.StringVar(&Config.Telemetry.ElasticsearchUserName, "telemetry-elasticsearch-username", "", "optional remote Elasticsearch telemetry username")
	flag.StringVar(&Config.Telemetry.ElasticsearchPassword, "telemetry-elasticsearch-password", "", "optional remote Elasticsearch telemetry password")
	flag.StringVar(&Config.Telemetry.ElasticsearchAPIKey, "telemetry-elasticsearch-api-key", "", "optional remote Elasticsearch telemetry API key")
	flag.DurationVar(&Config.Telemetry.ElasticsearchTimeout, "telemetry-elasticsearch-timeout", time.Minute, "optional remote Elasticsearch telemetry request timeout")
	flag.StringVar(&Config.Telemetry.ElasticsearchIndex, "telemetry-elasticsearch-index", "metrics-*", "optional remote Elasticsearch telemetry metrics index pattern")
	flag.StringVar(&Config.Telemetry.FilterClusterName, "telemetry-filter-cluster-name", "", "optional remote Elasticsearch telemetry cluster name metrics filter")
	flag.StringVar(&Config.Telemetry.FilterProjectID, "telemetry-filter-project-id", "", "optional remote Elasticsearch telemetry project id metrics filter")
	flag.Func("telemetry-metrics", "optional comma-separated `list` of remote Elasticsearch telemetry metrics to be reported",
		func(input string) error {
			var m []string
			for _, val := range strings.Split(input, ",") {
				val = strings.TrimSpace(val)
				if val == "" {
					continue
				}
				m = append(m, val)
			}
			Config.Telemetry.Metrics = m
			return nil
		},
	)
	flag.Lookup("telemetry-metrics").DefValue = strings.Join(defaultTelemetryMetrics, ",")
	// Set needs to be done separately since `DefValue` won't set default value for flag.Func.
	if err := flag.Set("telemetry-metrics", strings.Join(defaultTelemetryMetrics, ",")); err != nil {
		return fmt.Errorf(`error setting default flag "telemetry-metrics" value: %w`, err)
	}

	// For configs that can be set via environment variables, set the required
	// flags from env if they are not explicitly provided via command line
	return setFlagsFromEnv()
}