GitLabgitlab-org

cli

main
ply7 git calls308 ms98 KiB4 cachedprotocol v2
133 lines3.6 KiBRaw
1package autoflow
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "math"
8 "strconv"
9 "strings"
11 autoflowv1 "gitlab.com/gitlab-org/protos/gen/go/gitlab/autoflow/v1"
12 "google.golang.org/protobuf/encoding/protojson"
15// MarshalValue encodes v as plain JSON: None and a missing value become
16// null, an integer or a float a number, a list an array and a dict with string
17// keys an object in the dict's order. A float is written like Python's repr
18// writes it, with a fraction or an exponent, so it does not read back as an
19// integer. A value without a JSON equivalent, such as a channel, a tuple or
20// bytes, is encoded in its protobuf JSON form.
21func MarshalValue(v *autoflowv1.Value) ([]byte, error) {
22 var buf bytes.Buffer
23 if err := marshalValue(&buf, v); err != nil {
24 return nil, err
25 }
26 return buf.Bytes(), nil
29// MarshalProtoValue encodes v in its protobuf JSON form.
30func MarshalProtoValue(v *autoflowv1.Value) ([]byte, error) {
31 b, err := protojson.Marshal(v)
32 if err != nil {
33 return nil, fmt.Errorf("failed to encode value: %w", err)
34 }
35 // protojson randomizes its whitespace, so the output is compacted to stay
36 // the same between runs.
37 var buf bytes.Buffer
38 if err := json.Compact(&buf, b); err != nil {
39 return nil, fmt.Errorf("failed to encode value: %w", err)
40 }
41 return buf.Bytes(), nil
44func marshalValue(buf *bytes.Buffer, v *autoflowv1.Value) error {
45 switch k := v.GetKind().(type) {
46 case nil, *autoflowv1.Value_NoneValue:
47 buf.WriteString("null")
48 case *autoflowv1.Value_BoolValue:
49 buf.WriteString(strconv.FormatBool(k.BoolValue))
50 case *autoflowv1.Value_IntegerValue:
51 buf.WriteString(strconv.FormatInt(k.IntegerValue, 10))
52 case *autoflowv1.Value_FloatValue:
53 if math.IsInf(k.FloatValue, 0) || math.IsNaN(k.FloatValue) {
54 return marshalProto(buf, v)
55 }
56 buf.WriteString(formatFloat(k.FloatValue))
57 case *autoflowv1.Value_StringValue:
58 return marshalString(buf, k.StringValue)
59 case *autoflowv1.Value_ListValue:
60 buf.WriteByte('[')
61 for i, e := range k.ListValue.GetValues() {
62 if i > 0 {
63 buf.WriteByte(',')
64 }
65 if err := marshalValue(buf, e); err != nil {
66 return err
67 }
68 }
69 buf.WriteByte(']')
70 case *autoflowv1.Value_DictValue:
71 if !hasStringKeys(k.DictValue) {
72 return marshalProto(buf, v)
73 }
74 buf.WriteByte('{')
75 for i, kv := range k.DictValue.GetKeyValues() {
76 if i > 0 {
77 buf.WriteByte(',')
78 }
79 if err := marshalString(buf, kv.GetKey().GetStringValue()); err != nil {
80 return err
81 }
82 buf.WriteByte(':')
83 if err := marshalValue(buf, kv.GetVal()); err != nil {
84 return err
85 }
86 }
87 buf.WriteByte('}')
88 default:
89 return marshalProto(buf, v)
90 }
91 return nil
94func formatFloat(f float64) string {
95 if a := math.Abs(f); a != 0 && (a < 1e-4 || a >= 1e16) {
96 return strconv.FormatFloat(f, 'e', -1, 64)
97 }
98 s := strconv.FormatFloat(f, 'f', -1, 64)
99 if !strings.Contains(s, ".") {
100 s += ".0"
101 }
102 return s
105func hasStringKeys(d *autoflowv1.DictValue) bool {
106 for _, kv := range d.GetKeyValues() {
107 if _, ok := kv.GetKey().GetKind().(*autoflowv1.Value_StringValue); !ok {
108 return false
109 }
110 }
111 return true
114func marshalString(buf *bytes.Buffer, s string) error {
115 var b bytes.Buffer
116 enc := json.NewEncoder(&b) //nolint:forbidigo // encoding one string of a value, not producing stdout output
117 // A workflow result is read by people and tools, not embedded in HTML.
118 enc.SetEscapeHTML(false)
119 if err := enc.Encode(s); err != nil {
120 return fmt.Errorf("failed to encode value: %w", err)
121 }
122 buf.Write(bytes.TrimSuffix(b.Bytes(), []byte("\n")))
123 return nil
126func marshalProto(buf *bytes.Buffer, v *autoflowv1.Value) error {
127 b, err := MarshalProtoValue(v)
128 if err != nil {
129 return err
130 }
131 buf.Write(b)
132 return nil
Diagnostics7 git calls · 308 ms
CallStatusSizeTime0308 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=3
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 KiB2 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=UPDATING
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=5
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
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 · hit5 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=17
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=5
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:02001.1 KiB · hit17 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=8
git.response.bytes=1165
git.response.cache=HIT
git.response.duration_ms=17
git.fetch.filter=tree:0
git.fetch.wants=71c8407e0ff0e0af10f6a041ae330f754b68e7eb
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=1165
git.pkt.payload.max=1138
git.sideband.band1.bytes=1138
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1138
git.pack.trailer=61886367c69619d8db2b2cf2d7d24dca2016141c
Open pack map
fetchtree:0200254 B · hit8 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=275
git.response.bytes=254
git.response.cache=HIT
git.response.duration_ms=8
git.fetch.filter=tree:0
git.fetch.wants=92c0c916127a028255da99edec485fe247f8ada1
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=254
git.pkt.payload.max=227
git.sideband.band1.bytes=227
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=227
git.pack.trailer=97becb66cba7786f3c98f230357b525d141c4025
Open pack map
fetch2001.3 KiB275 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1378
git.response.cache=MISS
git.response.duration_ms=275
git.fetch.wants=f21ef8bec7894115a095e7702f1be5b2bda9053d
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=1378
git.pkt.payload.max=1351
git.sideband.band1.bytes=1351
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
a5e2864d6bc54af4
Request
316af037…
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