Skip to content

Commit

Permalink
fix: logging (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk authored Jun 20, 2024
1 parent 62c4225 commit 4fd820a
Show file tree
Hide file tree
Showing 337 changed files with 2,014 additions and 1,689 deletions.
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

0 comments on commit 4fd820a

Please sign in to comment.