Skip to content

Commit

Permalink
fix ff allocator for checks client (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayyush authored Jun 2, 2022
1 parent 81c96ea commit 96f4564
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 62 deletions.
2 changes: 1 addition & 1 deletion server/controllers/events/events_controller_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ func (t *testGithubClient) GetRepoStatuses(repo models.Repo, pull models.PullReq
return []*github.RepoStatus{}, nil

}
func (t *testGithubClient) GetRepoChecks(repo models.Repo, pull models.PullRequest) ([]*github.CheckRun, error) {
func (t *testGithubClient) GetRepoChecks(repo models.Repo, commitSHA string) ([]*github.CheckRun, error) {
return []*github.CheckRun{}, nil

}
Expand Down
8 changes: 4 additions & 4 deletions server/events/vcs/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type IGithubClient interface {

GetContents(owner, repo, branch, path string) ([]byte, error)
GetRepoStatuses(repo models.Repo, pull models.PullRequest) ([]*github.RepoStatus, error)
GetRepoChecks(repo models.Repo, pull models.PullRequest) ([]*github.CheckRun, error)
GetRepoChecks(repo models.Repo, commitSHA string) ([]*github.CheckRun, error)
}

// InstrumentedGithubClient should delegate to the underlying InstrumentedClient for vcs provider-agnostic
Expand Down Expand Up @@ -118,7 +118,7 @@ func (c *InstrumentedGithubClient) GetPullRequestFromName(repoName string, repoO
return pull, err
}

func (c *InstrumentedGithubClient) GetRepoChecks(repo models.Repo, pull models.PullRequest) ([]*github.CheckRun, error) {
func (c *InstrumentedGithubClient) GetRepoChecks(repo models.Repo, commitSHA string) ([]*github.CheckRun, error) {
scope := c.StatsScope.SubScope("get_repo_checks")

executionTime := scope.Timer(metrics.ExecutionTimeMetric).Start()
Expand All @@ -127,7 +127,7 @@ func (c *InstrumentedGithubClient) GetRepoChecks(repo models.Repo, pull models.P
executionSuccess := scope.Counter(metrics.ExecutionSuccessMetric)
executionError := scope.Counter(metrics.ExecutionErrorMetric)

statuses, err := c.GhClient.GetRepoChecks(repo, pull.HeadCommit)
statuses, err := c.GhClient.GetRepoChecks(repo, commitSHA)

if err != nil {
executionError.Inc(1)
Expand All @@ -137,7 +137,7 @@ func (c *InstrumentedGithubClient) GetRepoChecks(repo models.Repo, pull models.P
executionSuccess.Inc(1)

//TODO: thread context and use related logging methods.
c.Logger.Info("fetched vcs repo checks", fields.PullRequest(pull))
c.Logger.Info("fetched vcs repo checks", map[string]interface{}{"commitSHA": commitSHA})

return statuses, err
}
Expand Down
4 changes: 2 additions & 2 deletions server/events/vcs/lyft/pull_status_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const LockValue = "lock"
type PullClient interface {
GetPullRequest(repo models.Repo, pullNum int) (*github.PullRequest, error)
GetRepoStatuses(repo models.Repo, pull models.PullRequest) ([]*github.RepoStatus, error)
GetRepoChecks(repo models.Repo, pull models.PullRequest) ([]*github.CheckRun, error)
GetRepoChecks(repo models.Repo, commitSHA string) ([]*github.CheckRun, error)
PullIsApproved(repo models.Repo, pull models.PullRequest) (models.ApprovalStatus, error)
}

Expand Down Expand Up @@ -48,7 +48,7 @@ func (s *SQBasedPullStatusFetcher) FetchPullStatus(repo models.Repo, pull models
return pullStatus, errors.Wrap(err, "fetching repo statuses")
}

checks, err := s.client.GetRepoChecks(repo, pull)
checks, err := s.client.GetRepoChecks(repo, pull.HeadCommit)
if err != nil {
return pullStatus, errors.Wrap(err, "fetching repo checks")
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 22 additions & 37 deletions server/events/vcs/mocks/mock_IGithub_client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 13 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
var bitbucketCloudClient *bitbucketcloud.Client
var bitbucketServerClient *bitbucketserver.Client
var azuredevopsClient *vcs.AzureDevopsClient
var featureAllocator feature.Allocator

mergeabilityChecker := vcs.NewLyftPullMergeabilityChecker(userConfig.VCSStatusName)

Expand Down Expand Up @@ -204,18 +205,6 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
return nil, errors.Wrapf(err, "instantiating metrics scope")
}

featureAllocator, err := feature.NewGHSourcedAllocator(
feature.RepoConfig{
Owner: userConfig.FFOwner,
Repo: userConfig.FFRepo,
Branch: userConfig.FFBranch,
Path: userConfig.FFPath,
}, githubClient, ctxLogger)

if err != nil {
return nil, errors.Wrap(err, "initializing feature allocator")
}

if userConfig.GithubUser != "" || userConfig.GithubAppID != 0 {
supportedVCSHosts = append(supportedVCSHosts, models.Github)
if userConfig.GithubUser != "" {
Expand Down Expand Up @@ -252,6 +241,18 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) {
return nil, err
}

featureAllocator, err = feature.NewGHSourcedAllocator(
feature.RepoConfig{
Owner: userConfig.FFOwner,
Repo: userConfig.FFRepo,
Branch: userConfig.FFBranch,
Path: userConfig.FFPath,
}, rawGithubClient, ctxLogger)

if err != nil {
return nil, errors.Wrap(err, "initializing feature allocator")
}

// [WENGINES-4643] TODO: Remove this wrapped client once github checks is stable
checksWrapperGhClient := &lyft_checks.ChecksClientWrapper{
FeatureAllocator: featureAllocator,
Expand Down

0 comments on commit 96f4564

Please sign in to comment.