-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a0e08db
telemetry helpers for git commands
anmarchenko bfef85f
implement git.command_errors metric
anmarchenko dca91a5
use bytesize in HTTP specs
anmarchenko 1ef24c9
Curious problem encountered: accessing telemetry during library initi…
anmarchenko 6002775
git commands telemetry
anmarchenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
module Datadog | ||
module CI | ||
module Git | ||
module Telemetry | ||
def self.git_command(command) | ||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_GIT_COMMAND, 1, tags_for_command(command)) | ||
end | ||
|
||
def self.git_command_errors(command, exit_code: nil, executable_missing: false) | ||
tags = tags_for_command(command) | ||
|
||
exit_code_tag_value = exit_code_for(exit_code: exit_code, executable_missing: executable_missing) | ||
tags[Ext::Telemetry::TAG_EXIT_CODE] = exit_code_tag_value if exit_code_tag_value | ||
|
||
Utils::Telemetry.inc(Ext::Telemetry::METRIC_GIT_COMMAND_ERRORS, 1, tags) | ||
end | ||
|
||
def self.git_command_ms(command, duration_ms) | ||
Utils::Telemetry.distribution(Ext::Telemetry::METRIC_GIT_COMMAND_MS, duration_ms, tags_for_command(command)) | ||
end | ||
|
||
def self.tags_for_command(command) | ||
{Ext::Telemetry::TAG_COMMAND => command} | ||
end | ||
|
||
def self.exit_code_for(exit_code: nil, executable_missing: false) | ||
return Ext::Telemetry::ExitCode::MISSING if executable_missing | ||
return exit_code.to_s if exit_code | ||
|
||
nil | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Datadog | ||
module CI | ||
module Git | ||
module Telemetry | ||
def self.git_command: (String command) -> void | ||
|
||
def self.git_command_errors: (String command, ?exit_code: Integer?, ?executable_missing: bool) -> void | ||
|
||
def self.git_command_ms: (String command, untyped duration_ms) -> void | ||
|
||
def self.tags_for_command: (String command) -> ::Hash[String, String] | ||
|
||
def self.exit_code_for: (?exit_code: Integer?, ?executable_missing: bool) -> String? | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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! :) )There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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