Skip to content

Commit

Permalink
Merge branch 'master' into ivoanjo/add-dependency-on-logger-gem
Browse files Browse the repository at this point in the history
  • Loading branch information
ivoanjo authored Jan 17, 2025
2 parents 19af8f5 + 7e37aff commit f3770c5
Show file tree
Hide file tree
Showing 1,313 changed files with 8,258 additions and 28,178 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ save_bundle_checksum: &save_bundle_checksum
command: |
if [ "$CI_BUNDLE_CACHE_HIT" != 1 ]; then
# Recompute gemfiles/*.lock checksum, as those files might have changed
cat Gemfile Gemfile.lock ruby-*.gemfile gemfiles/*.gemfile gemfiles/*.gemfile.lock | md5sum > .circleci/bundle_checksum
cat Gemfile Gemfile.lock jruby-*.gemfile ruby-*.gemfile gemfiles/*.gemfile gemfiles/*.gemfile.lock | md5sum > .circleci/bundle_checksum
fi
cp .circleci/bundle_checksum /usr/local/bundle/bundle_checksum
step_bundle_install: &step_bundle_install
Expand Down Expand Up @@ -96,7 +96,7 @@ step_compute_bundle_checksum: &step_compute_bundle_checksum
# updating the gemset lock files produces extremely large commits.
command: |
bundle lock # Create Gemfile.lock
cat Gemfile Gemfile.lock ruby-*.gemfile gemfiles/*.gemfile gemfiles/*.gemfile.lock | md5sum > .circleci/bundle_checksum
cat Gemfile Gemfile.lock jruby-*.gemfile ruby-*.gemfile gemfiles/*.gemfile gemfiles/*.gemfile.lock | md5sum > .circleci/bundle_checksum
step_get_test_agent_trace_check_results: &step_get_test_agent_trace_check_results
run:
name: Get APM Test Agent Trace Check Results
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ body:

- type: textarea
attributes:
label: How does Datadog Help You
label: How does Datadog help you?
description: "Optionally, tell us why and how you're using datadog, and what your overall experience with it is!"
validations:
required: false
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ body:
description: Add any other context or screenshots about the feature request here
validations:
required: false

- type: textarea
attributes:
label: How does Datadog help you?
description: "Optionally, tell us why and how you're using datadog, and what your overall experience with it is!"
validations:
required: false
162 changes: 162 additions & 0 deletions .github/scripts/find_gem_version_bounds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
require 'pathname'
require 'rubygems'
require 'json'
require 'bundler'

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'datadog'

class GemfileProcessor
SPECIAL_CASES = {
"opensearch" => "OpenSearch" # special case because opensearch = OpenSearch not Opensearch
}.freeze
EXCLUDED_INTEGRATIONS = ["configuration", "propagation", "utils"].freeze

def initialize(directory: 'gemfiles/', contrib_dir: 'lib/datadog/tracing/contrib/')
@directory = directory
@contrib_dir = contrib_dir
@min_gems = { 'ruby' => {}, 'jruby' => {} }
@max_gems = { 'ruby' => {}, 'jruby' => {} }
@integration_json_mapping = {}
end

def process
parse_gemfiles
process_integrations
include_hardcoded_versions
write_output
end

private


def parse_gemfiles(directory = 'gemfiles/')
gemfiles = Dir.glob(File.join(@directory, '*'))
gemfiles.each do |gemfile_name|
runtime = File.basename(gemfile_name).split('_').first # ruby or jruby
next unless %w[ruby jruby].include?(runtime)
# parse the gemfile
if gemfile_name.end_with?(".gemfile")
process_gemfile(gemfile_name, runtime)
elsif gemfile_name.end_with?('.gemfile.lock')
process_lockfile(gemfile_name, runtime)
end
end

end

def process_gemfile(gemfile_name, runtime)
begin
definition = Bundler::Definition.build(gemfile_name, nil, nil)
definition.dependencies.each do |dependency|
gem_name = dependency.name
version = dependency.requirement.to_s
unspecified = version.strip == '' || version == ">= 0"
if unspecified
puts "#{gem_name} uses latest"
end
update_gem_versions(runtime, gem_name, version, unspecified)
end
rescue Bundler::GemfileError => e
puts "Error reading Gemfile: #{e.message}"
end
end

def process_lockfile(gemfile_name, runtime)
lockfile_contents = File.read(gemfile_name)
parser = Bundler::LockfileParser.new(lockfile_contents)
parser.specs.each do |spec|
gem_name = spec.name
version = spec.version.to_s
update_gem_versions(runtime, gem_name, version, false)
end
end

def update_gem_versions(runtime, gem_name, version, unspecified)
return unless version_valid?(version, unspecified)

gem_version = Gem::Version.new(version) unless unspecified
# Update minimum gems
if not unspecified
if @min_gems[runtime][gem_name].nil? || gem_version < Gem::Version.new(@min_gems[runtime][gem_name])
@min_gems[runtime][gem_name] = version
end
end

# Update maximum gems
if unspecified
puts "Setting gem #{gem_name} to infinity"
@max_gems[runtime][gem_name] = Float::INFINITY
else
if @max_gems[runtime][gem_name].nil? || (@max_gems[runtime][gem_name] != Float::INFINITY && gem_version > Gem::Version.new(@max_gems[runtime][gem_name]))
@max_gems[runtime][gem_name] = version
end
end
end

# Helper: Validate the version format
def version_valid?(version, unspecified)
return true if unspecified
return false if version.nil? || version.strip.empty?
Gem::Version.new(version)
true
rescue ArgumentError
false
end


def process_integrations
integrations = Datadog::Tracing::Contrib::REGISTRY.map(&:name).map(&:to_s)
integrations.each do |integration|
next if EXCLUDED_INTEGRATIONS.include?(integration)

integration_name = resolve_integration_name(integration)

@integration_json_mapping[integration] = [
@min_gems['ruby'][integration_name],
@max_gems['ruby'][integration_name],
@min_gems['jruby'][integration_name],
@max_gems['jruby'][integration_name]
]
end
end

def include_hardcoded_versions
# `httpx` is maintained externally
@integration_json_mapping['httpx'] = [
'0.11', # Min version Ruby
nil, # Max version Ruby
'0.11', # Min version JRuby
nil # Max version JRuby
]

# `makara` is part of `activerecord`
@integration_json_mapping['makara'] = [
'0.3.5', # Min version Ruby
nil, # Max version Ruby
'0.3.5', # Min version JRuby
nil # Max version JRuby
]
end

def resolve_integration_name(integration)
mod_name = SPECIAL_CASES[integration] || integration.split('_').map(&:capitalize).join
module_name = "Datadog::Tracing::Contrib::#{mod_name}"
integration_module = Object.const_get(module_name)::Integration
integration_module.respond_to?(:gem_name) ? integration_module.gem_name : integration
rescue NameError, NoMethodError
puts "Fallback for #{integration}: module or gem_name not found."
integration
end

def write_output
@integration_json_mapping = @integration_json_mapping.sort.to_h
@integration_json_mapping.each do |integration, versions|
versions.map! { |v| v == Float::INFINITY ? 'infinity' : v }
end
File.write("gem_output.json", JSON.pretty_generate(@integration_json_mapping))
end
end

GemfileProcessor.new.process
27 changes: 27 additions & 0 deletions .github/scripts/generate_table_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require 'json'

input_file = 'gem_output.json'
output_file = 'integration_versions.md'

data = JSON.parse(File.read(input_file))

comment = "# Integrations\n\n"
header = "| Integration | Ruby Min | Ruby Max | JRuby Min | JRuby Max |\n"
separator = "|-------------|----------|-----------|----------|----------|\n"
rows = data.map do |integration_name, versions|
ruby_min, ruby_max, jruby_min, jruby_max = versions.map do |v|
if v == "infinity"
"latest"
else
v || "None"
end
end
"| #{integration_name} | #{ruby_min} | #{ruby_max} | #{jruby_min} | #{jruby_max} |"
end

File.open(output_file, 'w') do |file|
file.puts comment
file.puts header
file.puts separator
rows.each { |row| file.puts row }
end
49 changes: 49 additions & 0 deletions .github/workflows/generate-supported-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Generate Supported Versions"

on:
workflow_dispatch:


concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true # runs bundle install
ruby-version: "3.3"

- name: Update latest
run: bundle exec ruby .github/scripts/find_gem_version_bounds.rb

- name: Generate versions table
run: ruby .github/scripts/generate_table_versions.rb

- run: git diff

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GHA_PAT }}
branch: auto-generate/update-supported-versions
title: '[🤖] Update Supported Versions'
base: master
labels: dev/internal, integrations
commit-message: "Test creating supported versions"
delete-branch: true
body: |
This is a PR to update the table for supported integration versions.
Workflow run: [Generate Supported Versions](https://github.com/DataDog/dd-trace-rb/actions/workflows/generate-supported-versions.yml)
This should be tied to tracer releases, or triggered manually.
23 changes: 15 additions & 8 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ onboarding_tests_installer:
onboarding_tests_k8s_injection:
parallel:
matrix:
- WEBLOG_VARIANT: [dd-lib-ruby-init-test-rails, dd-lib-ruby-init-test-rails-explicit,dd-lib-ruby-init-test-rails-gemsrb]
- WEBLOG_VARIANT: [dd-lib-ruby-init-test-rails, dd-lib-ruby-init-test-rails-explicit,dd-lib-ruby-init-test-rails-gemsrb]
SCENARIO: [K8S_LIB_INJECTION, K8S_LIB_INJECTION_UDS, K8S_LIB_INJECTION_NO_AC, K8S_LIB_INJECTION_NO_AC_UDS, K8S_LIB_INJECTION_PROFILING_DISABLED, K8S_LIB_INJECTION_PROFILING_ENABLED, K8S_LIB_INJECTION_PROFILING_OVERRIDE]
K8S_CLUSTER_VERSION: ['7.56.2','7.59.0']

save_versions:
image: $DOCKER_REGISTRY/images/mirror/ruby:3.2.2
Expand All @@ -149,16 +151,21 @@ deploy_to_reliability_env:
needs:
- save_versions

# Currently, the job is implemented with polling mechanism.
#
# Due to the constraints of Github workflow dispatch endpoint, it does not return the workflow run id.
# https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event
#
# We fetch the latest workflow run from vaccine after 5 seconds of the dispatch event.
# False positive/negative result can happen when multiple requests are made within the same window.
#
# TODO:
# Replace polling implementation with reporting status to Github with Github App. This will allow us
# to get a deterministic result without mismatched workflow run id.
vaccine:
image: $DOCKER_REGISTRY/docker:20.10.13
tags: [ "arch:amd64" ]
stage: vaccine
needs: [create-multiarch-lib-injection-image]
script: |
GH_VACCINE_PAT=$(vault kv get -field=vaccine-token kv/k8s/gitlab-runner/dd-trace-rb/github-token)
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $GH_VACCINE_PAT" \
https://api.github.com/repos/TonyCTHsu/vaccine/actions/workflows/vaccine.yml/dispatches \
-d '{"ref":"master", "inputs": {"commit_sha": "'$CI_COMMIT_SHA'"}}'
.gitlab/scripts/vaccine.sh
Loading

0 comments on commit f3770c5

Please sign in to comment.