Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add supported versions workflow #4210

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions .github/scripts/find_gem_version_bounds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
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'

def parse_gemfiles(directory = 'gemfiles/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

minimum_gems_ruby = {}
minimum_gems_jruby = {}
maximum_gems_ruby = {}
maximum_gems_jruby = {}


gemfiles = Dir.glob(File.join(directory, '*'))
gemfiles.each do |gemfile_name|
runtime = File.basename(gemfile_name).split('_').first # ruby or jruby
# parse the gemfile
if gemfile_name.end_with?(".gemfile")
begin
definition = Bundler::Definition.build(gemfile_name, nil, nil)

definition.dependencies.each do |dependency|
gem_name, version = dependency.name, dependency.requirement
# puts "Gem: #{dependency.name}, Version: #{dependency.requirement}"
if version_valid?(version)
case runtime
when 'ruby'
update_min_max(minimum_gems_ruby, maximum_gems_ruby, gem_name, version)
when 'jruby'
update_min_max(minimum_gems_jruby, maximum_gems_jruby, gem_name, version)
end
else
next
end
end
rescue Bundler::GemfileError => e
puts "Error reading Gemfile: #{e.message}"
end
elsif gemfile_name.end_with?(".gemfile.lock")
lockfile_contents = File.read(gemfile_name)
parser = Bundler::LockfileParser.new(lockfile_contents)
parser.specs.each do |spec|
# puts "Gem: #{spec.name}, Version: #{spec.version}"
gem_name, version = spec.name, spec.version.to_s
if version_valid?(version)
case runtime
when 'ruby'
update_min_max(minimum_gems_ruby, maximum_gems_ruby, gem_name, version)
when 'jruby'
update_min_max(minimum_gems_jruby, maximum_gems_jruby, gem_name, version)
end
else
next
end
end
end
end

[minimum_gems_ruby, minimum_gems_jruby, maximum_gems_ruby, maximum_gems_jruby]
end


def update_min_max(minimum_gems, maximum_gems, gem_name, version)
quinna-h marked this conversation as resolved.
Show resolved Hide resolved
gem_version = Gem::Version.new(version)

if minimum_gems[gem_name].nil? || gem_version < Gem::Version.new(minimum_gems[gem_name])
minimum_gems[gem_name] = version
end

if maximum_gems[gem_name].nil? || gem_version > Gem::Version.new(maximum_gems[gem_name])
maximum_gems[gem_name] = version
end
end

def parse_gemfile(gemfile_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

# Helper: Parse a Gemfile
begin
definition = Bundler::Definition.build(gemfile_path, nil, nil)

definition.dependencies.each do |dependency|
puts "Gem: #{dependency.name}, Version: #{dependency.requirement}"
end
end
rescue Bundler::GemfileError => e
puts "Error reading Gemfile: #{e.message}"
end


# Helper: Validate the version format
def version_valid?(version)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

return false if version.nil?

# Convert to string if version is not already a string
version = version.to_s.strip

return false if version.empty?

# Ensure it's a valid Gem::Version
begin
Gem::Version.new(version)
true
rescue ArgumentError
false
end
end


# Helper: Extract the actual version number from a constraint
# Matches on the following version patterns:
# 1. "pessimistic" versions, ex. '~> 1.2.3'
# 2. '>= 1.2.3'
# 3. 1.2.3
def extract_version(constraint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

if constraint =~ /~>\s*([\d.]+(?:[-.\w]*))| # Handles ~> constraints
>=\s*([\d.]+(?:[-.\w]*))| # Handles >= constraints
([\d.]+(?:[-.\w]*)) # Handles plain versions
/x
Regexp.last_match(1) || Regexp.last_match(2) || Regexp.last_match(3)
end
end

def get_integration_names(directory = 'lib/datadog/tracing/contrib/')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Code Quality Violation

Avoid top-level methods definition. Organize methods in modules/classes. (...read more)

This rule emphasizes the importance of organizing methods within modules or classes in Ruby. In Ruby, it's considered a best practice to wrap methods within classes or modules. This is because it helps in grouping related methods together, which in turn makes the code easier to understand, maintain, and reuse.

Not adhering to this rule can lead to a disorganized codebase, making it hard for other developers to understand and maintain the code. It can also lead to potential name clashes if a method is defined in the global scope.

To avoid violating this rule, always define your methods within a class or a module. For example, instead of writing def some_method; end, you should write class SomeClass def some_method; end end. This not only adheres to the rule but also improves the readability and maintainability of your code.

View in Datadog  Leave us feedback  Documentation

Datadog::Tracing::Contrib::REGISTRY.map{ |i| i.name.to_s }
end

# TODO: The gem information should reside in the integration declaration instead of here.

mapping = {
quinna-h marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some that I don't see and I don't think have a clear automation path that we could potentially just hardcode in:

Net/HTTP and Makara (via Active Record) are the only two I see (may have missed one though)

Just went through the list of them here: https://docs.datadoghq.com/tracing/trace_collection/compatibility/ruby/#integrations

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comments about these on the generated PR: #4236

"action_mailer" => "actionmailer",
"opensearch" => "opensearch-ruby",
"concurrent_ruby" => "concurrent-ruby",
"action_view" => "actionview",
"action_cable" => "actioncable",
"active_record" => "activerecord",
"mongodb" => "mongo",
"rest_client" => "rest-client",
"active_support" => "activesupport",
"action_pack" => "actionpack",
"active_job" => "activejob",
"httprb" => "http",
"kafka" => "ruby-kafka",
"presto" => "presto-client",
"aws" => "aws-sdk-core"
}

excluded = ["configuration", "propagation", "utils"]
min_gems_ruby, min_gems_jruby, max_gems_ruby, max_gems_jruby = parse_gemfiles("gemfiles/")
integrations = get_integration_names('lib/datadog/tracing/contrib/')

integration_json_mapping = {}

integrations.each do |integration|
if excluded.include?(integration)
next
end
integration_name = mapping[integration] || integration

min_version_jruby = min_gems_jruby[integration_name]
min_version_ruby = min_gems_ruby[integration_name]
max_version_jruby = max_gems_jruby[integration_name]
max_version_ruby = max_gems_ruby[integration_name]

# mapping jruby, ruby
integration_json_mapping[integration] = [min_version_ruby, max_version_ruby, min_version_jruby, max_version_jruby]
integration_json_mapping.replace(integration_json_mapping.sort.to_h)
end

File.write("gem_output.json", JSON.pretty_generate(integration_json_mapping))
25 changes: 25 additions & 0 deletions .github/scripts/generate_table_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require 'json'

# Input and output file names
input_file = 'gem_output.json'
output_file = 'integration_versions.md'

# Read JSON data from the input file
data = JSON.parse(File.read(input_file))

# Prepare the Markdown content
comment = "# This is a table of supported integration versions generated from gemfiles.\n\n"
quinna-h marked this conversation as resolved.
Show resolved Hide resolved
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 { |v| v || "None" }
"| #{integration_name} | #{ruby_min} | #{ruby_max} | #{jruby_min} | #{jruby_max} |"
end

# Write the Markdown file
File.open(output_file, 'w') do |file|
file.puts comment
file.puts header
file.puts separator
rows.each { |row| file.puts row }
end
Loading
Loading