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

[SDTEST-160] git commands telemetry #205

Merged
merged 5 commits into from
Jul 29, 2024

Conversation

anmarchenko
Copy link
Member

What does this PR do?
Adds telemetry metrics collection to git commands

Additional Notes
This change caused curious fail: one must not access Telemetry when the library is initialized. We previously collected environment tags during the library initialization stage, which might include using git commands. I made the environment tags collection lazy, so it does not happen until at least one span is traced.

How to test the change?
Unit tests are provided

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 96.81529% with 5 lines in your changes missing coverage. Please review.

Project coverage is 98.83%. Comparing base (9cd40ca) to head (6002775).

Files Patch % Lines
lib/datadog/ci/git/local_repository.rb 91.80% 5 Missing ⚠️
Additional details and impacted files
@@                          Coverage Diff                          @@
##           anmarchenko/telemetry_metrics_itr     #205      +/-   ##
=====================================================================
- Coverage                              98.86%   98.83%   -0.04%     
=====================================================================
  Files                                    249      251       +2     
  Lines                                  11279    11416     +137     
  Branches                                 503      509       +6     
=====================================================================
+ Hits                                   11151    11283     +132     
- Misses                                   128      133       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

res = nil

duration_ms = Core::Utils::Time.measure(:float_millisecond) do
res = exec_git_command("git ls-remote --get-url")

Choose a reason for hiding this comment

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

Small question: why not have exec_git_command() do the measuring and return some kind of tuple with result, duration, and status code? Or alternatively, you could pass the git command as a parameter and have the underlying method do the telemetry piece.

It would be a very modest win in code deduplication.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not a fan of DRY in general and I eager to accept code duplication every time over confusing behaviour.

Changing return of the method to include telemetry mixes 2 different concepts together: executing command and measuring it. If I return back to this code after 2 months, I will never remember why exec_git_command returns a tuple. What's worse, we measure only subset of git commands (for whatever reason). This means that these return values will be used in some cases but ignored in other and it will be absolutely impossible to explain why.

In this case deduplicating the code would completely break exec_git_command abstraction: I will take duplication over broken abstraction every day (like Sandi taught me! :) )

Choose a reason for hiding this comment

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

I ended up inserting a wrapped function for the Python tracer... but since I had to maintain backwards compatibility, I kept the original function as a wrapper of the new one, which may or may not have been the right move.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm fine with duplication for now, but I will refactor if it'll become painful in the future

Base automatically changed from anmarchenko/telemetry_metrics_itr to main July 29, 2024 07:54
@anmarchenko anmarchenko merged commit 1ab2fd2 into main Jul 29, 2024
25 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/telemetry_metrics_git_commands branch July 29, 2024 08:39
@github-actions github-actions bot added this to the 1.3.0 milestone Jul 29, 2024
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.

3 participants