<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Remove undocumented handling of `DIST_*` environment variables
replacements
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes#13335
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
The primary purpose of this PR is to provide greater flexibility in how
OTEL binaries are built, enabling the inclusion of debugging symbols
when needed, without always stripping them by default.
Currently, debugging symbols are only retained when
debug_compilation=true. However, this approach also disables all
compiler inlining and optimizations (gcflags=all=-N -l) to ensure an
exact match between written and executed code, resulting in a
significant increase in CPU consumption. There are scenarios where we
want binaries with debugging symbols and DWARF information while still
allowing the compiler to optimize and inline. This PR addresses that
need by introducing configurable GCFlags.
`ocb --ldflags="" --gcflags="" --config=builder-config.yaml`
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes
[#58](https://github.com/open-telemetry/opentelemetry-collector-releases/issues/58)
<!--Describe what testing was performed and which tests were added.-->
#### Testing
Manual
Override LDflags:

Override both

<!--Describe the documentation added.-->
#### Documentation
README file updated.
--
Backward compatibility concerns:
- As of today, passing cfg.LDFlags will append to LD flags that are by
default to `-s -w`.
Questions:
- Should we deprecate DebugCompilation property?
<!--Please delete paragraphs that you did not use before submitting.-->
This is a no-op, because the file config cannot set the "skip"
properties since they have `mapstructure:"-"`
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes #
<!--Describe what testing was performed and which tests were added.-->
#### Testing
<!--Describe the documentation added.-->
#### Documentation
<!--Please delete paragraphs that you did not use before submitting.-->
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Disable strict version check. The `--skip-strict-version-check` is kept
but is now a no-op.
This fixes#11152.
<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes#11152
A continuation of
https://github.com/open-telemetry/opentelemetry-collector/pull/9253 and
https://github.com/open-telemetry/opentelemetry-collector/pull/9631
Description: Adds a `--skip-new-go-module` flag to the OTC builder. This
enables users working in an existing go module environment (say, a
"monorepo") to update the module they have, vs forcing the use of a new
module.
With the new support inside an existing Go module, a collector main
package can be generated using a go:generate directive. For example, in
the directory where I want my collector built, the file generate.go has
this line:
//go:generate builder --skip-new-go-module --skip-compilation
--strict-versioning --config=./build-config.yaml
In the same directory, the build-config.yaml describes the collector to
build. The builder generates the other files in the same directory. At
this point, normal Go workflows can be used to update indirect
dependencies.
Link to tracking Issue:
https://github.com/open-telemetry/opentelemetry-collector/issues/9252
Testing: Will add unit tests in the next few days.
Documentation: Yes.
---------
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
**Description:**
Allow configuring confmap providers in the builder's config. If the
field isn't set, the default set of providers is used.
**Link to tracking Issue:**
Resolves
https://github.com/open-telemetry/opentelemetry-collector/issues/4759.
**Testing:**
Extended unit tests.
**Documentation:**
Updated the readme to include the new options in the example manifest
file.
cc @mx-psi
---------
Co-authored-by: Evan Bradley <evan-bradley@users.noreply.github.com>
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
**Description:** <Describe what has changed.>
Adds strict version checking in the builder. This enables users to
ensure that the versions specified in the builder config are the
versions used in the go.mod when building the collector binary. This can
be disabled with --skip-strict-versioning.
**Link to tracking Issue:** #9896
**Testing:** Added unit tests
**Documentation:** Added to builder README
---------
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
Adds `go.opentelemetry.io/collector/otelcol` to `go.mod` template for
the builder. This fixes#8692.
Since #8443, the `otelcol` folder is its own component. Before this
change, `otelcol_version` was enforced by the `collector` module
dependency:
287b98f697/cmd/builder/internal/builder/templates/go.mod.tmpl (L23)
After this change, the `go mod tidy` step here:
287b98f697/cmd/builder/internal/builder/main.go (L115)
will add the latest available version for the `otelcol` module since
none of the components actually depend on it. For example, with the
`v0.86.0` builder config the output is as follows:
```
❯ go mod tidy -v -compat=1.20
go: finding module for package go.opentelemetry.io/collector/otelcol
go: found go.opentelemetry.io/collector/otelcol in go.opentelemetry.io/collector/otelcol v0.87.0
```
Explicitly adding `otelcol` makes it so the `otelcol_version` is
correctly honored.
**Link to tracking Issue:** Fixes#8692
**Description:** partially fix loading builder config from the env. This
moves the env option from unusable (wrong parsing of nested keys), to
usable for the `dist.*` settings, but not for any of the
components/modules, which will require more complex parsing for arrays.
**Link to tracking Issue:** #8239
**Testing:** try running it locally
This option makes the builder skip generating sources.
**Link to tracking Issue:** #7541
**Testing:** Unit tests
**Documentation:** as part of the CLI help menu
Signed-off-by: Francois JACQUES <hypnoce@donarproject.org>
* [chore] use license shortform
To remain consistent w/ contrib repo, see https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/22052
Signed-off-by: Alex Boten <aboten@lightstep.com>
* make goporto
Signed-off-by: Alex Boten <aboten@lightstep.com>
---------
Signed-off-by: Alex Boten <aboten@lightstep.com>
Embed the build configuration that is used to build otelcorecol into ocb
so that end users can easily generate a useful collector. This makes the
`--config` flag optional again.
Signed-off-by: James Peach <jpeach@cloudflare.com>
Signed-off-by: James Peach <jpeach@cloudflare.com>
This is unnecessary because:
1. It happens before flags are loaded, so will initialize things with default values, which already happens during flags initialization. See flags.StringVar for example.
2. The load using posflag provider, as defined right now (with current flags name) produce this config:
```
k := map[string]interface{} {
"config": ""
"description": "Custom OpenTelemetry Collector distribution"
"go": ""
"module": "go.opentelemetry.io/collector/cmd/builder"
"name": "otelcol-custom otelcol-version:0.58.0"
"output-path": "/var/folders/5c/5p_3jmvd6qx0rsvmb9j7c_s00000gn/T/otelcol-distribution1155391158"
"skip-compilation": false
"version": "1.0.0"
}
```
As you can see, this will whole be ignored, since all the configs (except the config flag) are sub-configs under "dist" anyway.
Signed-off-by: Bogdan <bogdandrutu@gmail.com>
This PR updates the builder's config initialization so that flags always take precedence over configuration files or default values.
I opted not to use the collector's resolvers/converter approach as it felt overkill for this command. This approach takes advantage of the command's existing use of global vars, which isn't the best, but is at least consistent.
If the builder can't load its build configuration file, it logs an error
and continues. This results in building a collector that is not the one
the user specified. Exit with a fatal error instead.
Signed-off-by: James Peach <jpeach@cloudflare.com>
Update the builder to consistently use "ocb" in the name of the command,
version. Since the builder does not expand environment variables in the
config file pathname, the default value for `--config` does not work,
so we can make this flag required so that users don't silently build an
inoperative collector.
This fixes#5581.
Signed-off-by: James Peach <jpeach@cloudflare.com>