From 8b4b2e77697fb381c4419519d9e9b5f2a0ac7337 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Wed, 26 Jun 2024 15:11:19 -0400 Subject: [PATCH 01/10] Merge pull request #3731 from DataDog/trace-disabled-fix --- lib/datadog/tracing.rb | 4 +++- spec/datadog/tracing_spec.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/datadog/tracing.rb b/lib/datadog/tracing.rb index 26cbd3ddadb..12001319861 100644 --- a/lib/datadog/tracing.rb +++ b/lib/datadog/tracing.rb @@ -96,9 +96,11 @@ def correlation # # dd.env=prod dd.service=auth dd.version=13.8 dd.trace_id=5458478252992251 dd.span_id=7117552347370098 My message # ``` # - # @return [String] correlation information + # @return [String] correlation information; or an empty String if Tracing is disabled (`!enabled?`) # @public_api def log_correlation + return '' unless enabled? + correlation.to_log_format end diff --git a/spec/datadog/tracing_spec.rb b/spec/datadog/tracing_spec.rb index dfd63111196..74914b6ea7b 100644 --- a/spec/datadog/tracing_spec.rb +++ b/spec/datadog/tracing_spec.rb @@ -106,6 +106,16 @@ expect(log_correlation).to eq(returned) end # rubocop:enable RSpec/MessageChain + + context 'with tracing disabled' do + before do + allow(Datadog.send(:components).tracer).to receive(:enabled).and_return(false) + end + + it 'returns an empty string' do + expect(log_correlation).to eq('') + end + end end describe '.shutdown!' do From 1f37a23a00f99962e84a5eb9880646358d1122e8 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 30 Aug 2024 11:36:49 +0200 Subject: [PATCH 02/10] Disable persist-credentials when checking out system tests --- .github/workflows/lib-injection.yml | 4 +++- .github/workflows/system-tests.yml | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lib-injection.yml b/.github/workflows/lib-injection.yml index 95df541751f..332a39be93e 100644 --- a/.github/workflows/lib-injection.yml +++ b/.github/workflows/lib-injection.yml @@ -58,9 +58,10 @@ jobs: uses: actions/checkout@v4 with: repository: 'DataDog/system-tests' + persist-credentials: false - name: Install runner - uses: ./.github/actions/install_runner + uses: ./.github/actions/install_runner - name: Run K8s Lib Injection Tests run: ./run.sh K8S_LIB_INJECTION_BASIC @@ -91,6 +92,7 @@ jobs: uses: actions/checkout@v4 with: repository: DataDog/system-tests + persist-credentials: false path: system-tests - name: Overwrite auto inject script with commit SHA run: | diff --git a/.github/workflows/system-tests.yml b/.github/workflows/system-tests.yml index c4ce4e5014d..c6dbf3b672a 100644 --- a/.github/workflows/system-tests.yml +++ b/.github/workflows/system-tests.yml @@ -31,6 +31,7 @@ jobs: uses: actions/checkout@v4 with: repository: 'DataDog/system-tests' + persist-credentials: false - name: Pull released image run: | if docker pull ${{ env.REPO }}/system-tests/${{ matrix.image.name }}:latest; then @@ -104,6 +105,7 @@ jobs: uses: actions/checkout@v4 with: repository: 'DataDog/system-tests' + persist-credentials: false - name: Checkout ${{ matrix.library.repository }} uses: actions/checkout@v4 with: @@ -250,6 +252,7 @@ jobs: uses: actions/checkout@v4 with: repository: 'DataDog/system-tests' + persist-credentials: false - name: Pull runner image run: | docker pull ${{ env.REPO }}/system-tests/runner:gha${{ github.run_id }}-g${{ github.sha }} @@ -316,6 +319,7 @@ jobs: uses: actions/checkout@v4 with: repository: 'DataDog/system-tests' + persist-credentials: false - name: Retrieve logs uses: actions/download-artifact@v4 with: From abc8342d906d505f70768d44048f63a955a7b369 Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Mon, 2 Sep 2024 11:59:11 +0200 Subject: [PATCH 03/10] Backport lib injection test --- .github/workflows/lib-injection.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lib-injection.yml b/.github/workflows/lib-injection.yml index 332a39be93e..01acdad3551 100644 --- a/.github/workflows/lib-injection.yml +++ b/.github/workflows/lib-injection.yml @@ -50,8 +50,8 @@ jobs: env: TEST_LIBRARY: ruby WEBLOG_VARIANT: ${{ matrix.weblog-variant }} - DOCKER_REGISTRY_IMAGES_PATH: ghcr.io/datadog - DOCKER_IMAGE_TAG: ${{ github.sha }} + LIB_INIT_IMAGE: ghcr.io/datadog/dd-trace-rb/dd-lib-ruby-init:${{ github.sha }} + LIBRARY_INJECTION_TEST_APP_IMAGE: ghcr.io/datadog/system-tests/${{ matrix.weblog-variant }}:latest BUILDX_PLATFORMS: linux/amd64,linux/arm64/v8 steps: - name: Checkout system tests @@ -64,7 +64,7 @@ jobs: uses: ./.github/actions/install_runner - name: Run K8s Lib Injection Tests - run: ./run.sh K8S_LIB_INJECTION_BASIC + run: ./run.sh K8S_LIBRARY_INJECTION_BASIC - name: Compress logs id: compress_logs From 425e9883665284935f7de1a19dfdec6e08d74286 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 30 Aug 2024 13:00:56 +0200 Subject: [PATCH 04/10] Fix update-gemfiles workflow permissions No permission is declared in the workflow file, when a switch to a more restrictive global setting would cause the workflow to fail. --- .github/workflows/update-gemfiles.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/update-gemfiles.yml b/.github/workflows/update-gemfiles.yml index e0cbbd0cedb..b6d463d05d3 100644 --- a/.github/workflows/update-gemfiles.yml +++ b/.github/workflows/update-gemfiles.yml @@ -29,6 +29,9 @@ jobs: check: name: Update Gemfiles runs-on: ubuntu-22.04 + permissions: + contents: write + pull-requests: write steps: # Only execute if there's a PR attached to this branch. # Because we execute on `push`, we have to double check here if this is part of a PR. From 88c7723ebb543a335b2e0867900808598cac0d19 Mon Sep 17 00:00:00 2001 From: roberto montero Date: Wed, 17 Jul 2024 15:59:27 +0200 Subject: [PATCH 05/10] Onboarding and k8s lib injection tests: Remove deprecated scenarios (avoid deb and rpm) --- .gitlab-ci.yml | 20 ++++++-------------- .gitlab/onboarding_tests.yml | 34 ---------------------------------- 2 files changed, 6 insertions(+), 48 deletions(-) delete mode 100644 .gitlab/onboarding_tests.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e68fed81440..a6daadd47a8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ stages: include: - remote: https://gitlab-templates.ddbuild.io/apm/packaging.yml - local: ".gitlab/benchmarks.yml" - - local: ".gitlab/onboarding_tests.yml" + - remote: https://gitlab-templates.ddbuild.io/libdatadog/include/single-step-instrumentation-tests.yml variables: DOWNSTREAM_BRANCH: @@ -199,27 +199,19 @@ oci-internal-test-ecr-publish: IMG_REGISTRIES: agent-qa onboarding_tests: - extends: .base_job_onboarding_tests + extends: .base_job_onboarding stage: integration-tests - needs: [ package-amd64, package-arm64, oci-internal-test-ecr-publish] + needs: [ oci-internal-test-ecr-publish ] allow_failure: false variables: TEST_LIBRARY: ruby - ONBOARDING_FILTER_ENV: prod + SCENARIO: SIMPLE_INSTALLER_AUTO_INJECTION + DD_INSTALLER_LIBRARY_VERSION: pipeline-${CI_PIPELINE_ID} parallel: matrix: - - ONBOARDING_FILTER_WEBLOG: [test-app-ruby] - SCENARIO: [SIMPLE_HOST_AUTO_INJECTION] - - ONBOARDING_FILTER_WEBLOG: [test-app-ruby-container] - SCENARIO: [SIMPLE_CONTAINER_AUTO_INJECTION] - - ONBOARDING_FILTER_WEBLOG: [test-app-ruby,test-app-ruby-container] - SCENARIO: [INSTALLER_AUTO_INJECTION] + - ONBOARDING_FILTER_WEBLOG: [test-app-ruby, test-app-ruby-container] script: - git clone https://git@github.com/DataDog/system-tests.git system-tests - - cp packaging/*.rpm system-tests/binaries - - cp packaging/*.deb system-tests/binaries - - export DD_INSTALLER_LIBRARY_VERSION="pipeline-${CI_PIPELINE_ID}" - - ls system-tests/binaries - cd system-tests - ./build.sh -i runner - timeout 2700s ./run.sh $SCENARIO --vm-weblog ${ONBOARDING_FILTER_WEBLOG} --vm-env prod --vm-library ${TEST_LIBRARY} --vm-provider aws --vm-skip-branches ubuntu18_amd64 diff --git a/.gitlab/onboarding_tests.yml b/.gitlab/onboarding_tests.yml deleted file mode 100644 index 1ad4471659a..00000000000 --- a/.gitlab/onboarding_tests.yml +++ /dev/null @@ -1,34 +0,0 @@ -.base_job_onboarding_tests: - - image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/test-infra-definitions/runner:a58cc31c - tags: ["arch:amd64"] - before_script: - # Setup AWS Credentials for dd-trace-rb. - - mkdir -p ~/.aws - - aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.agent-qa-profile --with-decryption --query "Parameter.Value" --out text >> ~/.aws/config - - export DD_API_KEY_ONBOARDING=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.dd-api-key-onboarding --with-decryption --query "Parameter.Value" --out text) - - export DD_APP_KEY_ONBOARDING=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.dd-app-key-onboarding --with-decryption --query "Parameter.Value" --out text) - - export ONBOARDING_AWS_INFRA_SUBNET_ID=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.aws-infra-subnet-id --with-decryption --query "Parameter.Value" --out text) - - export ONBOARDING_AWS_INFRA_SECURITY_GROUPS_ID=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.aws-infra-securiy-groups-id --with-decryption --query "Parameter.Value" --out text) - - export ONBOARDING_AWS_INFRA_IAM_INSTANCE_PROFILE=ec2InstanceRole - - export PULUMI_CONFIG_PASSPHRASE=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.pulumi-config-passphrase --with-decryption --query "Parameter.Value" --out text) - #Install plugins for PULUMI you need connect to gh. Sometimes this problem arises: GitHub rate limit exceeded - - export GITHUB_TOKEN=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.gh-token --with-decryption --query "Parameter.Value" --out text) - #Avoid dockerhub rate limits - - export DOCKER_LOGIN=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.docker-login --with-decryption --query "Parameter.Value" --out text) - - export DOCKER_LOGIN_PASS=$(aws ssm get-parameter --region us-east-1 --name ci.dd-trace-rb.docker-login-pass --with-decryption --query "Parameter.Value" --out text) - - export AWS_PROFILE=agent-qa-ci - - pulumi login --local #"s3://dd-pulumi-state?region=us-east-1&awssdk=v2&profile=$AWS_PROFILE" - - pulumi plugin install resource command 0.7.2 - - pulumi plugin install resource aws 5.41.0 - - after_script: - - echo "After onboarding script" - - cd system-tests - - mkdir -p reports - - cp -R logs_*/ reports/ - - artifacts: - when: always - paths: - - system-tests/reports/ From 99a0138c9e730958b869deba5fc9590836c7fd7a Mon Sep 17 00:00:00 2001 From: Yury Lebedev Date: Fri, 30 Aug 2024 16:04:16 +0200 Subject: [PATCH 06/10] Fix permissions system-tests workflow We need write permissions to push images to registry. --- .github/workflows/system-tests.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/system-tests.yml b/.github/workflows/system-tests.yml index c6dbf3b672a..b7d59b528cf 100644 --- a/.github/workflows/system-tests.yml +++ b/.github/workflows/system-tests.yml @@ -25,6 +25,8 @@ jobs: - name: proxy internal: datadog/system-tests:proxy-v1 runs-on: ubuntu-latest + permissions: + packages: write name: Build (${{ matrix.image.name }}) steps: - name: Checkout @@ -100,6 +102,8 @@ jobs: - rails71 runs-on: ubuntu-latest name: Build (${{ matrix.app }}) + permissions: + packages: write steps: - name: Checkout uses: actions/checkout@v4 From aa261f4d1eebf9d1a7206804950768c6d492bbf6 Mon Sep 17 00:00:00 2001 From: Marco Costa Date: Thu, 12 Sep 2024 15:04:34 -0700 Subject: [PATCH 07/10] Fix Ruby 3.3 warning for ostruct removal --- spec/datadog/core/environment/execution_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/datadog/core/environment/execution_spec.rb b/spec/datadog/core/environment/execution_spec.rb index ef39af0b5e5..ec57ff5b0d9 100644 --- a/spec/datadog/core/environment/execution_spec.rb +++ b/spec/datadog/core/environment/execution_spec.rb @@ -71,7 +71,7 @@ f.close out, = Open3.capture2e('pry', '-f', '--noprompt', f.path) - expect(out).to eq('ACTUAL:true') + expect(out).to include('ACTUAL:true') end end end From 36870daed9d25206a882fef43e90422ec2bb710e Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 13 Sep 2024 01:59:52 +0200 Subject: [PATCH 08/10] Fix permission --- .github/workflows/lib-injection.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/lib-injection.yml b/.github/workflows/lib-injection.yml index 01acdad3551..dd5d1891579 100644 --- a/.github/workflows/lib-injection.yml +++ b/.github/workflows/lib-injection.yml @@ -6,6 +6,8 @@ on: jobs: build-and-publish-test-image: runs-on: ubuntu-latest + permissions: + packages: write steps: - uses: actions/checkout@v4 - name: Set up QEMU From a519a4aaebd9a11dfc9091641476484915fee011 Mon Sep 17 00:00:00 2001 From: TonyCTHsu Date: Thu, 1 Aug 2024 14:34:55 +0200 Subject: [PATCH 09/10] Merge pull request #3821 from DataDog/tonycthsu/fix-integration Pin passenger version for integration test --- integration/apps/rack/Gemfile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integration/apps/rack/Gemfile b/integration/apps/rack/Gemfile index c1a031be60d..33dde3a3e30 100644 --- a/integration/apps/rack/Gemfile +++ b/integration/apps/rack/Gemfile @@ -4,7 +4,11 @@ source "https://rubygems.org" gem 'puma' gem 'unicorn' -gem 'passenger' +if RUBY_VERSION < '2.6.0' + gem 'passenger', '< 6.0.23' +else + gem 'passenger' +end gem 'rack' gem 'rackup' if RUBY_VERSION >= '2.4' # The `rackup` is its own gem since Rack 3.0 From ec2c75a1659f6076f23f33516e7318fb9270e2ee Mon Sep 17 00:00:00 2001 From: Tony Hsu Date: Fri, 6 Sep 2024 17:34:56 +0200 Subject: [PATCH 10/10] Improve brittle assertion --- .../core/environment/execution_spec.rb | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/datadog/core/environment/execution_spec.rb b/spec/datadog/core/environment/execution_spec.rb index ec57ff5b0d9..bb3b9f1fe90 100644 --- a/spec/datadog/core/environment/execution_spec.rb +++ b/spec/datadog/core/environment/execution_spec.rb @@ -57,10 +57,10 @@ context 'when in an IRB session' do it 'returns true' do - _, err = Bundler.with_clean_env do # Ruby 2.6 does not have irb by default in a bundle, but has it outside of it. - Open3.capture3('irb', '--noprompt', '--noverbose', stdin_data: repl_script) + _, err, = Bundler.with_clean_env do # Ruby 2.6 does not have irb by default in a bundle, but has it outside of it. + Open3.capture3('irb', '--noprompt', '--noverbose', '--noecho', stdin_data: repl_script) end - expect(err).to end_with('true') + expect(err).to end_with('ACTUAL:true') end end @@ -70,8 +70,8 @@ f.write(repl_script) f.close - out, = Open3.capture2e('pry', '-f', '--noprompt', f.path) - expect(out).to include('ACTUAL:true') + _, err, = Open3.capture3('pry', '-f', '--noprompt', f.path) + expect(err).to end_with('ACTUAL:true') end end end @@ -128,7 +128,7 @@ def test_it_does_something_useful it 'returns true' do _, err, = Open3.capture3('ruby', stdin_data: script) - expect(err).to end_with('true') + expect(err).to end_with('ACTUAL:true') end end @@ -186,9 +186,10 @@ def test_it_does_something_useful # Add our script to `env.rb`, which is always run before any feature is executed. File.write('features/support/env.rb', repl_script) - _, err = Bundler.with_clean_env do + _, err, = Bundler.with_clean_env do Open3.capture3('ruby', stdin_data: script) end + expect(err).to include('ACTUAL:true') end end @@ -252,7 +253,7 @@ def test_it_does_something_useful context 'when given WebMock', skip: Gem::Version.new(Bundler::VERSION) < Gem::Version.new('2') do it do - out, err = Bundler.with_clean_env do + out, = Bundler.with_clean_env do Open3.capture3('ruby', stdin_data: <<-RUBY require 'bundler/inline' @@ -268,13 +269,12 @@ def test_it_does_something_useful $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'datadog/core/environment/execution' - STDOUT.print Datadog::Core::Environment::Execution.webmock_enabled? + STDOUT.print "ACTUAL:\#{Datadog::Core::Environment::Execution.webmock_enabled?}" RUBY ) end - expect(err).to be_empty - expect(out).to eq('true') + expect(out).to end_with('ACTUAL:true') end end end