-
Notifications
You must be signed in to change notification settings - Fork 505
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
metrics: add build command duration metric #2225
Merged
Merged
Changes from all commits
Commits
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
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
package confutil | ||
|
||
import ( | ||
"crypto/rand" | ||
"encoding/hex" | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
) | ||
|
||
var nodeIdentifierMu sync.Mutex | ||
|
||
func TryNodeIdentifier(configDir string) (out string) { | ||
nodeIdentifierMu.Lock() | ||
defer nodeIdentifierMu.Unlock() | ||
sessionFile := filepath.Join(configDir, ".buildNodeID") | ||
if _, err := os.Lstat(sessionFile); err != nil { | ||
if os.IsNotExist(err) { // create a new file with stored randomness | ||
b := make([]byte, 8) | ||
if _, err := rand.Read(b); err != nil { | ||
return out | ||
} | ||
if err := os.WriteFile(sessionFile, []byte(hex.EncodeToString(b)), 0600); err != nil { | ||
return out | ||
} | ||
} | ||
} | ||
|
||
dt, err := os.ReadFile(sessionFile) | ||
if err == nil { | ||
return string(dt) | ||
} | ||
return | ||
} |
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.
These paths need to be normalized so they always generate same hash(Eg. made absolute).
As this is leaking the system paths and Git info it still needs the salt like #2185 (comment) . The multi-machine case doesn't apply anyway as system paths are different, and I don't think there is a way to implement it safely with some other way.
If the path is a URL then the URL should go into hash. If it is
-
then maybe workdir is better than just const character? (but it needs salt)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.
Since this code is in a new place, I don't have easy access to the node identifier anymore. I'd have to make that function public.
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've also now changed this so it will attempt to transform context path into a relative path. If a git directory is present, the relative path will be dependent on the root directory of the git repository.