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

feat(api/database)!: store deployment record in database for Vela-targeted deployments #1031

Merged
merged 42 commits into from
Dec 29, 2023

Conversation

claire1618
Copy link
Contributor

@claire1618 claire1618 commented Dec 22, 2023

When a repo has a lot of deployments historically, viewing them in the UI is cumbersome and slow.

The loading of deployments on the deployments tab in Vela takes a few more seconds to load than the other pages (schedules, secrets, audits...) even when there are no deployments for a repo. This is due to the way deployments are stored and retrieved.

The changes made in this pull request add a new database table so that we can store deployment information instead of having to go to the scm to retrieve them.

With these changes, any new deployments will be added to our database and pulled from there when requested, but old deployments are still pulled from GitHub.

@claire1618 claire1618 requested a review from a team as a code owner December 22, 2023 19:55
Copy link

codecov bot commented Dec 22, 2023

Codecov Report

Attention: 132 lines in your changes are missing coverage. Please review.

Comparison is base (2dd31d6) 67.79% compared to head (245a6db) 66.96%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1031      +/-   ##
==========================================
- Coverage   67.79%   66.96%   -0.84%     
==========================================
  Files         318      330      +12     
  Lines       13754    14074     +320     
==========================================
+ Hits         9325     9424      +99     
- Misses       3956     4169     +213     
- Partials      473      481       +8     
Files Coverage Δ
database/build/table.go 100.00% <ø> (ø)
database/database.go 63.38% <ø> (ø)
database/deployment/count.go 100.00% <100.00%> (ø)
database/deployment/count_repo.go 100.00% <100.00%> (ø)
database/deployment/delete.go 100.00% <100.00%> (ø)
database/deployment/index.go 100.00% <100.00%> (ø)
database/deployment/table.go 100.00% <100.00%> (ø)
router/middleware/logger.go 97.52% <100.00%> (+0.02%) ⬆️
scm/github/webhook.go 86.18% <100.00%> (+0.53%) ⬆️
api/schedule/update.go 0.00% <0.00%> (ø)
... and 11 more

@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0

package deployment

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
3-33 lines are duplicate of database/deployment/update.go:5-35 (dupl)

//
// Use of this source code is governed by the LICENSE file in this repository.

package deployment

Choose a reason for hiding this comment

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

🚫 [golangci] reported by reviewdog 🐶
5-35 lines are duplicate of database/deployment/create.go:3-33 (dupl)

database/deployment/delete.go Outdated Show resolved Hide resolved
database/deployment/deployment.go Outdated Show resolved Hide resolved
database/deployment/get.go Outdated Show resolved Hide resolved
database/deployment/table_test.go Outdated Show resolved Hide resolved
database/deployment/update.go Outdated Show resolved Hide resolved
database/deployment/get.go Outdated Show resolved Hide resolved
database/deployment/delete.go Outdated Show resolved Hide resolved
api/build/restart.go Outdated Show resolved Hide resolved
Copy link
Contributor

@plyr4 plyr4 left a comment

Choose a reason for hiding this comment

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

left a couple comments, looks great so far

Copy link
Contributor

@ecrupper ecrupper left a comment

Choose a reason for hiding this comment

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

Noting a few things here. Major one being the need for listing deployments endpoint to be repo-specific.

api/build/restart.go Outdated Show resolved Hide resolved
api/deployment/get.go Outdated Show resolved Hide resolved
api/deployment/list.go Outdated Show resolved Hide resolved
api/webhook/post.go Outdated Show resolved Hide resolved
api/webhook/post.go Outdated Show resolved Hide resolved
api/webhook/post.go Outdated Show resolved Hide resolved
} else {
d.SetBuilds(builds)
_, err := database.FromContext(c).UpdateDeployment(d)
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.

Should an error like this stop the build? Probably? Not sure though, so noting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im not too sure what to do for this?

scm/github/webhook.go Outdated Show resolved Hide resolved
Claire.Nicholas added 2 commits December 28, 2023 12:39
Copy link
Member

@wass3rw3rk wass3rw3rk left a comment

Choose a reason for hiding this comment

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

super minor things, otherwise nice work :D only other thing i noted was a few linter messages still, but hard to tell in GitHub UI if they are current.

api/deployment/get.go Outdated Show resolved Hide resolved
database/build/interface.go Outdated Show resolved Hide resolved
wass3rw3rk
wass3rw3rk previously approved these changes Dec 29, 2023
plyr4
plyr4 previously approved these changes Dec 29, 2023
dWithBs := []*library.Deployment{}

for _, deployment := range d {
b, _, err := database.FromContext(c).ListBuildsForDeployment(ctx, deployment, nil, 1, 3)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we delete the database function ListBuildsForDeployment? Can be a follow up PR but would be nice to remove any dead code.

ecrupper
ecrupper previously approved these changes Dec 29, 2023
wass3rw3rk
wass3rw3rk previously approved these changes Dec 29, 2023
@claire1618 claire1618 dismissed stale reviews from wass3rw3rk, ecrupper, and plyr4 via 16fc94c December 29, 2023 15:59
ecrupper
ecrupper previously approved these changes Dec 29, 2023
@claire1618 claire1618 merged commit a7cd07f into main Dec 29, 2023
13 of 15 checks passed
@claire1618 claire1618 deleted the feat/deploymentTable branch December 29, 2023 16:55
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.

5 participants