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

Check require encapsulation of components #3646

Closed
wants to merge 5 commits into from

Conversation

p-datadog
Copy link
Contributor

What does this PR do?
This PR adds tests that requiring individual components is successful. It also adds some requires that were missing in appsec to make the tests pass.

Motivation:
Troubleshooting configuration for debugging which I copied from appsec, appsec itself does not load cleanly.

Additional Notes:

How to test the change?

Added a unit test and a GH configuration to run it (since it needs a clean environment).

Unsure? Have a question? Request a review!

@p-datadog p-datadog requested review from a team as code owners May 14, 2024 16:45
@github-actions github-actions bot added appsec Application Security monitoring product integrations Involves tracing integrations labels May 14, 2024
Copy link
Contributor

@lloeki lloeki left a comment

Choose a reason for hiding this comment

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

Good catches! But I think it needs some changes.

@@ -0,0 +1,31 @@
require 'English'
Copy link
Contributor

Choose a reason for hiding this comment

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

Filename should be _spec.rb

it 'loads' do
pid = fork do
require req
exec('true')
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you tricky ;)

ruby-version: '3.2'
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- run: rm -f .rspec
- run: bundle exec rspec spec/require_encapsulation_check.rb
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale for a separate job?

If the file is named correctly it can be part of the usual rake spec tasks and tested across the matrix.

Comment on lines +2 to +8
REQUIRES = %w[
datadog/appsec
datadog/core
datadog/kit
datadog/profiling
datadog/tracing
].freeze
Copy link
Contributor

Choose a reason for hiding this comment

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

This constant will be leaking globally, as is it should probably go into the RSpec.describe block.

Could even be a plain local variable, or even just %w[ ... ].each do |req|.

datadog/tracing
].freeze

RSpec.describe 'require encapsulation' do
Copy link
Contributor

Choose a reason for hiding this comment

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

In a way I feel this description isn't quite correct, which led me to think that this spec isn't quite how we expect it to be.

Notably it puts some cross-component knowledge into that spec file. I think it might be better if each "require "works is isolated in each separate component:

  • assert that require datadog/core works => in spec/datadog/core_spec.rb
  • assert that require datadog/appsec works => in spec/datadog/appsec_spec.rb
  • ... and so on

@@ -1,5 +1,6 @@
# frozen_string_literal: true

require_relative '../../../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.

I'm not sure about this require here: this integration file doesn't itself seem to need it.

@@ -11,6 +11,7 @@
require_relative 'gateway/route_params'
require_relative 'gateway/request'
require_relative '../../../tracing/contrib/sinatra/framework'
require_relative '../../../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.

That's a good catch!

But AppSec should be able to load without Tracing being present, so I think instead there's a bit of conditioning around the Tracing constants to be made below.

REQUIRES.each do |req|
context req do
it 'loads' do
pid = fork do
Copy link
Contributor

Choose a reason for hiding this comment

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

fork isn't available on Windows (which we don't support.. yet. I think it's a worthy goal) but more importantly it's not available on JRuby, for which we want coverage as well.

@@ -0,0 +1,31 @@
require 'English'
Copy link
Contributor

Choose a reason for hiding this comment

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

require 'English'

That's in order to have $CHILD_STATUS instead of $??`

@p-datadog
Copy link
Contributor Author

New PR: #3738

@p-datadog p-datadog closed this Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
appsec Application Security monitoring product integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants