From 92a70f46350a244669574cec7154f9dc2ed9c13b Mon Sep 17 00:00:00 2001 From: Benedikt Bongartz Date: Wed, 20 Sep 2023 09:14:51 +0200 Subject: [PATCH] builder: start the collector with the parsing of featuregates Signed-off-by: Benedikt Bongartz --- cmd/builder/internal/builder/templates/main.go.tmpl | 5 +++++ otelcol/command.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/cmd/builder/internal/builder/templates/main.go.tmpl b/cmd/builder/internal/builder/templates/main.go.tmpl index 2def32ffe0b..bc73cc5582b 100644 --- a/cmd/builder/internal/builder/templates/main.go.tmpl +++ b/cmd/builder/internal/builder/templates/main.go.tmpl @@ -5,11 +5,16 @@ package main import ( "log" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/otelcol" ) func main() { + if err := otelcol.NewCommandFeatureGate().Execute(); err != nil { + log.Fatalf("failed to validate featuregates: %v", err) + } + factories, err := components() if err != nil { log.Fatalf("failed to build components: %v", err) diff --git a/otelcol/command.go b/otelcol/command.go index a9baff305f3..8f5a1772413 100644 --- a/otelcol/command.go +++ b/otelcol/command.go @@ -12,6 +12,14 @@ import ( "go.opentelemetry.io/collector/featuregate" ) +// NewCommandFeatureGate constructs a new cobra.Command used to parse given FeatureGates. +func NewCommandFeatureGate() *cobra.Command { + flagSet := flags(featuregate.GlobalRegistry()) + rootCmd := &cobra.Command{SilenceUsage: true} + rootCmd.Flags().AddGoFlagSet(flagSet) + return rootCmd +} + // NewCommand constructs a new cobra.Command using the given CollectorSettings. func NewCommand(set CollectorSettings) *cobra.Command { flagSet := flags(featuregate.GlobalRegistry())