-
Notifications
You must be signed in to change notification settings - Fork 79
feat(zebra): gate resilient git checkout behind git_clone_slow_retry feature flag #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
393148d
feat(zebra): gate resilient git checkout behind git_clone_slow_retry …
skipi fee4acd
test(zebra): bump stubbed feature count after adding git_clone_slow_r…
skipi 2167e99
feat(zebra): only inject git_clone_slow_retry on cloud agents
skipi 683c489
Merge remote-tracking branch 'origin/main' into skipi/zebra/git-clone…
skipi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
zebra/lib/zebra/workers/job_request_factory/git_checkout.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| defmodule Zebra.Workers.JobRequestFactory.GitCheckout do | ||
| @moduledoc """ | ||
| Handles resilient git checkout configuration for jobs. | ||
|
|
||
| When the :git_clone_slow_retry feature is enabled for an organization, | ||
| this module adds the SEMAPHORE_GIT_CLONE_SLOW_RETRY environment variable, | ||
| which opts the toolbox `checkout` into slow-clone detection and resilient | ||
| retry (speed monitoring, retries, and alternative-endpoint fallback). | ||
|
|
||
| Only injected on cloud agents. The resilient behaviour (GeoDNS-based | ||
| alternative-endpoint fallback, DoH lookups) targets GitHub.com reachability | ||
| from Semaphore's cloud egress; on self-hosted agents the network is the | ||
| customer's own, so injecting it there is inappropriate (and the DoH | ||
| endpoint may well be blocked). | ||
|
|
||
| The toolbox keeps sensible defaults for the tuning knobs | ||
| (threshold/timeout/grace/retries), so only the on/off switch is injected | ||
| here; the feature is a no-op in the toolbox when this var is absent. | ||
| """ | ||
|
|
||
| alias Zebra.Models.Job | ||
| alias Zebra.Workers.JobRequestFactory.JobRequest | ||
|
|
||
| @doc """ | ||
| Returns environment variables for resilient git checkout. | ||
|
|
||
| Adds SEMAPHORE_GIT_CLONE_SLOW_RETRY=true when the job runs on a cloud agent | ||
| and the :git_clone_slow_retry feature is enabled for the organization. | ||
| """ | ||
| def env_vars(job, org_id) do | ||
| if inject?(job, org_id) do | ||
| [JobRequest.env_var("SEMAPHORE_GIT_CLONE_SLOW_RETRY", "true")] | ||
| else | ||
| [] | ||
| end | ||
| end | ||
|
|
||
| defp inject?(job, org_id) do | ||
| not Job.self_hosted?(job.machine_type) and | ||
| FeatureProvider.feature_enabled?(:git_clone_slow_retry, param: org_id) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
zebra/test/zebra/workers/job_request_factory/git_checkout_test.exs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| defmodule Zebra.Workers.JobRequestFactory.GitCheckoutTest do | ||
| use Zebra.DataCase | ||
|
|
||
| alias Zebra.Models.Job | ||
| alias Zebra.Workers.JobRequestFactory.GitCheckout | ||
|
|
||
| @cloud_job %Job{machine_type: "e1-standard-2"} | ||
| @self_hosted_job %Job{machine_type: "s1-local"} | ||
|
|
||
| describe "env_vars/2" do | ||
| test "returns empty list when feature is disabled" do | ||
| org_id = Ecto.UUID.generate() | ||
|
|
||
| assert GitCheckout.env_vars(@cloud_job, org_id) == [] | ||
| end | ||
|
|
||
| test "returns SEMAPHORE_GIT_CLONE_SLOW_RETRY env var on a cloud agent when feature is enabled" do | ||
| org_id = Support.StubbedProvider.git_clone_slow_retry_org_id() | ||
|
|
||
| env_vars = GitCheckout.env_vars(@cloud_job, org_id) | ||
|
|
||
| assert length(env_vars) == 1 | ||
| [env_var] = env_vars | ||
| assert env_var["name"] == "SEMAPHORE_GIT_CLONE_SLOW_RETRY" | ||
| assert env_var["value"] == Base.encode64("true") | ||
| end | ||
|
|
||
| test "returns empty list on a self-hosted agent even when feature is enabled" do | ||
| org_id = Support.StubbedProvider.git_clone_slow_retry_org_id() | ||
|
|
||
| assert GitCheckout.env_vars(@self_hosted_job, org_id) == [] | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.