-
Notifications
You must be signed in to change notification settings - Fork 462
sci: add git metadata from artifacts support #1646
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
Conversation
NB: Don't merge until APM Intake team deploy corresponded changes! |
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.
Thanks! I'll have a closer look at the profiler part soon, but I have a thought for a different way to work around needing to support Go 1.17.
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.
Okay, I looked over this more for the profiling part. I like that you've de-duplicated the tag logic. There's one small change we should do for tags (see my comment) and then we should be good to go for the profiling part of this change :)
11adc10
to
26fe827
Compare
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.
Some quick feedback. Didn't do a full review.
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.
Thanks! Approved, with one small question about how DD_TAGS
is handled an an optional suggestion for making the test code a little shorter.
profiler/upload_test.go
Outdated
|
||
t.Run("git-metadata-from-dd-tags", func(t *testing.T) { | ||
maininternal.ResetGitMetadataTags() | ||
os.Setenv(maininternal.EnvDDTags, "git.commit.sha:123456789ABCD git.repository_url:github.com/user/repo go_path:somepath") |
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.
These os.Setenv
calls followed by defer os.Unsetenv
can be replaced by t.Setenv
calls. This saves you some lines of code, and also handles corner cases better, like re-setting the env var to its previous value if it had one.
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.
Thanks!
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.
LGTM. A few nits and one warning, but that can be dealt with in a follow-up PR.
res := make(map[string]string) | ||
tags := GetGitMetadataTags() | ||
|
||
updateTags(res, TraceTagRepositoryURL, tags[TagRepositoryURL]) | ||
updateTags(res, TraceTagCommitSha, tags[TagCommitSha]) | ||
updateTags(res, TraceTagGoPath, tags[TagGoPath]) | ||
|
||
return res |
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.
NIT: This could be simplified.
res := make(map[string]string) | |
tags := GetGitMetadataTags() | |
updateTags(res, TraceTagRepositoryURL, tags[TagRepositoryURL]) | |
updateTags(res, TraceTagCommitSha, tags[TagCommitSha]) | |
updateTags(res, TraceTagGoPath, tags[TagGoPath]) | |
return res | |
tags := GetGitMetadataTags() | |
return map[string]string{ | |
TraceTagRepositoryURL: tags[TagRepositoryURL], | |
TraceTagCommitSha: tags[TagCommitSha], | |
TraceTagGoPath: tags[TagGoPath], | |
} |
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.
Thanks, but it will not work, updateTags has some checks (e.g. it will not add empty strings)
func updateTags(tags map[string]string, key string, value string) { | ||
if _, ok := tags[key]; !ok && value != "" { | ||
tags[key] = value | ||
} | ||
} | ||
|
||
func updateAllTags(tags map[string]string, newtags map[string]string) { | ||
for k, v := range newtags { | ||
updateTags(tags, k, v) | ||
} | ||
} |
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.
NIT: This code doesn't really seem to benefit from being split into two functions. The naming of the methods implies that there is tag specific logic happening. But it's really just a simple map merging operation. Maybe a rename and putting it all into a single method would be better?
func updateTags(tags map[string]string, key string, value string) { | |
if _, ok := tags[key]; !ok && value != "" { | |
tags[key] = value | |
} | |
} | |
func updateAllTags(tags map[string]string, newtags map[string]string) { | |
for k, v := range newtags { | |
updateTags(tags, k, v) | |
} | |
} | |
func mergeNewKeys(dst map[string]string, src map[string]string) { | |
for k, v := range src { | |
if _, ok := dst[k]; !ok && v != "" { | |
dst[k] = v | |
} | |
} | |
} |
It's also not clear to me why values from src are ignored if they are ""
? Is there a real use case for this?
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.
It's also not clear to me why values from src are ignored if they are ""? Is there a real use case for this?
It is for skip empty tags adding, they can appear e.g. because "" is default value for os.Getenv
updateAllTags(gitMetadataTags, getTagsFromBinary()) | ||
} | ||
|
||
return gitMetadataTags |
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.
WARN: The returned map is mutable which is dangerous. The caller might decide to add their own keys or even overwrite keys by accident.
return res | ||
} | ||
res[TagCommitSha] = commitSha | ||
res[TagGoPath] = goPath |
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.
NIT: No need for extra goPath
var.
res[TagGoPath] = goPath | |
res[TagGoPath] = info.Path |
[SC-1158] Add git metadata from artifacts support
What does this PR do?
Add three environment variables:
Add following steps:
Extract git metadata from version information from binary by means of the debug/buildinfo package:
During trace telemetry sending:
Add metadata tags to the first span of each chunk:
During profile telemetry sending:
Add metadata tags to each profile:
Motivation
Allow customers easily provide git metadata
Describe how to test/QA your changes
Check git.repository_url and git.commit.sha tags on traces/profiles DD pages
Reviewer's Checklist
Triage
milestone is set.