Skip to content

Commit

Permalink
Adjust some logging statements
Browse files Browse the repository at this point in the history
* Change metric type log level to debug

  Logging metric style info is better to handle properly; since this
  is one of very few instances it is changed to debug level for now.
  Future goal is to add tracing and metric instrumentation for such
  information.

* Log event type once at start of handle function

* Drop now duplicate log lines of the event type

* Consistently add event type into PR logger

  Once PR logger includes the event_type. For consistency add the same
  field to the other PR loggers.

* Remove now unused eventType argument
  • Loading branch information
hnnsgstfssn committed Oct 28, 2024
1 parent 195488c commit 2427f3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func findArgocdAppByManifestPathAnnotation(ctx context.Context, componentPath st
getAppsStart := time.Now()
allRepoApps, err := appClient.List(ctx, &appQuery)
getAppsDuration := time.Since(getAppsStart).Milliseconds()
log.Infof("Got %v ArgoCD applications for repo %s in %v ms", len(allRepoApps.Items), repo, getAppsDuration)
log.Debugf("Got %v ArgoCD applications for repo %s in %v ms", len(allRepoApps.Items), repo, getAppsDuration)
if err != nil {
return nil, err
}
Expand Down
21 changes: 11 additions & 10 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ func ReciveEventFile(eventType string, eventFilePath string, mainGhClientCache *
r.Header.Set("Content-Type", "application/json")
r.Header.Set("X-GitHub-Event", eventType)

handleEvent(eventPayloadInterface, mainGhClientCache, prApproverGhClientCache, r, payload, eventType)
handleEvent(eventPayloadInterface, mainGhClientCache, prApproverGhClientCache, r, payload)
}

// ReciveWebhook is the main entry point for the webhook handling it starts parases the webhook payload and start a thread to handle the event success/failure are dependant on the payload parsing only
Expand All @@ -363,22 +363,23 @@ func ReciveWebhook(r *http.Request, mainGhClientCache *lru.Cache[string, GhClien
}
prom.InstrumentWebhookHit("successful")

go handleEvent(eventPayloadInterface, mainGhClientCache, prApproverGhClientCache, r, payload, eventType)
go handleEvent(eventPayloadInterface, mainGhClientCache, prApproverGhClientCache, r, payload)
return nil
}

func handleEvent(eventPayloadInterface interface{}, mainGhClientCache *lru.Cache[string, GhClientPair], prApproverGhClientCache *lru.Cache[string, GhClientPair], r *http.Request, payload []byte, eventType string) {
func handleEvent(eventPayloadInterface interface{}, mainGhClientCache *lru.Cache[string, GhClientPair], prApproverGhClientCache *lru.Cache[string, GhClientPair], r *http.Request, payload []byte) {
// We don't use the request context as it might have a short deadline and we don't want to stop event handling based on that
// But we do want to stop the event handling after a certain point, so:
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
var mainGithubClientPair GhClientPair
var approverGithubClientPair GhClientPair

log.Infof("Handling event type %T", eventPayloadInterface)

switch eventPayload := eventPayloadInterface.(type) {
case *github.PushEvent:
// this is a commit push, do something with it?
log.Infoln("is PushEvent")
repoOwner := *eventPayload.Repo.Owner.Login
mainGithubClientPair.GetAndCache(mainGhClientCache, "GITHUB_APP_ID", "GITHUB_APP_PRIVATE_KEY_PATH", "GITHUB_OAUTH_TOKEN", repoOwner, ctx)

Expand All @@ -400,8 +401,9 @@ func handleEvent(eventPayloadInterface interface{}, mainGhClientCache *lru.Cache
log.Infof("is PullRequestEvent(%s)", *eventPayload.Action)

prLogger := log.WithFields(log.Fields{
"repo": *eventPayload.Repo.Owner.Login + "/" + *eventPayload.Repo.Name,
"prNumber": *eventPayload.PullRequest.Number,
"repo": *eventPayload.Repo.Owner.Login + "/" + *eventPayload.Repo.Name,
"prNumber": *eventPayload.PullRequest.Number,
"event_type": "pr",
})

repoOwner := *eventPayload.Repo.Owner.Login
Expand Down Expand Up @@ -430,10 +432,10 @@ func handleEvent(eventPayloadInterface interface{}, mainGhClientCache *lru.Cache
mainGithubClientPair.GetAndCache(mainGhClientCache, "GITHUB_APP_ID", "GITHUB_APP_PRIVATE_KEY_PATH", "GITHUB_OAUTH_TOKEN", repoOwner, ctx)

botIdentity, _ := GetBotGhIdentity(mainGithubClientPair.v4Client, ctx)
log.Infof("Actionable event type %s\n", eventType)
prLogger := log.WithFields(log.Fields{
"repo": *eventPayload.Repo.Owner.Login + "/" + *eventPayload.Repo.Name,
"prNumber": *eventPayload.Issue.Number,
"repo": *eventPayload.Repo.Owner.Login + "/" + *eventPayload.Repo.Name,
"prNumber": *eventPayload.Issue.Number,
"event_type": "issue_comment",
})
// Ignore comment events sent by the bot (this is about who trigger the event not who wrote the comment)
if *eventPayload.Sender.Login != botIdentity {
Expand All @@ -453,7 +455,6 @@ func handleEvent(eventPayloadInterface interface{}, mainGhClientCache *lru.Cache
}

default:
log.Infof("Non-actionable event type %s", eventType)
return
}
}
Expand Down

0 comments on commit 2427f3e

Please sign in to comment.