Browse Source

flags: add base `collector endpoint` URL

Anton Petruhin 2 năm trước cách đây
mục cha
commit
e68f0610d8
1 tập tin đã thay đổi với 26 bổ sung8 xóa
  1. 26 8
      flags/flags.go

+ 26 - 8
flags/flags.go

@@ -25,14 +25,15 @@ var (
 	LogPerSecond      = kingpin.Flag("log-per-second", "The number of logs per second").Default("10.0").Envar("LOG_PER_SECOND").Float64()
 	LogBurst          = kingpin.Flag("log-burst", "The maximum number of tokens that can be consumed in a single call to allow").Default("100").Envar("LOG_BURST").Int()
 
-	MetricsEndpoint  = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL()
-	TracesEndpoint   = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL()
-	LogsEndpoint     = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL()
-	ProfilesEndpoint = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL()
-	ApiKey           = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String()
-	ScrapeInterval   = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
-
-	WalDir = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String()
+	CollectorEndpoint = kingpin.Flag("collector-endpoint", "A base endpoint URL for metrics, traces, logs, and profiles").Envar("COLLECTOR_ENDPOINT").URL()
+	ApiKey            = kingpin.Flag("api-key", "Coroot API key").Envar("API_KEY").String()
+	MetricsEndpoint   = kingpin.Flag("metrics-endpoint", "The URL of the endpoint to send metrics to").Envar("METRICS_ENDPOINT").URL()
+	TracesEndpoint    = kingpin.Flag("traces-endpoint", "The URL of the endpoint to send traces to").Envar("TRACES_ENDPOINT").URL()
+	LogsEndpoint      = kingpin.Flag("logs-endpoint", "The URL of the endpoint to send logs to").Envar("LOGS_ENDPOINT").URL()
+	ProfilesEndpoint  = kingpin.Flag("profiles-endpoint", "The URL of the endpoint to send profiles to").Envar("PROFILES_ENDPOINT").URL()
+
+	ScrapeInterval = kingpin.Flag("scrape-interval", "How often to gather metrics from the agent").Default("15s").Envar("SCRAPE_INTERVAL").Duration()
+	WalDir         = kingpin.Flag("wal-dir", "Path to where the agent stores data (e.g. the metrics Write-Ahead Log)").Default("/tmp/coroot-node-agent").Envar("WAL_DIR").String()
 )
 
 func GetString(fl *string) string {
@@ -46,6 +47,23 @@ func init() {
 	if strings.HasSuffix(os.Args[0], ".test") {
 		return
 	}
+
 	kingpin.HelpFlag.Short('h').Hidden()
 	kingpin.Parse()
+
+	if *CollectorEndpoint != nil {
+		u := *CollectorEndpoint
+		if *MetricsEndpoint == nil {
+			*MetricsEndpoint = u.JoinPath("/v1/metrics")
+		}
+		if *TracesEndpoint == nil {
+			*TracesEndpoint = u.JoinPath("/v1/traces")
+		}
+		if *LogsEndpoint == nil {
+			*LogsEndpoint = u.JoinPath("/v1/logs")
+		}
+		if *ProfilesEndpoint == nil {
+			*ProfilesEndpoint = u.JoinPath("/v1/profiles")
+		}
+	}
 }