forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.go
89 lines (72 loc) · 2.73 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright The OpenTelemetry Authors
// Copyright (c) 2018 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0
//go:generate mdatagen metadata.yaml
package main // import "github.com/open-telemetry/opentelemetry-collector-contrib/telemetrygen/internal/telemetrygen"
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/logs"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/metrics"
"github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen/internal/traces"
)
var (
tracesCfg *traces.Config
metricsCfg *metrics.Config
logsCfg *logs.Config
)
// rootCmd is the root command on which will be run children commands
var rootCmd = &cobra.Command{
Use: "telemetrygen",
Short: "Telemetrygen simulates a client generating traces, metrics, and logs",
Example: "telemetrygen traces\ntelemetrygen metrics\ntelemetrygen logs",
}
// tracesCmd is the command responsible for sending traces
var tracesCmd = &cobra.Command{
Use: "traces",
Short: fmt.Sprintf("Simulates a client generating traces. (Stability level: %s)", metadata.TracesStability),
Example: "telemetrygen traces",
RunE: func(_ *cobra.Command, _ []string) error {
return traces.Start(tracesCfg)
},
}
// metricsCmd is the command responsible for sending metrics
var metricsCmd = &cobra.Command{
Use: "metrics",
Short: fmt.Sprintf("Simulates a client generating metrics. (Stability level: %s)", metadata.MetricsStability),
Example: "telemetrygen metrics",
RunE: func(_ *cobra.Command, _ []string) error {
return metrics.Start(metricsCfg)
},
}
// logsCmd is the command responsible for sending logs
var logsCmd = &cobra.Command{
Use: "logs",
Short: fmt.Sprintf("Simulates a client generating logs. (Stability level: %s)", metadata.LogsStability),
Example: "telemetrygen logs",
RunE: func(_ *cobra.Command, _ []string) error {
return logs.Start(logsCfg)
},
}
func init() {
rootCmd.AddCommand(tracesCmd, metricsCmd, logsCmd)
tracesCfg = new(traces.Config)
tracesCfg.Flags(tracesCmd.Flags())
metricsCfg = new(metrics.Config)
metricsCfg.Flags(metricsCmd.Flags())
logsCfg = new(logs.Config)
logsCfg.Flags(logsCmd.Flags())
// Disabling completion command for end user
// https://github.com/spf13/cobra/blob/master/shell_completions.md
rootCmd.CompletionOptions.DisableDefaultCmd = true
}
// Execute tries to run the input command
func Execute() {
if err := rootCmd.Execute(); err != nil {
// TODO: Uncomment the line below when using Run instead of RunE in the xxxCmd functions
// fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}