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

Create init image for lib-injection #2606

Merged
merged 29 commits into from
Feb 28, 2023
Merged

Create init image for lib-injection #2606

merged 29 commits into from
Feb 28, 2023

Conversation

TonyCTHsu
Copy link
Contributor

@TonyCTHsu TonyCTHsu commented Feb 8, 2023

What

Create init container image for k8s admission controller injection.

The init container image leverage RUBYOPT for ruby intepreter and the injection script would make an attempt to include ddtrace within the bundle. The install attempt could failed due to Bundler's deployment mode or unable to resolve compatible versions from bundler, but it would not blocked application process.

For a Rails/Hanami app, the application would be auto instrumented.

Public release workflow would be triggered during a release with a tag push v*.*.* . Otherwise, the workflow would create images for internal testing purchase.

@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch 2 times, most recently from db3ca3e to d2f48b4 Compare February 16, 2023 13:09
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 55ee18f to 1d48dad Compare February 16, 2023 19:31
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 1d48dad to 159657b Compare February 16, 2023 19:42
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch 2 times, most recently from 4554856 to 764028b Compare February 21, 2023 11:02
@TonyCTHsu TonyCTHsu marked this pull request as ready for review February 21, 2023 11:54
@TonyCTHsu TonyCTHsu requested a review from a team February 21, 2023 11:54
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 764028b to 4b648ee Compare February 21, 2023 11:54
@ivoanjo
Copy link
Member

ivoanjo commented Feb 21, 2023

Any thoughts on how to test this? There's quite a bit of non-trivial logic in auto_inject.rb, so it would be great to have some tests that give us confidence that we don't accidentally break it as we change things.

@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2023

Codecov Report

Merging #2606 (befe4f7) into master (d76de94) will increase coverage by 0.00%.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #2606   +/-   ##
=======================================
  Coverage   98.08%   98.08%           
=======================================
  Files        1160     1160           
  Lines       63676    63678    +2     
  Branches     2849     2849           
=======================================
+ Hits        62457    62459    +2     
  Misses       1219     1219           
Impacted Files Coverage Δ
spec/ddtrace/release_gem_spec.rb 100.00% <ø> (ø)
...ec/datadog/tracing/contrib/sidekiq/patcher_spec.rb 96.00% <0.00%> (-4.00%) ⬇️
lib/datadog/core/workers/polling.rb 96.55% <0.00%> (-3.45%) ⬇️
spec/datadog/profiling/ext/forking_spec.rb 100.00% <0.00%> (+0.72%) ⬆️
lib/datadog/core/diagnostics/environment_logger.rb 98.48% <0.00%> (+0.79%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

# and auto instrument Ruby applications in containerized environments.
FROM busybox

ARG UID=10000
Copy link
Member

Choose a reason for hiding this comment

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

Why is the user id set to 10000? Any reason for this specific value?

Copy link
Member

Choose a reason for hiding this comment

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

@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch 5 times, most recently from 3901487 to 8d3e847 Compare February 27, 2023 15:30
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 8d3e847 to f656a00 Compare February 27, 2023 15:32
@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 84f7128 to a9bfad6 Compare February 27, 2023 17:36
Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

Looks solid! Let's get this out and hear the feedback!

puts "[DATADOG LIB INJECTION] #{output}"
end
rescue => e
puts "[DATADOG LIB INJECTION] trial error: #{e}"
Copy link
Member

Choose a reason for hiding this comment

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

Trial error? What does it mean?

Copy link
Contributor Author

@TonyCTHsu TonyCTHsu Feb 28, 2023

Choose a reason for hiding this comment

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

The ruby script here is conducting a trial for adding ddtrace into the bundle. The trial could be success or not and then cleanup the filesystem. I added this to be safe if there is an exception thrown during the trial but I don't see it coming.

Copy link
Member

Choose a reason for hiding this comment

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

I think customers may have the same question, and I suggest that the answer is part of the error message, not just a comment here :)

Copy link
Member

@GustavoCaso GustavoCaso left a comment

Choose a reason for hiding this comment

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

Great work

Copy link
Member

@ivoanjo ivoanjo left a comment

Choose a reason for hiding this comment

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

Left a few notes. I wouldn't say my feedback is blocking, but please do consider looking into it before we release this to customers.

Especially the current log messages I think need a bit of love.

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about this -- does the current test action still require write permissions? Is this perhaps a left-over from an example/another action we started from?

lib-injection/auto_inject.rb Outdated Show resolved Hide resolved
lib-injection/auto_inject.rb Outdated Show resolved Hide resolved
lib-injection/auto_inject.rb Outdated Show resolved Hide resolved
lib-injection/auto_inject.rb Show resolved Hide resolved
lib-injection/auto_inject.rb Outdated Show resolved Hide resolved
require 'fileutils'

begin
# Copies for trial
Copy link
Member

Choose a reason for hiding this comment

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

Consider explaining here in a bit more detail why we're doing this

lib-injection/auto_inject.rb Outdated Show resolved Hide resolved
puts "[DATADOG LIB INJECTION] #{output}"
end
rescue => e
puts "[DATADOG LIB INJECTION] trial error: #{e}"
Copy link
Member

Choose a reason for hiding this comment

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

I think customers may have the same question, and I suggest that the answer is part of the error message, not just a comment here :)

puts "[DATADOG LIB INJECTION] LoadError: #{e}"
rescue Exception => e
puts "[DATADOG LIB INJECTION] Exception: #{e}"
end
Copy link
Member

Choose a reason for hiding this comment

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

I had left an earlier comment on this PR, that perhaps you missed but -- I think we're missing some specs for this. We do have some coverage via the system tests, but consider testing some or all of the behaviors here using RSpec as well, to give us more confidence when changing this script.

@TonyCTHsu TonyCTHsu force-pushed the tonycthsu/lib-injection branch from 4dcf76c to 0499917 Compare February 28, 2023 15:30
@TonyCTHsu TonyCTHsu merged commit f39b81b into master Feb 28, 2023
@TonyCTHsu TonyCTHsu deleted the tonycthsu/lib-injection branch February 28, 2023 16:51
@github-actions github-actions bot added this to the 1.10.0 milestone Feb 28, 2023
@TonyCTHsu TonyCTHsu mentioned this pull request Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants