Skip to content

Commit

Permalink
update builder to fix feature gate initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole committed Mar 30, 2022
1 parent 80f3f08 commit dfa10e4
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
- The `featuregates` were not configured from the "--feature-gates" flag on windows service (#5060)
- Fix Semantic Convention Schema URL definition for 1.5.0 and 1.6.1 versions (#5103)

### 🧰 Bug fixes 🧰

- Fix the use of feature gates within factory initialization. (#4977)

## v0.47.0 Beta

### 🛑 Breaking changes 🛑
Expand Down
43 changes: 31 additions & 12 deletions cmd/builder/internal/builder/templates/main.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,51 @@ package main
import (
"log"

"github.com/spf13/cobra"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/service"
"go.opentelemetry.io/collector/service/featuregate"
)

func main() {
factories, err := components()
if err != nil {
log.Fatalf("failed to build components: %v", err)
}

info := component.BuildInfo{
Command: "{{ .Distribution.Name }}",
Description: "{{ .Distribution.Description }}",
Version: "{{ .Distribution.Version }}",
}

if err := run(service.CollectorSettings{BuildInfo: info, Factories: factories}); err != nil {
log.Fatal(err)
if err := run(service.CollectorSettings{BuildInfo: info}); err != nil {
log.Fatalf("collector server run finished with error: %v", err)
}
}

func runInteractive(params service.CollectorSettings) error {
cmd := service.NewCommand(params)
if err := cmd.Execute(); err != nil {
log.Fatalf("collector server run finished with error: %v", err)
}
return newCommand(params).Execute()
}

return nil
func newCommand(params service.CollectorSettings) *cobra.Command {
cmd := &cobra.Command{
Use: params.BuildInfo.Command,
Version: params.BuildInfo.Version,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
featuregate.Apply(featuregate.GetFlags())
if params.ConfigProvider == nil {
params.ConfigProvider = service.MustNewDefaultConfigProvider(service.GetConfigFlag(), service.GetSetFlag())
}
var err error
params.Factories, err = components()
if err != nil {
return err
}
col, err := service.New(params)
if err != nil {
return err
}
return col.Run(cmd.Context())
},
}
cmd.Flags().AddGoFlagSet(service.Flags())
return cmd
}
26 changes: 24 additions & 2 deletions cmd/builder/internal/builder/templates/main_others.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,27 @@ package main
import "go.opentelemetry.io/collector/service"

func run(params service.CollectorSettings) error {
return runInteractive(params)
}
cmd := &cobra.Command{
Use: params.BuildInfo.Command,
Version: params.BuildInfo.Version,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
service.ApplyFeatureGateFlags()
if params.ConfigProvider == nil {
params.ConfigProvider = service.MustNewDefaultConfigProvider(service.GetConfigFlag(), service.GetSetFlag())
}
var err error
params.Factories, err = components()
if err != nil {
return err
}
col, err := service.New(params)
if err != nil {
return err
}
return col.Run(cmd.Context())
},
}
cmd.Flags().AddGoFlagSet(service.Flags())
return cmd.Execute()
}
5 changes: 5 additions & 0 deletions cmd/builder/internal/builder/templates/main_windows.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ import (
)

func run(params service.CollectorSettings) error {
// Parse all the flags manually.
if err := service.Flags().Parse(os.Args[1:]); err != nil {
return err
}
service.ApplyFeatureGateFlags()
if useInteractiveMode, err := checkUseInteractiveMode(); err != nil {
return err
} else if useInteractiveMode {
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module go.opentelemetry.io/collector/cmd/otelcorecol
go 1.17

require (
github.com/spf13/cobra v1.4.0
github.com/stretchr/testify v1.7.1
go.opentelemetry.io/collector v0.48.0
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9
Expand Down Expand Up @@ -48,7 +49,6 @@ require (
github.com/rs/cors v1.8.2 // indirect
github.com/shirou/gopsutil/v3 v3.22.2 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cobra v1.4.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
Expand Down
43 changes: 31 additions & 12 deletions cmd/otelcorecol/main.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dfa10e4

Please sign in to comment.