Skip to content

Commit

Permalink
Merge branch 'main' into fix-cmdline
Browse files Browse the repository at this point in the history
  • Loading branch information
RidhwaanDev committed Apr 17, 2024
2 parents 76b028f + df827f1 commit 881ec11
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -6,7 +6,7 @@ require (
github.com/github/go-pipe v1.0.2
github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.6.0
golang.org/x/sync v0.7.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -29,8 +29,8 @@ golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
Expand Down
4 changes: 4 additions & 0 deletions internal/governor/conn.go
Expand Up @@ -176,6 +176,10 @@ func readSockstat(environ []string) updateData {
res.PubkeyVerifierID = sockstat.Uint32Value(parts[1])
case "pubkey_creator_id":
res.PubkeyCreatorID = sockstat.Uint32Value(parts[1])
case "gitmon_delay":
res.GitmonDelay = sockstat.Uint32Value(parts[1])
case "command_id":
res.CommandID = sockstat.StringValue(parts[1])
}
}

Expand Down
21 changes: 16 additions & 5 deletions internal/governor/governor.go
Expand Up @@ -69,6 +69,11 @@ type updateData struct {
GitProtocol string `json:"git_protocol,omitempty"`
PubkeyVerifierID uint32 `json:"pubkey_verifier_id,omitempty"`
PubkeyCreatorID uint32 `json:"pubkey_creator_id,omitempty"`
GitmonDelay uint32 `json:"gitmon_delay,omitempty"`
// An ID that identifies a group of commands that all make up one
// logical request. Is only used by the githttpdaemon to sync
// its gitmon proxy and request scheduler logical threads
CommandID string `json:"command_id,omitempty"`
}

func update(w io.Writer, ud updateData) error {
Expand All @@ -91,16 +96,18 @@ func update(w io.Writer, ud updateData) error {

type WaitError struct {
Duration time.Duration
Reason string
}

func newWaitError(duration time.Duration) error {
func newWaitError(duration time.Duration, reason string) error {
return WaitError{
Duration: duration,
Reason: reason,
}
}

func (err WaitError) Error() string {
return fmt.Sprintf("governor asked us to wait %s", err.Duration)
return fmt.Sprintf("governor asked us to wait %s: %s", err.Duration, err.Reason)
}

type FailError struct {
Expand Down Expand Up @@ -132,12 +139,13 @@ func schedule(r *bufio.Reader, w io.Writer) error {

line := string(b[:len(b)-1])

words := strings.SplitN(line, " ", 2)
words := strings.SplitN(line, " ", 3)
switch words[0] {
case "continue":
return nil
case "wait":
duration := 1 * time.Second
reason := "UNKNOWN"
if len(words) > 1 {
d, err := strconv.Atoi(words[1])
if err != nil {
Expand All @@ -146,11 +154,14 @@ func schedule(r *bufio.Reader, w io.Writer) error {
duration = time.Duration(d) * time.Second
}
}
return newWaitError(duration)
if len(words) > 2 {
reason = strings.Join(words[2:], " ")
}
return newWaitError(duration, reason)
case "fail":
reason := "UNKNOWN"
if len(words) > 1 {
reason = words[1]
reason = strings.Join(words[1:], " ")
}
return newFailError(reason)
default:
Expand Down
10 changes: 9 additions & 1 deletion internal/governor/governor_test.go
Expand Up @@ -31,7 +31,15 @@ func TestSchedule(t *testing.T) {
},
{
response: "wait 100\n",
expectedError: WaitError{Duration: 100 * time.Second},
expectedError: WaitError{Duration: 100 * time.Second, Reason: "UNKNOWN"},
},
{
response: "wait 100 network:ip\n",
expectedError: WaitError{Duration: 100 * time.Second, Reason: "network:ip"},
},
{
response: "wait 100 network:reason with spaces\n",
expectedError: WaitError{Duration: 100 * time.Second, Reason: "network:reason with spaces"},
},
{
response: "fail Too Busy\n",
Expand Down

0 comments on commit 881ec11

Please sign in to comment.