diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-11-04 16:41:51 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-11-07 10:21:27 +0300 |
commit | cf06896a6e55947c2ff01cec482d7215636c196f (patch) | |
tree | af55e8d3702ed5de2d2885c4bb8fbc296c6250f0 | |
parent | 7077f6d7432fdddfee5073ab9d90997872c278f6 (diff) |
stats: Implement support for SHA256 object format in push probes
The stats package has a blackbox tester for HTTP-based pushes that allow
the user to observe timings for preconfigured pushes. In order for this
to be configurable, we had to reimplement parts of the Git protocol so
that we can easily drive this.
One part that our implementation does not currently support is the
`object-format` capability that advertises the object format that the
client expects the remote repository to be in. As this capability will
default to "sha1" in case it's not explicitly set, this means that we
don't support SHA256-based pushes.
Add a new configuration that allows the user to specify the object
format that shall be used for the push probe and report the object
format capability depending on that. This is sufficient for enabling
SHA256-based pushes.
Changelog: added
-rw-r--r-- | internal/blackbox/blackbox.go | 12 | ||||
-rw-r--r-- | internal/blackbox/config.go | 3 | ||||
-rw-r--r-- | internal/git/stats/http_push.go | 3 | ||||
-rw-r--r-- | internal/git/stats/http_push_test.go | 2 | ||||
-rw-r--r-- | internal/git/stats/http_send_pack.go | 7 |
5 files changed, 22 insertions, 5 deletions
diff --git a/internal/blackbox/blackbox.go b/internal/blackbox/blackbox.go index 38cfa8b6d..e23abb257 100644 --- a/internal/blackbox/blackbox.go +++ b/internal/blackbox/blackbox.go @@ -196,6 +196,16 @@ func (b Blackbox) push(probe Probe) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() + objectFormat := probe.Push.ObjectFormat + if objectFormat == "" { + objectFormat = git.ObjectHashSHA1.Format + } + + objectHash, err := git.ObjectHashByFormat(objectFormat) + if err != nil { + return fmt.Errorf("looking up object format: %w", err) + } + commands := make([]stats.PushCommand, len(probe.Push.Commands)) for i, command := range probe.Push.Commands { oldOID, err := git.ObjectHashSHA1.FromHex(command.OldOID) @@ -222,7 +232,7 @@ func (b Blackbox) push(probe Probe) error { defer packfile.Close() clone, err := stats.PerformHTTPPush( - ctx, probe.URL, probe.User, probe.Password, commands, packfile, false) + ctx, probe.URL, probe.User, probe.Password, objectHash, commands, packfile, false) if err != nil { return err } diff --git a/internal/blackbox/config.go b/internal/blackbox/config.go index 9ea3c33a9..4beb16f2d 100644 --- a/internal/blackbox/config.go +++ b/internal/blackbox/config.go @@ -49,6 +49,9 @@ type PushCommand struct { // PushConfig is the configuration for a Push-type probe. type PushConfig struct { + // ObjectFormat is the object format that is used on the remote side. This can either be + // "sha1" or "sha256". Defaults to "sha1". + ObjectFormat string `toml:"object_format"` // Commands is the list of commands which should be executed as part of the push. Commands []PushCommand `toml:"commands"` // Packfile is the path to the packfile that shall be sent as part of the push. diff --git a/internal/git/stats/http_push.go b/internal/git/stats/http_push.go index 58020ea2a..8601720e3 100644 --- a/internal/git/stats/http_push.go +++ b/internal/git/stats/http_push.go @@ -28,6 +28,7 @@ type PushCommand struct { func PerformHTTPPush( ctx context.Context, url, user, password string, + objectHash git.ObjectHash, commands []PushCommand, packfile io.Reader, interactive bool, @@ -40,7 +41,7 @@ func PerformHTTPPush( } } - sendPack, err := performHTTPSendPack(ctx, url, user, password, + sendPack, err := performHTTPSendPack(ctx, url, user, password, objectHash, commands, packfile, printInteractive) if err != nil { return HTTPPush{}, ctxErr(ctx, err) diff --git a/internal/git/stats/http_push_test.go b/internal/git/stats/http_push_test.go index 49531722a..8c6cfed9b 100644 --- a/internal/git/stats/http_push_test.go +++ b/internal/git/stats/http_push_test.go @@ -169,7 +169,7 @@ func TestPerformHTTPPush(t *testing.T) { start := time.Now() - stats, err := PerformHTTPPush(ctx, url, "", "", commands, packfile, false) + stats, err := PerformHTTPPush(ctx, url, "", "", gittest.DefaultObjectHash, commands, packfile, false) require.Equal(t, tc.expectedErr, err) if err != nil { return diff --git a/internal/git/stats/http_send_pack.go b/internal/git/stats/http_send_pack.go index 71c8eff38..356e7d125 100644 --- a/internal/git/stats/http_send_pack.go +++ b/internal/git/stats/http_send_pack.go @@ -9,6 +9,7 @@ import ( "net/http" "time" + "gitlab.com/gitlab-org/gitaly/v15/internal/git" "gitlab.com/gitlab-org/gitaly/v15/internal/git/pktline" ) @@ -33,6 +34,7 @@ type HTTPSendPack struct { func buildSendPackRequest( ctx context.Context, url, user, password string, + objectHash git.ObjectHash, commands []PushCommand, packfile io.Reader, ) (*http.Request, error) { @@ -42,7 +44,7 @@ func buildSendPackRequest( for i, command := range commands { c := fmt.Sprintf("%s %s %s", command.OldOID, command.NewOID, command.Reference) if i == 0 { - c += "\x00side-band-64k report-status delete-refs" + c += "\x00side-band-64k report-status delete-refs object-format=" + objectHash.Format } if _, err := pktline.WriteString(zipper, c); err != nil { @@ -89,11 +91,12 @@ func buildSendPackRequest( func performHTTPSendPack( ctx context.Context, url, user, password string, + objectHash git.ObjectHash, commands []PushCommand, packfile io.Reader, reportProgress func(string, ...interface{}), ) (HTTPSendPack, error) { - request, err := buildSendPackRequest(ctx, url, user, password, commands, packfile) + request, err := buildSendPackRequest(ctx, url, user, password, objectHash, commands, packfile) if err != nil { return HTTPSendPack{}, err } |