Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions server/limit_rate_gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,3 @@ func (s *Server) CheckLimitRateAndSleep() {
}
}

// CheckLimitRateAndAbortRequest checks the api rate and abort the request if needed
func (s *Server) CheckLimitRateAndAbortRequest() bool {
s.Logger.Info("Checking the rate limit on Github and will abort request if need...")

client := newGithubClient(s.Config.GithubAccessToken)
rate, _, err := client.RateLimits(context.Background())
if err != nil {
s.Logger.WithError(err).Error("Error getting the rate limit")
time.Sleep(30 * time.Second)
return false
}
s.Logger.WithFields(logrus.Fields{
"Remaining Rate": rate.Core.Remaining,
"Limit Rate": rate.Core.Limit,
}).Info("Current rate limit")
if rate.Core.Remaining <= s.Config.GitHubTokenReserve {
s.Logger.Error("Request will be aborted...")
return true
}
return false
}
14 changes: 13 additions & 1 deletion server/push_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ func (s *Server) handlePushEvent(event *github.PushEvent) {
// Release-branch push trigger was removed; release stabilization is covered by PR-label E2E and CMT.

if s.Config.E2EAutoTriggerOnMaster && (branch == "master" || branch == "main") {
logger.WithField("type", "master_main").Info("Master/main branch detected, triggering E2E tests")
sha := ""
if event.GetHeadCommit() != nil {
sha = event.GetHeadCommit().GetID()
}
logger.WithFields(logrus.Fields{
"type": "master_main",
"sha": sha,
}).Info("Master/main branch detected, triggering E2E tests")
go s.handlePushEventE2E(event, branch)
return
}
Expand Down Expand Up @@ -94,6 +101,7 @@ func (s *Server) handlePushEventE2E(event *github.PushEvent, branch string) {

if !isDesktop && !isMobile {
logger.Warn("Repository is neither desktop nor mobile, skipping E2E tests")
s.notifyMattermost("E2E on %s %s (%s) skipped: repo is neither mobile nor desktop", repoName, branch, sha)
return
}

Expand All @@ -104,10 +112,12 @@ func (s *Server) handlePushEventE2E(event *github.PushEvent, branch string) {

if sha == "" {
logger.Error("Push event has no commit SHA, skipping E2E dispatch")
s.notifyMattermost("E2E on %s %s did not run: push event had no commit SHA", repoName, branch)
return
}

logger.WithField("instanceType", instanceType).Info("Creating E2E instances for push event")
s.notifyMattermost("E2E on %s %s (%s): received push — provisioning %s test servers", repoName, branch, sha, instanceType)

instances, err := s.createMultipleE2EInstancesForPushEvent(repoName, instanceType, branch)
if err != nil {
Expand All @@ -125,6 +135,7 @@ func (s *Server) handlePushEventE2E(event *github.PushEvent, branch string) {
}

logger.WithField("instanceCount", len(instances)).Info("E2E instances created successfully")
s.notifyMattermost("E2E on %s %s (%s): provisioned %d test servers — dispatching workflow", repoName, branch, sha, len(instances))

// Key on the branch HEAD resolved now (just before dispatch), not the push SHA: the
// dispatched (ref=branch) run reports its head_sha as the branch HEAD at dispatch time,
Expand Down Expand Up @@ -157,6 +168,7 @@ func (s *Server) handlePushEventE2E(event *github.PushEvent, branch string) {
}

logger.Info("E2E workflow triggered successfully and instances tracked for cleanup")
s.notifyMattermost("E2E on %s %s (%s): workflow dispatched successfully (%d servers)", repoName, branch, sha, len(instances))
}

// createMultipleE2EInstancesForPushEvent creates all platform instances in parallel.
Expand Down
8 changes: 3 additions & 5 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,9 @@ func (s *Server) ping(w http.ResponseWriter, r *http.Request) {
}

func (s *Server) githubEvent(w http.ResponseWriter, r *http.Request) {
overLimit := s.CheckLimitRateAndAbortRequest()
if overLimit {
return
}

// Do not gate webhook ingest on GitHub API rate reserve. A silent abort here
// drops the delivery forever (GitHub does not auto-retry), so main-push E2E
// never starts and nothing is logged. Rate limiting belongs on outbound calls.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
buf, _ := io.ReadAll(r.Body)

receivedHash := strings.SplitN(r.Header.Get("X-Hub-Signature"), "=", 2)
Expand Down
5 changes: 5 additions & 0 deletions server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import (
)

func (s *Server) logErrorToMattermost(msg string, args ...interface{}) {
s.notifyMattermost(msg, args...)
}

// notifyMattermost posts a lifecycle/status message to the configured webhook.
func (s *Server) notifyMattermost(msg string, args ...interface{}) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
if s.Config.MattermostWebhookURL == "" {
s.Logger.Warn("No Mattermost webhook URL set: unable to send message")
return
Expand Down
Loading