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

Send push timings to the server #2152

Merged
merged 17 commits into from
Feb 21, 2025
Merged

Send push timings to the server #2152

merged 17 commits into from
Feb 21, 2025

Conversation

NikhilSinha1
Copy link
Contributor

Summary

We want to know about how long it takes to build and push images. If we are introducing something called "fast push", we should probably know if it is actually faster or not than the same thing through the standard push flow.

Test Plan

Do a push with the fast push flow and the standard push flow and see if they still work

@NikhilSinha1 NikhilSinha1 marked this pull request as ready for review February 14, 2025 19:58
@meatballhat meatballhat requested a review from a team February 15, 2025 02:33
Copy link
Contributor

@meatballhat meatballhat left a comment

Choose a reason for hiding this comment

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

⏱️👀

go.mod Outdated
toolchain go1.23.2
go 1.23.0

toolchain go1.23.6
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like maybe your asdf installation isn't happy 🤔 The toolchain should stay in lockstep with what is in .tool-versions.

Comment on lines 29 to 35
// Generate 256 bit random hash (4x64 bits) to use as an upload ID
for i := 0; i < 4; i++ {
// Ignoring the linter warning about math/rand/v2 not being cryptographically secure
// because this just needs to be a "unique enough" ID for a cache between when the
// push starts and ends, which should only be ~a week max.
imageID = fmt.Sprintf("%s%x", imageID, rand.Int64()) //nolint:gosec
}
Copy link
Contributor

Choose a reason for hiding this comment

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

  • moving this to a function would be nice 😁
  • I'm uncomfortable with this being random. Could it be deterministic instead? Isn't this ID assigned by the server side in a later step?
  • does rand.Int64 guarantee large enough int64 values for our needs? The docs claim the value will always be a 63 bit int, so I think the answer is "yes", but wanted to call it out.

Comment on lines 41 to 46
parts := strings.Split(imageMeta.ID, ":")
if len(parts) != 2 {
console.Warn("Image ID was not of the form sha:hash")
} else {
imageID = parts[1]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Ooh! Use strings.Cut instead!

Comment on lines 49 to 50
err = webClient.PostBuildStart(ctx, imageID, buildTime)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I don't see err being used later, so

Suggested change
err = webClient.PostBuildStart(ctx, imageID, buildTime)
if err != nil {
if err := webClient.PostBuildStart(ctx, imageID, buildTime); err != nil {

}

url := webBaseURL()
url.Path = strings.Join([]string{"", "api", "models", "build-start"}, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Given there's no variable data in this string, I think it should be a const instead.

defer resp.Body.Close()

if resp.StatusCode != http.StatusCreated {
return errors.New("Bad response from new version endpoint: " + strconv.Itoa(resp.StatusCode))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: it's not a huge deal in this context since the process is not long-lived, but errors.New should generally not be used like this. Instead, define a module-level var of the base error and then use error wrapping to include the variable bit.

Copy link
Contributor

@meatballhat meatballhat left a comment

Choose a reason for hiding this comment

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

Nice 🙌🏼 !

@NikhilSinha1 NikhilSinha1 merged commit 0c6c0be into main Feb 21, 2025
21 checks passed
@NikhilSinha1 NikhilSinha1 deleted the nikhil/push-timings-wiring branch February 21, 2025 01:11
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.

2 participants