Skip to content

Commit

Permalink
Merge branch 'main' into ocb-default-config
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrohling authored Aug 24, 2022
2 parents 7a1a36e + 62d41a8 commit 17f982e
Show file tree
Hide file tree
Showing 19 changed files with 517 additions and 101 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
- Deprecate FlagsStruct types (#5933):
- `MetricDataPointFlagsStruct` -> `MetricDataPointFlags`
- `NewMetricDataPointFlagsStruct` -> `NewMetricDataPointFlags`
- Deprecate builder distribution flags, use configuration. (#5946)

### 💡 Enhancements 💡

Expand All @@ -39,10 +40,13 @@
- Instead of exiting, `ocb` now generates a default Collector when no build configuration is supplied (#5752)
- Added `service.telemetry.traces.propagators` configuration to set propagators for collector's internal spans. (#5572)
- Remove unnecessary duplicate code and allocations for reading enums in JSON. (#5928)
- Add "dist.build_tags" configuration option to support passing go build flags to builder. (#5659)
- Add an AsRaw func on the flags, lots of places to encode these flags. (#5934)

### 🧰 Bug fixes 🧰

- Fix reading scope attributes for trace JSON, remove duplicate code. (#5930)
- otlpjson/trace: skip unknown fields instead of error. (#5931)
- Fix bug in setting the correct collector state after a configuration change event. (#5830)
- Fix json trace unmarshalling for numbers (#5924):
- Accept both string and number for int32/uint32.
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module go.opentelemetry.io/collector/cmd/builder
go 1.18

require (
github.com/knadh/koanf v1.4.2
github.com/knadh/koanf v1.4.3
github.com/spf13/cobra v1.5.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
Expand Down
247 changes: 241 additions & 6 deletions cmd/builder/go.sum

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"

"go.uber.org/zap"
Expand Down Expand Up @@ -52,6 +53,7 @@ type Distribution struct {
OtelColVersion string `mapstructure:"otelcol_version"`
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
BuildTags string `mapstructure:"build_tags"`
}

// Module represents a receiver, exporter, processor or extension for the distribution
Expand Down Expand Up @@ -143,13 +145,13 @@ func parseModules(mods []Module) ([]Module, error) {
mod.Name = parts[len(parts)-1]
}

if strings.HasPrefix(mod.Path, "./") {
path, err := os.Getwd()
// Check if path is empty, otherwise filepath.Abs replaces it with current path ".".
if mod.Path != "" {
var err error
mod.Path, err = filepath.Abs(mod.Path)
if err != nil {
return mods, fmt.Errorf("module has a relative Path element, but we couldn't get the current working dir: %w", err)
return mods, fmt.Errorf("module has a relative \"path\" element, but we couldn't resolve the current working dir: %w", err)
}

mod.Path = fmt.Sprintf("%s/%s", path, mod.Path[2:])
}

parsedModules = append(parsedModules, mod)
Expand Down
7 changes: 6 additions & 1 deletion cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ func Compile(cfg Config) error {
}

cfg.Logger.Info("Compiling")

args := []string{"build", "-ldflags=-s -w", "-trimpath", "-o", cfg.Distribution.Name}
if cfg.Distribution.BuildTags != "" {
args = append(args, "-tags", cfg.Distribution.BuildTags)
}
// #nosec G204
cmd := exec.Command(cfg.Distribution.Go, "build", "-ldflags=-s -w", "-trimpath", "-o", cfg.Distribution.Name)
cmd := exec.Command(cfg.Distribution.Go, args...)
cmd.Dir = cfg.Distribution.OutputPath
if out, err := cmd.CombinedOutput(); err != nil {
return fmt.Errorf("failed to compile the OpenTelemetry Collector distribution: %w. Output: %q", err, out)
Expand Down
21 changes: 21 additions & 0 deletions cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,33 @@ configuration is provided, ocb will generate a default Collector.
// the distribution parameters, which we accept as CLI flags as well
cmd.Flags().BoolVar(&cfg.SkipCompilation, skipCompilationFlag, false, "Whether builder should only generate go code with no compile of the collector (default false)")
cmd.Flags().StringVar(&cfg.Distribution.Name, distributionNameFlag, "otelcol-custom", "The executable name for the OpenTelemetry Collector distribution")
if err := cmd.Flags().MarkDeprecated(distributionNameFlag, "use config distribution::name"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.Description, distributionDescriptionFlag, "Custom OpenTelemetry Collector distribution", "A descriptive name for the OpenTelemetry Collector distribution")
if err := cmd.Flags().MarkDeprecated(distributionDescriptionFlag, "use config distribution::description"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.Version, distributionVersionFlag, "1.0.0", "The version for the OpenTelemetry Collector distribution")
if err := cmd.Flags().MarkDeprecated(distributionVersionFlag, "use config distribution::version"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.OtelColVersion, distributionOtelColVersionFlag, cfg.Distribution.OtelColVersion, "Which version of OpenTelemetry Collector to use as base")
if err := cmd.Flags().MarkDeprecated(distributionOtelColVersionFlag, "use config distribution::otelcol_version"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.OutputPath, distributionOutputPathFlag, cfg.Distribution.OutputPath, "Where to write the resulting files")
if err := cmd.Flags().MarkDeprecated(distributionOutputPathFlag, "use config distribution::output_path"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.Go, distributionGoFlag, "", "The Go binary to use during the compilation phase. Default: go from the PATH")
if err := cmd.Flags().MarkDeprecated(distributionGoFlag, "use config distribution::go"); err != nil {
return nil, err
}
cmd.Flags().StringVar(&cfg.Distribution.Module, distributionModuleFlag, "go.opentelemetry.io/collector/cmd/builder", "The Go module for the new distribution")
if err := cmd.Flags().MarkDeprecated(distributionModuleFlag, "use config distribution::module"); err != nil {
return nil, err
}

// version of this binary
cmd.AddCommand(versionCommand())
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.9 // indirect
github.com/knadh/koanf v1.4.2 // indirect
github.com/knadh/koanf v1.4.3 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
Expand Down
Loading

0 comments on commit 17f982e

Please sign in to comment.