GitLabgitlab-org

cli

main
ply7 git calls33 ms98 KiB6 cachedprotocol v2
158 lines4.3 KiBRaw
1//go:build !integration
3package proxy
5import (
6 "net/http"
7 "net/http/httptest"
8 "testing"
10 "github.com/stretchr/testify/assert"
13type respOpts struct {
14 status int
15 contentType string
16 path string
17 contentLength int64
18 uncompressed bool
21func streamResp(o respOpts) *http.Response {
22 return &http.Response{
23 StatusCode: o.status,
24 Header: http.Header{"Content-Type": {o.contentType}},
25 ContentLength: o.contentLength,
26 Uncompressed: o.uncompressed,
27 Body: http.NoBody,
28 Request: httptest.NewRequest(http.MethodGet, "https://example.com"+o.path, http.NoBody),
29 }
32func TestIsStreamable(t *testing.T) {
33 t.Parallel()
34 cases := []struct {
35 name string
36 opts respOpts
37 want bool
38 }{
39 {
40 name: "large botocore wheel binary/octet-stream streams",
41 opts: respOpts{200, "binary/octet-stream", "/botocore-1.43.89-py3-none-any.whl", 15768272, false},
42 want: true,
43 },
44 {
45 name: "crate application/gzip streams",
46 opts: respOpts{200, "application/gzip", "/crates/anyhow/anyhow-1.0.104.crate", 48819, false},
47 want: true,
48 },
49 {
50 name: "wheel by extension with text content-type streams",
51 opts: respOpts{200, "text/plain", "/foo-1.0-py3-none-any.whl", 1234, false},
52 want: true,
53 },
54 {
55 name: "application octet-stream with length streams",
56 opts: respOpts{200, "application/octet-stream", "/x", 1000, false},
57 want: true,
58 },
59 {
60 name: "tarball .tar.gz by extension streams",
61 opts: respOpts{200, "text/plain", "/pkg-1.0.tar.gz", 2048, false},
62 want: true,
63 },
64 {
65 name: "tarball .tar.bz2 by extension streams",
66 opts: respOpts{200, "text/plain", "/pkg-1.0.tar.bz2", 2048, false},
67 want: true,
68 },
69 {
70 name: "gem by extension streams",
71 opts: respOpts{200, "text/plain", "/gems/rake-13.2.1.gem", 4096, false},
72 want: true,
73 },
74 {
75 name: "jar by extension streams",
76 opts: respOpts{200, "text/plain", "/com/example/foo/1.0/foo-1.0.jar", 8192, false},
77 want: true,
78 },
79 {
80 name: "nupkg by extension streams",
81 opts: respOpts{200, "text/plain", "/newtonsoft.json/13.0.3/newtonsoft.json.13.0.3.nupkg", 16384, false},
82 want: true,
83 },
84 {
85 name: "war by extension streams",
86 opts: respOpts{200, "text/plain", "/com/example/app/1.0/app-1.0.war", 29745860, false},
87 want: true,
88 },
89 {
90 name: "aar by extension streams",
91 opts: respOpts{200, "text/plain", "/com/example/lib/1.0/lib-1.0.aar", 2293265, false},
92 want: true,
93 },
94 {
95 name: "maven central war served application/java-archive streams",
96 opts: respOpts{200, "application/java-archive", "/org/apache/solr/solr/4.10.4/solr-4.10.4.war", 29745860, false},
97 want: true,
98 },
99 {
100 name: "application/java-archive content-type streams",
101 opts: respOpts{200, "application/java-archive", "/download", 1631109, false},
102 want: true,
103 },
104 {
105 name: "application/x-gzip content-type streams",
106 opts: respOpts{200, "application/x-gzip", "/download", 3072, false},
107 want: true,
108 },
109 {
110 name: "application/zip content-type streams",
111 opts: respOpts{200, "application/zip", "/download", 5120, false},
112 want: true,
113 },
114 {
115 name: "metadata sidecar unknown length is buffered (regression)",
116 opts: respOpts{200, "binary/octet-stream", "/boto3-1.43.89-py3-none-any.whl.metadata", -1, true},
117 want: false,
118 },
119 {
120 name: "artifact with unknown content length is buffered",
121 opts: respOpts{200, "binary/octet-stream", "/foo.whl", -1, false},
122 want: false,
123 },
124 {
125 name: "transport-decompressed artifact is buffered",
126 opts: respOpts{200, "application/octet-stream", "/foo.whl", 500, true},
127 want: false,
128 },
129 {
130 name: "json metadata is buffered",
131 opts: respOpts{200, "application/json", "/simple/boto3/", 200, false},
132 want: false,
133 },
134 {
135 name: "html metadata is buffered",
136 opts: respOpts{200, "text/html", "/simple/boto3/", 200, false},
137 want: false,
138 },
139 {
140 name: "non-2xx is not streamed",
141 opts: respOpts{302, "application/octet-stream", "/foo.whl", 100, false},
142 want: false,
143 },
144 {
145 name: "404 is not streamed",
146 opts: respOpts{404, "application/octet-stream", "/foo.whl", 100, false},
147 want: false,
148 },
149 }
150 for _, tc := range cases {
151 t.Run(tc.name, func(t *testing.T) {
152 t.Parallel()
153 resp := streamResp(tc.opts)
154 defer resp.Body.Close()
155 assert.Equal(t, tc.want, isStreamable(resp))
156 })
157 }
Diagnostics7 git calls · 33 ms
CallStatusSizeTime033 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit1 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=1
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0200361 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=361
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=506cba622ceda1473ee3cde63969809c144b7247
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=361
git.pkt.payload.max=334
git.sideband.band1.bytes=334
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=334
git.pack.trailer=26d32585a3a474717e00a318584ccd16918c9d32
Open pack map
fetchtree:02001.0 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=21
git.response.bytes=1051
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=7a2a90605315ba5b37f63c08726e6b2caa26e48d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1051
git.pkt.payload.max=1024
git.sideband.band1.bytes=1024
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1024
git.pack.trailer=7503ef36a75d3595b473035c69e639fd0ce41598
Open pack map
fetch2001.2 KiB · hit21 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1264
git.response.cache=HIT
git.response.duration_ms=21
git.fetch.wants=17b165e4d7b473ca41a9790e43a851890e7c01fa
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1264
git.pkt.payload.max=1237
git.sideband.band1.bytes=1237
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e2599b0f84a23e
Request
6feab99f…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format