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

fix: logging #1145

Merged
merged 31 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6a41f5b
wip
wass3r May 31, 2024
5af9033
use logrus for gorm
wass3r May 31, 2024
8e48d76
use witherror
wass3r May 31, 2024
590d21e
add knobs for db logging
wass3r Jun 2, 2024
444e5d1
format is deprecated
wass3r Jun 2, 2024
ee5ed83
tweak logging for admin endpoint
wass3r Jun 3, 2024
44cedd1
add more logging
wass3r Jun 3, 2024
1de0d68
more logging on update/create events in post webhook
wass3rw3rk Jun 3, 2024
4625c8e
updated enqueue logging
wass3rw3rk Jun 3, 2024
30c1ef2
update logging messages for various components
wass3rw3rk Jun 5, 2024
15c3a83
moving things around a little
wass3r Jun 5, 2024
31bfa73
Merge branch 'main' into chore/logging
wass3r Jun 10, 2024
dd4205e
Merge branch 'main' into chore/logging
wass3r Jun 10, 2024
97485ce
oops
wass3r Jun 10, 2024
900df92
Merge branch 'main' into chore/logging
wass3r Jun 10, 2024
9f5ebe6
use logger from context
wass3r Jun 16, 2024
0a77bbd
fix swagger annotations
wass3r Jun 16, 2024
c175d2c
Merge branch 'main' into chore/logging
wass3r Jun 16, 2024
9e8c996
fix tests
wass3r Jun 17, 2024
d5473b0
revert return status code change
wass3rw3rk Jun 17, 2024
708f551
linter says it's not similar code
wass3rw3rk Jun 17, 2024
fe6edcc
Merge branch 'main' into chore/logging
wass3rw3rk Jun 18, 2024
53edfd6
remove redundant wording (feedback)
wass3rw3rk Jun 18, 2024
6038bcd
use %s over %#q (feedback)
wass3rw3rk Jun 18, 2024
3c55bab
fix panic - use Entry, not Logger
wass3r Jun 20, 2024
2c8afee
info -> debug in webhook/post (feedback)
wass3r Jun 20, 2024
2508d5f
consistent order (feedback)
wass3r Jun 20, 2024
7699745
secret creation log adjust (feedback)
wass3r Jun 20, 2024
924390d
consistent nameing (feedback)
wass3rw3rk Jun 20, 2024
e7d9fd3
reword
wass3rw3rk Jun 20, 2024
e1c4e37
debug -> info on auth/token activity
wass3rw3rk Jun 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
28 changes: 23 additions & 5 deletions api/admin/build.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code
package admin

