Skip to content

Commit

Permalink
Generate replaces automatically in builder-integration-test (#11793)
Browse files Browse the repository at this point in the history
This PR removes the manually maintained `replace` statements in
`cmd/builder/test/core.builder.yaml` and generates them automatically in
`cmd/builder/test/test.sh`. This ensures that the builder integration
test properly uses the local version of core collector modules, even if
a `replace` statement is forgotten. This is especially important in
release PRs where dependencies have not-yet-valid version numbers (see
tracking issue for context).

I believe a better implementation of this long-term may be to commit a
`go.work` file to the repository as the single source of truth for
`replace`s, and let the `go` commands run by `ocb` take it into account
automatically. (This would also avoid needing to maintain the `replace`s
in every `go.mod`, which can be annoying when `make crosslink` is not
sufficient.) But as there were [objections the last time this was
discussed](open-telemetry/opentelemetry-collector-contrib#21972 (comment)),
I decided to leave this as a future discussion.

Fixes #11607

We can simulate a Release PR by setting the `exporter` import in
`debugexporter` to an invalid version like `0.999.0`. With the new
script, this causes no problems, showing that the build uses the local
version without fetching from the proxy. Filtering the `exporter` module
from the replace statements by adding this to the script:
```bash
core_mods=$(echo "$core_mods" | grep -v "/exporter$")
```
makes `ocb` output the expected `unknown revision` error.
  • Loading branch information
jade-guiton-dd committed Dec 17, 2024
1 parent 4fc50a8 commit e8f5c27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 65 deletions.
64 changes: 0 additions & 64 deletions cmd/builder/test/core.builder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,3 @@ receivers:
exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.116.0

replaces:
- go.opentelemetry.io/collector => ${WORKSPACE_DIR}
- go.opentelemetry.io/collector/client => ${WORKSPACE_DIR}/client
- go.opentelemetry.io/collector/component => ${WORKSPACE_DIR}/component
- go.opentelemetry.io/collector/component/componenttest => ${WORKSPACE_DIR}/component/componenttest
- go.opentelemetry.io/collector/component/componentstatus => ${WORKSPACE_DIR}/component/componentstatus
- go.opentelemetry.io/collector/config/configauth => ${WORKSPACE_DIR}/config/configauth
- go.opentelemetry.io/collector/config/configcompression => ${WORKSPACE_DIR}/config/configcompression
- go.opentelemetry.io/collector/config/configgrpc => ${WORKSPACE_DIR}/config/configgrpc
- go.opentelemetry.io/collector/config/confighttp => ${WORKSPACE_DIR}/config/confighttp
- go.opentelemetry.io/collector/config/confignet => ${WORKSPACE_DIR}/config/confignet
- go.opentelemetry.io/collector/config/configopaque => ${WORKSPACE_DIR}/config/configopaque
- go.opentelemetry.io/collector/config/configretry => ${WORKSPACE_DIR}/config/configretry
- go.opentelemetry.io/collector/config/configtelemetry => ${WORKSPACE_DIR}/config/configtelemetry
- go.opentelemetry.io/collector/config/configtls => ${WORKSPACE_DIR}/config/configtls
- go.opentelemetry.io/collector/config/internal => ${WORKSPACE_DIR}/config/internal
- go.opentelemetry.io/collector/confmap => ${WORKSPACE_DIR}/confmap
- go.opentelemetry.io/collector/confmap/provider/envprovider => ${WORKSPACE_DIR}/confmap/provider/envprovider
- go.opentelemetry.io/collector/confmap/provider/fileprovider => ${WORKSPACE_DIR}/confmap/provider/fileprovider
- go.opentelemetry.io/collector/confmap/provider/httpprovider => ${WORKSPACE_DIR}/confmap/provider/httpprovider
- go.opentelemetry.io/collector/confmap/provider/httpsprovider => ${WORKSPACE_DIR}/confmap/provider/httpsprovider
- go.opentelemetry.io/collector/confmap/provider/yamlprovider => ${WORKSPACE_DIR}/confmap/provider/yamlprovider
- go.opentelemetry.io/collector/consumer => ${WORKSPACE_DIR}/consumer
- go.opentelemetry.io/collector/consumer/consumererror => ${WORKSPACE_DIR}/consumer/consumererror
- go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles => ${WORKSPACE_DIR}/consumer/consumererror/consumererrorprofiles
- go.opentelemetry.io/collector/consumer/consumererror/xconsumererror => ${WORKSPACE_DIR}/consumer/consumererror/xconsumererror
- go.opentelemetry.io/collector/consumer/xconsumer => ${WORKSPACE_DIR}/consumer/xconsumer
- go.opentelemetry.io/collector/consumer/consumertest => ${WORKSPACE_DIR}/consumer/consumertest
- go.opentelemetry.io/collector/connector => ${WORKSPACE_DIR}/connector
- go.opentelemetry.io/collector/connector/connectortest => ${WORKSPACE_DIR}/connector/connectortest
- go.opentelemetry.io/collector/connector/xconnector => ${WORKSPACE_DIR}/connector/xconnector
- go.opentelemetry.io/collector/exporter => ${WORKSPACE_DIR}/exporter
- go.opentelemetry.io/collector/exporter/debugexporter => ${WORKSPACE_DIR}/exporter/debugexporter
- go.opentelemetry.io/collector/exporter/xexporter => ${WORKSPACE_DIR}/exporter/xexporter
- go.opentelemetry.io/collector/exporter/exportertest => ${WORKSPACE_DIR}/exporter/exportertest
- go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper => ${WORKSPACE_DIR}/exporter/exporterhelper/xexporterhelper
- go.opentelemetry.io/collector/extension => ${WORKSPACE_DIR}/extension
- go.opentelemetry.io/collector/extension/auth => ${WORKSPACE_DIR}/extension/auth
- go.opentelemetry.io/collector/extension/auth/authtest => ${WORKSPACE_DIR}/extension/auth/authtest
- go.opentelemetry.io/collector/extension/experimental/storage => ${WORKSPACE_DIR}/extension/experimental/storage
- go.opentelemetry.io/collector/extension/extensioncapabilities => ${WORKSPACE_DIR}/extension/extensioncapabilities
- go.opentelemetry.io/collector/extension/extensiontest => ${WORKSPACE_DIR}/extension/extensiontest
- go.opentelemetry.io/collector/extension/zpagesextension => ${WORKSPACE_DIR}/extension/zpagesextension
- go.opentelemetry.io/collector/featuregate => ${WORKSPACE_DIR}/featuregate
- go.opentelemetry.io/collector/internal/memorylimiter => ${WORKSPACE_DIR}/internal/memorylimiter
- go.opentelemetry.io/collector/internal/fanoutconsumer => ${WORKSPACE_DIR}/internal/fanoutconsumer
- go.opentelemetry.io/collector/internal/sharedcomponent => ${WORKSPACE_DIR}/internal/sharedcomponent
- go.opentelemetry.io/collector/otelcol => ${WORKSPACE_DIR}/otelcol
- go.opentelemetry.io/collector/otelcol/otelcoltest => ${WORKSPACE_DIR}/otelcol/otelcoltest
- go.opentelemetry.io/collector/pdata => ${WORKSPACE_DIR}/pdata
- go.opentelemetry.io/collector/pdata/pprofile => ${WORKSPACE_DIR}/pdata/pprofile
- go.opentelemetry.io/collector/pdata/testdata => ${WORKSPACE_DIR}/pdata/testdata
- go.opentelemetry.io/collector/pipeline => ${WORKSPACE_DIR}/pipeline
- go.opentelemetry.io/collector/pipeline/xpipeline => ${WORKSPACE_DIR}/pipeline/xpipeline
- go.opentelemetry.io/collector/processor => ${WORKSPACE_DIR}/processor
- go.opentelemetry.io/collector/processor/processortest => ${WORKSPACE_DIR}/processor/processortest
- go.opentelemetry.io/collector/processor/xprocessor => ${WORKSPACE_DIR}/processor/xprocessor
- go.opentelemetry.io/collector/receiver => ${WORKSPACE_DIR}/receiver
- go.opentelemetry.io/collector/receiver/otlpreceiver => ${WORKSPACE_DIR}/receiver/otlpreceiver
- go.opentelemetry.io/collector/receiver/xreceiver => ${WORKSPACE_DIR}/receiver/xreceiver
- go.opentelemetry.io/collector/receiver/receivertest => ${WORKSPACE_DIR}/receiver/receivertest
- go.opentelemetry.io/collector/scraper => ${WORKSPACE_DIR}/scraper
- go.opentelemetry.io/collector/semconv => ${WORKSPACE_DIR}/semconv
- go.opentelemetry.io/collector/service => ${WORKSPACE_DIR}/service
11 changes: 10 additions & 1 deletion cmd/builder/test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test_build_config() {
echo "Starting test '${test}' at $(date)" >> "${out}/test.log"

final_build_config=$(basename "${build_config}")
"${WORKSPACE_DIR}/.tools/envsubst" < "$build_config" > "${out}/${final_build_config}"
"${WORKSPACE_DIR}/.tools/envsubst" -o "${out}/${final_build_config}" -i <(cat "$build_config" "$replaces")
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"
Expand Down Expand Up @@ -113,6 +113,15 @@ tests="core"
base=$(mktemp -d)
echo "Running the tests in ${base}"

replaces="$base/replaces"
# Get path of all core modules, in sorted order, without the initial dot
core_mods=$(cd ../.. && find . -type f -name "go.mod" -exec dirname {} \; | sort | sed 's/.//')
echo "replaces:" >> "$replaces"
for mod in $core_mods; do
echo " - go.opentelemetry.io/collector$mod => \${WORKSPACE_DIR}$mod" >> "$replaces"
done
echo "Wrote replace statements to $replaces"

failed=false

for test in $tests
Expand Down

0 comments on commit e8f5c27

Please sign in to comment.