Skip to content
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

Split the is_importing stat in two #96

Merged
merged 3 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions internal/governor/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ func readSockstat(environ []string) updateData {
res.GroupLeader = sockstat.GetBool(parts[1])
case "is_importing":
res.IsImporting = sockstat.BoolValue(parts[1])
case "import_skip_push_limit":
res.ImportSkipPushLimit = sockstat.BoolValue(parts[1])
case "import_soft_throttling":
res.ImportSoftThrottling = sockstat.BoolValue(parts[1])
}
}

Expand Down
6 changes: 6 additions & 0 deletions internal/governor/governor.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ type updateData struct {
CommandID string `json:"command_id,omitempty"`
// IsImporting is true if the command is an import.
IsImporting bool `json:"is_importing,omitempty"`
// ImportSkipPushLimit is true if the command is an import and
// we want to skip the push limit for a command.
ImportSkipPushLimit bool `json:"import_skip_push_limit,omitempty"`
// ImportSoftThrottling is true if the command is an import and
// we want to apply it some soft throttling policies.
ImportSoftThrottling bool `json:"import_soft_throttling,omitempty"`
}

func update(w io.Writer, ud updateData) error {
Expand Down
34 changes: 34 additions & 0 deletions internal/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,40 @@ func (suite *SpokesReceivePackTestSuite) TestBadDateAllowedWithOverride() {
assert.Contains(suite.T(), string(out), " badDate:", "should still complain about a bad date")
}

func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackAllowedWhenWithIsImportingSockStat() {
assert.NoError(suite.T(), chdir(suite.T(), suite.remoteRepo), "unable to chdir into our remote Git repo")
// Set a really low value to receive.maxsize in order to make it fail
require.NoError(suite.T(), exec.Command("git", "config", "receive.maxsize", "1").Run())

assert.NoError(suite.T(), chdir(suite.T(), suite.localRepo), "unable to chdir into our local Git repo")
cmd := exec.Command("git", "push", "--all", "--receive-pack=spokes-receive-pack-wrapper", "r")
cmd.Env = append(os.Environ(),
"GIT_SOCKSTAT_VAR_is_importing=bool:true",
)
err := cmd.Run()
assert.NoError(
suite.T(),
err,
"unexpected failure with the custom spokes-receive-pack program; it should have succeeded")
}

func (suite *SpokesReceivePackTestSuite) TestSpokesReceivePackAllowedWhenWithImportSkipPushLimitSockStat() {
assert.NoError(suite.T(), chdir(suite.T(), suite.remoteRepo), "unable to chdir into our remote Git repo")
// Set a really low value to receive.maxsize in order to make it fail
require.NoError(suite.T(), exec.Command("git", "config", "receive.maxsize", "1").Run())

assert.NoError(suite.T(), chdir(suite.T(), suite.localRepo), "unable to chdir into our local Git repo")
cmd := exec.Command("git", "push", "--all", "--receive-pack=spokes-receive-pack-wrapper", "r")
cmd.Env = append(os.Environ(),
"GIT_SOCKSTAT_VAR_import_skip_push_limit=bool:true",
)
err := cmd.Run()
assert.NoError(
suite.T(),
err,
"unexpected failure with the custom spokes-receive-pack program; it should have succeeded")
}

func (suite *SpokesReceivePackTestSuite) TestWithGovernor() {
started := make(chan any)
govSock, msgs, cleanup := startFakeGovernor(suite.T(), started, nil)
Expand Down
10 changes: 9 additions & 1 deletion internal/spokes/spokes.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,11 @@ func (r *spokesReceivePack) isFsckConfigEnabled() bool {
}

func (r *spokesReceivePack) getMaxInputSize() (int, error) {
if isImporting() {
// We want to skip the default push limit when the `import_skip_push_limit`
// stat is set only.
// We keep using the `is_import` here for backward compatibility only,
// which should be removed on a subsequent PR.
if isImporting() || skipPushLimit() {
return 80 * 1024 * 1024 * 1024, nil /* 80 GB */
}

Expand Down Expand Up @@ -1234,6 +1238,10 @@ func isImporting() bool {
return sockstat.GetBool("is_importing")
}

func skipPushLimit() bool {
return sockstat.GetBool("import_skip_push_limit")
}

func allowBadDate() bool {
return isImporting() && sockstat.GetBool("allow_baddate_in_import")
}
Expand Down
Loading