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

DDO-3377: Use CreatedAt instead of CommittedAt #398

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

katiewelch
Copy link
Contributor

@katiewelch katiewelch commented Dec 14, 2023

We are trying to recording the time between git pushes. We originally used the github webhooks push event - commit timestamp to record the time of the push (there is no webhook for the time when the push itself occurred).

If the developer pushes more than one commit at a time, it will record the time of the first commit. We noticed that for at least one developer, they had pushed more than one commit at once, but the commits were more than a month apart.

In order to not skew our data, we determined it would be better to use the CreatedAt field to calculate the time between pushes instead.

This change involves a database migration to remove the committed_at column from the git_commits table.

Testing for Database Migration
I tested this locally by

  1. starting up my local Sherlock. Doing this will run all the migrations and fail if there are any errors.
Screenshot 2023-12-14 at 2 23 45 PM
  1. using the golang-migrate/migrate tool to test run my up and down migrations. I used
    migrate -path sherlock/db/migrations -database 'postgres://sherlock:password@localhost:5432/sherlock?sslmode=disable' goto 68
    and
    migrate -path sherlock/db/migrations -database 'postgres://sherlock:password@localhost:5432/sherlock?sslmode=disable' goto 69
    to test down and up, respectively.
Screenshot 2023-12-14 at 2 23 16 PM

Testing for Webhook Handler
I tested following the instructions in the README.
For the 3rd command, I instead used
gh webhook forward --repo=broadinstitute/sherlock --events=push --url=http://localhost:8090/webhook --secret=foobar so that it would run for a push event instead of workflow_run.

  1. make local-up
Screenshot 2023-12-14 at 2 30 01 PM
  1. cd sherlock-webhook-proxy && FUNCTION_TARGET="HandleWebhook" IAP_TOKEN=$(thelma auth iap --echo) SHERLOCK_URL=http://localhost:8080 GITHUB_WEBHOOK_SECRET=foobar ALLOWED_GITHUB_ORGS=broadinstitute go run cmd/main.go
Screenshot 2023-12-14 at 2 30 30 PM

@katiewelch katiewelch requested a review from a team as a code owner December 14, 2023 16:28
Copy link

github-actions bot commented Dec 14, 2023

What's Changed


PUT /api/git-commits/v3
Request:

Changed content type : application/json

  • Deleted property committedAt (string)
Return Type:

Changed response : 201 Created

Created

  • Changed content type : application/json

    • Deleted property committedAt (string)

Copy link

github-actions bot commented Dec 14, 2023

Published image from d721744 (merge 9382556):

us-central1-docker.pkg.dev/dsp-artifact-registry/sherlock/sherlock:v0.2.55-9382556

Copy link

codecov bot commented Dec 14, 2023

Codecov Report

Merging #398 (d721744) into main (68f5de1) will increase coverage by 0.05%.
Report is 6 commits behind head on main.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #398      +/-   ##
==========================================
+ Coverage   68.56%   68.61%   +0.05%     
==========================================
  Files         165      165              
  Lines       10711    10703       -8     
==========================================
  Hits         7344     7344              
+ Misses       2864     2856       -8     
  Partials      503      503              
Files Coverage Δ
sherlock/internal/api/sherlock/git_commits_v3.go 0.00% <ø> (ø)
...ock/internal/api/sherlock/git_commits_v3_upsert.go 0.00% <0.00%> (ø)

... and 1 file with indirect coverage changes

Copy link
Contributor

@jack-r-warren jack-r-warren left a comment

Choose a reason for hiding this comment

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

thought: This PR does two things that normally would not be okay, but I think it is okay here:

One, the cloud function and the backend are being changed by the same PR, but the cloud function will get immediately auto-deployed (in practice, before we would've deployed the new Sherlock). This means Sherlock before this PR would receive some incoming git-commit requests lacking the CommittedAt field, which'll make it unhappy.

Two, this PR drops a column while it is still in use (both the old Sherlock and the new Sherlock will coexist briefly during an update). Old Sherlock would get very confused and unhappy if it tries to read or write the CommittedAt column if new Sherlock has already migrated and dropped it.

But... this table and everything here is completely isolated and we're going to throw out the data anyway, we're just moving fast to collect data. I don't think we should worry about those two notes I just made; who cares if we get an ugly row or two.

GitBranch string `json:"gitBranch"`
IsMainBranch bool `json:"isMainBranch"`
CommittedAt time.Time `json:"committedAt"`
CommonFields
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CommonFields

suggestion: I don't think we actually want to allow upserting the CommonFields, those are typically ready only (the underlying gorm.Model is handled by Gorm, so I actually don't know what would happen if you tried to manually set these)

@@ -54,15 +53,14 @@ func gitCommitsV3Upsert(ctx *gin.Context) {
var timeSince *uint

if len(previous) > 0 {
timeSince = utils.PointerTo(uint(body.CommittedAt.Sub(previous[0].CommittedAt).Seconds()))
timeSince = utils.PointerTo(uint(body.CreatedAt.Sub(previous[0].CreatedAt).Seconds()))
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Based on my comment above, the body won't have a .CreatedAt. Instead I think we should just use time.Now() (not leaving it as a GitHub suggestion because you'd need to import "time" too, which GoLand will do if you write it yourself)

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

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