From f5c639ae288bcb582ffe26a60e5880e76719b18d Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Wed, 10 Mar 2021 09:40:44 +0900 Subject: [PATCH] Make webhook-based autoscaler github event logs more operator-friendly (#384) Adds fields like `pullRequest.base.ref` and `checkRun.status` that are useful for verifying the autoscaling behaviour without browsing GitHub. Ref https://github.com/summerwind/actions-runner-controller/issues/377#issuecomment-794175312 --- .../horizontal_runner_autoscaler_webhook.go | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/controllers/horizontal_runner_autoscaler_webhook.go b/controllers/horizontal_runner_autoscaler_webhook.go index be9dff64..af373024 100644 --- a/controllers/horizontal_runner_autoscaler_webhook.go +++ b/controllers/horizontal_runner_autoscaler_webhook.go @@ -159,6 +159,13 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons e.Repo.Owner.GetType(), autoscaler.MatchPullRequestEvent(e), ) + + if pullRequest := e.PullRequest; pullRequest != nil { + log = log.WithValues( + "pullRequest.base.ref", e.PullRequest.Base.GetRef(), + "action", e.GetAction(), + ) + } case *gogithub.CheckRunEvent: target, err = autoscaler.getScaleUpTarget( context.TODO(), @@ -168,6 +175,13 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons e.Repo.Owner.GetType(), autoscaler.MatchCheckRunEvent(e), ) + + if checkRun := e.GetCheckRun(); checkRun != nil { + log = log.WithValues( + "checkRun.status", checkRun.GetStatus(), + "action", e.GetAction(), + ) + } case *gogithub.PingEvent: ok = true @@ -195,9 +209,11 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) Handle(w http.Respons } if target == nil { - msg := "no horizontalrunnerautoscaler to scale for this github event" + log.Info( + "Scale target not found. If this is unexpected, ensure that there is exactly one repository-wide or organizational runner deployment that matches this webhook event", + ) - log.Info(msg, "eventType", webhookType) + msg := "no horizontalrunnerautoscaler to scale for this github event" ok = true @@ -365,10 +381,6 @@ func (autoscaler *HorizontalRunnerAutoscalerGitHubWebhook) getScaleUpTarget(ctx return target, nil } - log.Info( - "Scale target not found. If this is unexpected, ensure that there is exactly one repository-wide or organizational runner deployment that matches this webhook event", - ) - return nil, nil }