Skip to content

Commit

Permalink
Remove reprecated flags from Builder (#11576)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Oct 31, 2024
1 parent 0204d95 commit cd6bfbb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 59 deletions.
26 changes: 26 additions & 0 deletions .chloggen/rm-dep-flags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'breaking'

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: 'builder'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Remove deprecated flags from Builder

# One or more tracking issues or pull requests related to the change
issues: [11576]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: Here is the list of flags |
--name, --description, --version, --otelcol-version, --go, --module

# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user, api]
70 changes: 15 additions & 55 deletions cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,13 @@ import (
)

const (
skipGenerateFlag = "skip-generate"
skipCompilationFlag = "skip-compilation"
skipGetModulesFlag = "skip-get-modules"
skipStrictVersioningFlag = "skip-strict-versioning"
ldflagsFlag = "ldflags"
distributionNameFlag = "name"
distributionDescriptionFlag = "description"
distributionVersionFlag = "version"
distributionOtelColVersionFlag = "otelcol-version"
distributionOutputPathFlag = "output-path"
distributionGoFlag = "go"
distributionModuleFlag = "module"
verboseFlag = "verbose"
skipGenerateFlag = "skip-generate"
skipCompilationFlag = "skip-compilation"
skipGetModulesFlag = "skip-get-modules"
skipStrictVersioningFlag = "skip-strict-versioning"
ldflagsFlag = "ldflags"
distributionOutputPathFlag = "output-path"
verboseFlag = "verbose"
)

var (
Expand Down Expand Up @@ -83,34 +77,10 @@ configuration is provided, ocb will generate a default Collector.
cmd.Flags().BoolVar(&cfg.SkipStrictVersioning, skipStrictVersioningFlag, true, "Whether builder should skip strictly checking the calculated versions following dependency resolution")
cmd.Flags().BoolVar(&cfg.Verbose, verboseFlag, false, "Whether builder should print verbose output (default false)")
cmd.Flags().StringVar(&cfg.LDFlags, ldflagsFlag, "", `ldflags to include in the "go build" command`)
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 Expand Up @@ -184,27 +154,17 @@ func applyCfgFromFile(flags *flag.FlagSet, cfgFromFile builder.Config) {
if !flags.Changed(skipStrictVersioningFlag) && cfgFromFile.SkipStrictVersioning {
cfg.SkipStrictVersioning = cfgFromFile.SkipStrictVersioning
}
if !flags.Changed(distributionNameFlag) && cfgFromFile.Distribution.Name != "" {
cfg.Distribution.Name = cfgFromFile.Distribution.Name
}
if !flags.Changed(distributionDescriptionFlag) && cfgFromFile.Distribution.Description != "" {
cfg.Distribution.Description = cfgFromFile.Distribution.Description
}
if !flags.Changed(distributionVersionFlag) && cfgFromFile.Distribution.Version != "" {
cfg.Distribution.Version = cfgFromFile.Distribution.Version
}
if !flags.Changed(distributionOtelColVersionFlag) && cfgFromFile.Distribution.OtelColVersion != "" {
cfg.Distribution.OtelColVersion = cfgFromFile.Distribution.OtelColVersion
}

if !flags.Changed(distributionOutputPathFlag) && cfgFromFile.Distribution.OutputPath != "" {
cfg.Distribution.OutputPath = cfgFromFile.Distribution.OutputPath
}
if !flags.Changed(distributionGoFlag) && cfgFromFile.Distribution.Go != "" {
cfg.Distribution.Go = cfgFromFile.Distribution.Go
}
if !flags.Changed(distributionModuleFlag) && cfgFromFile.Distribution.Module != "" {
cfg.Distribution.Module = cfgFromFile.Distribution.Module
}

cfg.Distribution.Name = cfgFromFile.Distribution.Name
cfg.Distribution.Description = cfgFromFile.Distribution.Description
cfg.Distribution.Version = cfgFromFile.Distribution.Version
cfg.Distribution.OtelColVersion = cfgFromFile.Distribution.OtelColVersion
cfg.Distribution.Go = cfgFromFile.Distribution.Go
cfg.Distribution.Module = cfgFromFile.Distribution.Module
cfg.Distribution.BuildTags = cfgFromFile.Distribution.BuildTags
cfg.Distribution.DebugCompilation = cfgFromFile.Distribution.DebugCompilation
}
2 changes: 2 additions & 0 deletions cmd/builder/test/core.builder.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
dist:
name: core
module: go.opentelemetry.io/collector/builder/test/core
otelcol_version: 0.112.0
go: ${GOBIN}

extensions:
- gomod: go.opentelemetry.io/collector/extension/zpagesextension v0.112.0
Expand Down
9 changes: 5 additions & 4 deletions cmd/builder/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GOBIN=$(go env GOBIN)
if [[ "$GO" == "" ]]; then
GOBIN=$(which go)
fi
export GOBIN

if [[ "$GOBIN" == "" ]]; then
echo "Could not determine which Go binary to use."
Expand All @@ -33,15 +34,15 @@ test_build_config() {

final_build_config=$(basename "${build_config}")
"${WORKSPACE_DIR}/.tools/envsubst" < "$build_config" > "${out}/${final_build_config}"
if ! go run . --go "${GOBIN}" --config "${out}/${final_build_config}" --output-path "${out}" --name otelcol-built-test > "${out}/builder.log" 2>&1; then
if ! go run . --config "${out}/${final_build_config}" --output-path "${out}" > "${out}/builder.log" 2>&1; then
echo "❌ FAIL ${test}. Failed to compile the test ${test}. Build logs:"
cat "${out}/builder.log"
failed=true
return
fi

if [ ! -f "${out}/otelcol-built-test" ]; then
echo "❌ FAIL ${test}. Binary not found for ${test} at '${out}/otelcol-built-test'. Build logs:"
if [ ! -f "${out}/${test}" ]; then
echo "❌ FAIL ${test}. Binary not found for ${test} at '${out}/${test}'. Build logs:"
cat "${out}/builder.log"
failed=true
return
Expand All @@ -54,7 +55,7 @@ test_build_config() {
return
fi

"${out}/otelcol-built-test" --config "./test/${test}.otel.yaml" > "${out}/otelcol.log" 2>&1 &
"${out}/${test}" --config "./test/${test}.otel.yaml" > "${out}/otelcol.log" 2>&1 &
pid=$!

retries=0
Expand Down

0 comments on commit cd6bfbb

Please sign in to comment.