import (
Expand Down Expand Up @@ -50,11 +49,13 @@ import (

// AllBuildsQueue represents the API handler to get running and pending builds.
func AllBuildsQueue(c *gin.Context) {
l := c.MustGet("logger").(*logrus.Entry)

l.Debug("platform admin: reading running and pending builds")

// capture middleware values
ctx := c.Request.Context()

logrus.Info("Admin: reading running and pending builds")

// default timestamp to 24 hours ago if user did not provide it as query parameter
after := c.DefaultQuery("after", strconv.FormatInt(time.Now().UTC().Add(-24*time.Hour).Unix(), 10))

Expand Down Expand Up @@ -103,11 +104,12 @@ func AllBuildsQueue(c *gin.Context) {

// UpdateBuild represents the API handler to update a build.
func UpdateBuild(c *gin.Context) {
logrus.Info("Admin: updating build in database")

// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: updating build")

// capture body from API request
input := new(types.Build)

Expand All @@ -120,6 +122,14 @@ func UpdateBuild(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"build": input.GetNumber(),
"build_id": input.GetID(),
"repo": util.EscapeValue(input.GetRepo().GetName()),
"repo_id": input.GetRepo().GetID(),
"org": util.EscapeValue(input.GetRepo().GetOrg()),
}).Debug("platform admin: attempting to update build")

// send API call to update the build
b, err := database.FromContext(c).UpdateBuild(ctx, input)
if err != nil {
Expand All @@ -130,5 +140,13 @@ func UpdateBuild(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"build": b.GetNumber(),
"build_id": b.GetID(),
"repo": b.GetRepo().GetName(),
"repo_id": b.GetRepo().GetID(),
"org": b.GetRepo().GetOrg(),
}).Info("platform admin: updated build")

c.JSON(http.StatusOK, b)
}
15 changes: 8 additions & 7 deletions api/admin/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/sirupsen/logrus"

"github.com/go-vela/server/database"
"github.com/go-vela/server/router/middleware/user"
"github.com/go-vela/server/util"
"github.com/go-vela/types"
"github.com/go-vela/types/constants"
Expand Down Expand Up @@ -60,10 +59,10 @@ import (
// CleanResources represents the API handler to update stale resources.
func CleanResources(c *gin.Context) {
// capture middleware values
u := user.Retrieve(c)
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

logrus.Infof("platform admin %s: updating pending resources in database", u.GetName())
l.Debug("platform admin: cleaning resources")

// default error message
msg := "build cleaned by platform admin"
Expand All @@ -82,7 +81,7 @@ func CleanResources(c *gin.Context) {

// if a message is provided, set the error message to that
if input.Message != nil {
msg = *input.Message
msg = util.EscapeValue(*input.Message)
}

// capture before query parameter, default to max build timeout
Expand All @@ -105,7 +104,7 @@ func CleanResources(c *gin.Context) {
return
}

logrus.Infof("platform admin %s: cleaned %d builds in database", u.GetName(), builds)
l.Debugf("platform admin: cleaned %d builds", builds)

// clean executables
executables, err := database.FromContext(c).CleanBuildExecutables(ctx)
Expand All @@ -117,6 +116,8 @@ func CleanResources(c *gin.Context) {
return
}

l.Debugf("platform admin: cleaned %d executables", executables)

// clean services
services, err := database.FromContext(c).CleanServices(ctx, msg, before)
if err != nil {
Expand All @@ -127,7 +128,7 @@ func CleanResources(c *gin.Context) {
return
}

logrus.Infof("platform admin %s: cleaned %d services in database", u.GetName(), services)
l.Debugf("platform admin: cleaned %d services", services)

// clean steps
steps, err := database.FromContext(c).CleanSteps(ctx, msg, before)
Expand All @@ -139,7 +140,7 @@ func CleanResources(c *gin.Context) {
return
}

logrus.Infof("platform admin %s: cleaned %d steps in database", u.GetName(), steps)
l.Debugf("platform admin: cleaned %d steps", steps)

c.JSON(http.StatusOK, fmt.Sprintf("%d builds cleaned. %d executables cleaned. %d services cleaned. %d steps cleaned.", builds, executables, services, steps))
}
14 changes: 11 additions & 3 deletions api/admin/hook.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code
package admin

import (
Expand Down Expand Up @@ -51,11 +50,12 @@ import (

// UpdateHook represents the API handler to update a hook.
func UpdateHook(c *gin.Context) {
logrus.Info("Admin: updating hook in database")

// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: updating hook")

// capture body from API request
input := new(library.Hook)

Expand All @@ -68,6 +68,10 @@ func UpdateHook(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"hook_id": input.GetID(),
}).Debug("platform admin: attempting to update hook")

// send API call to update the hook
h, err := database.FromContext(c).UpdateHook(ctx, input)
if err != nil {
Expand All @@ -78,5 +82,9 @@ func UpdateHook(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"hook_id": h.GetID(),
}).Info("platform admin: hook updated")

c.JSON(http.StatusOK, h)
}
18 changes: 15 additions & 3 deletions api/admin/repo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code
package admin

import (
Expand Down Expand Up @@ -51,11 +50,12 @@ import (

// UpdateRepo represents the API handler to update a repo.
func UpdateRepo(c *gin.Context) {
logrus.Info("Admin: updating repo in database")

// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: updating repo")

// capture body from API request
input := new(types.Repo)

Expand All @@ -68,6 +68,12 @@ func UpdateRepo(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"org": util.EscapeValue(input.GetOrg()),
"repo": util.EscapeValue(input.GetName()),
"repo_id": input.GetID(),
}).Debug("platform admin: attempting to update repo")

// send API call to update the repo
r, err := database.FromContext(c).UpdateRepo(ctx, input)
if err != nil {
Expand All @@ -78,5 +84,11 @@ func UpdateRepo(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"org": r.GetOrg(),
"repo": r.GetName(),
"repo_id": r.GetID(),
}).Info("platform admin: repo updated")

c.JSON(http.StatusOK, r)
}
4 changes: 3 additions & 1 deletion api/admin/rotate_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import (
// RotateOIDCKeys represents the API handler to
// rotate RSA keys in the OIDC provider service.
func RotateOIDCKeys(c *gin.Context) {
logrus.Info("Admin: rotating keys for OIDC provider")
l := c.MustGet("logger").(*logrus.Entry)

l.Info("platform admin: rotating keys for OIDC provider")

// capture middleware values
ctx := c.Request.Context()
Expand Down
24 changes: 21 additions & 3 deletions api/admin/secret.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: Apache-2.0

//nolint:dupl // ignore similar code
package admin

import (
Expand Down Expand Up @@ -51,11 +50,12 @@ import (

// UpdateSecret represents the API handler to update a secret.
func UpdateSecret(c *gin.Context) {
logrus.Info("Admin: updating secret in database")

// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: updating secret")

// capture body from API request
input := new(library.Secret)

Expand All @@ -68,6 +68,15 @@ func UpdateSecret(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"secret_id": input.GetID(),
"secret_org": util.EscapeValue(input.GetOrg()),
"secret_repo": util.EscapeValue(input.GetRepo()),
"secret_type": util.EscapeValue(input.GetType()),
"secret_name": util.EscapeValue(input.GetName()),
"secret_team": util.EscapeValue(input.GetTeam()),
}).Debug("platform admin: attempting to update secret")

// send API call to update the secret
s, err := database.FromContext(c).UpdateSecret(ctx, input)
if err != nil {
Expand All @@ -78,5 +87,14 @@ func UpdateSecret(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"secret_id": s.GetID(),
"secret_org": s.GetOrg(),
"secret_repo": s.GetRepo(),
"secret_type": s.GetType(),
"secret_name": s.GetName(),
"secret_team": s.GetTeam(),
}).Info("platform admin: secret updated")

c.JSON(http.StatusOK, s)
}
15 changes: 13 additions & 2 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ import (

// UpdateService represents the API handler to update a service.
func UpdateService(c *gin.Context) {
logrus.Info("Admin: updating service in database")

// capture middleware values
l := c.MustGet("logger").(*logrus.Entry)
ctx := c.Request.Context()

l.Debug("platform admin: updating service")

// capture body from API request
input := new(library.Service)

Expand All @@ -69,6 +70,11 @@ func UpdateService(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"service_id": input.GetID(),
"service": util.EscapeValue(input.GetName()),
}).Debug("platform admin: attempting to update service")

// send API call to update the service
s, err := database.FromContext(c).UpdateService(ctx, input)
if err != nil {
Expand All @@ -79,5 +85,10 @@ func UpdateService(c *gin.Context) {
return
}

l.WithFields(logrus.Fields{
"service_id": s.GetID(),
"service": s.GetName(),
}).Info("platform admin: updated service")

c.JSON(http.StatusOK, s)
}
Loading
Loading