GitLabgitlab-org

cli

main
ply7 git calls201 ms98 KiB4 cachedprotocol v2
137 lines3.8 KiBRaw
1package autoflow
3import (
4 "bytes"
5 "encoding/json"
6 "errors"
7 "fmt"
8 "io"
9 "strings"
11 autoflowv1 "gitlab.com/gitlab-org/protos/gen/go/gitlab/autoflow/v1"
14// ParseValue converts a JSON document into an AutoFlow value. null becomes
15// None, a number without a fraction or exponent an integer and any other
16// number a float, an array a list and an object a dict with string keys in the
17// order the document lists them.
18func ParseValue(data []byte) (*autoflowv1.Value, error) {
19 if len(bytes.TrimSpace(data)) == 0 {
20 return nil, errors.New("no JSON value")
21 }
22 dec := json.NewDecoder(bytes.NewReader(data))
23 dec.UseNumber()
24 v, err := parseValue(dec)
25 if err != nil {
26 return nil, truncated(err)
27 }
28 switch _, err := dec.Token(); {
29 case errors.Is(err, io.EOF):
30 return v, nil
31 case err != nil:
32 return nil, truncated(err)
33 default:
34 return nil, errors.New("more than one JSON value")
35 }
38// truncated gives a document that ends inside a value one error, where the
39// decoder reports io.EOF, io.ErrUnexpectedEOF or a syntax error depending on
40// where it stops.
41func truncated(err error) error {
42 var syntaxErr *json.SyntaxError
43 if errors.Is(err, io.EOF) || errors.Is(err, io.ErrUnexpectedEOF) ||
44 (errors.As(err, &syntaxErr) && syntaxErr.Error() == "unexpected end of JSON input") {
45 return errors.New("unexpected end of JSON input")
46 }
47 return err
50// ChannelValue returns the value that hands a workflow the channel name.
51func ChannelValue(name string) *autoflowv1.Value {
52 return &autoflowv1.Value{Kind: &autoflowv1.Value_ChannelValue{ChannelValue: &autoflowv1.ChannelValue{Name: name}}}
55func parseValue(dec *json.Decoder) (*autoflowv1.Value, error) {
56 tok, err := dec.Token()
57 if err != nil {
58 return nil, err
59 }
60 switch t := tok.(type) {
61 case nil:
62 return &autoflowv1.Value{Kind: &autoflowv1.Value_NoneValue{}}, nil
63 case bool:
64 return &autoflowv1.Value{Kind: &autoflowv1.Value_BoolValue{BoolValue: t}}, nil
65 case string:
66 return stringValue(t), nil
67 case json.Number:
68 return parseNumber(t)
69 case json.Delim:
70 if t == '[' {
71 return parseList(dec)
72 }
73 return parseDict(dec)
74 default:
75 return nil, fmt.Errorf("unexpected JSON token %v", tok)
76 }
79func parseNumber(n json.Number) (*autoflowv1.Value, error) {
80 if strings.ContainsAny(n.String(), ".eE") {
81 f, err := n.Float64()
82 if err != nil {
83 return nil, fmt.Errorf("number %s is out of range", n)
84 }
85 return &autoflowv1.Value{Kind: &autoflowv1.Value_FloatValue{FloatValue: f}}, nil
86 }
87 i, err := n.Int64()
88 if err != nil {
89 return nil, fmt.Errorf("integer %s is out of range", n)
90 }
91 return &autoflowv1.Value{Kind: &autoflowv1.Value_IntegerValue{IntegerValue: i}}, nil
94func parseList(dec *json.Decoder) (*autoflowv1.Value, error) {
95 list := &autoflowv1.ListValue{}
96 for dec.More() {
97 v, err := parseValue(dec)
98 if err != nil {
99 return nil, err
100 }
101 list.Values = append(list.Values, v)
102 }
103 if _, err := dec.Token(); err != nil {
104 return nil, err
105 }
106 return &autoflowv1.Value{Kind: &autoflowv1.Value_ListValue{ListValue: list}}, nil
109func parseDict(dec *json.Decoder) (*autoflowv1.Value, error) {
110 dict := &autoflowv1.DictValue{}
111 seen := map[string]struct{}{}
112 for dec.More() {
113 tok, err := dec.Token()
114 if err != nil {
115 return nil, err
116 }
117 // The decoder only yields a string where an object key belongs.
118 key, _ := tok.(string)
119 if _, ok := seen[key]; ok {
120 return nil, fmt.Errorf("duplicate key %q", key)
121 }
122 seen[key] = struct{}{}
123 v, err := parseValue(dec)
124 if err != nil {
125 return nil, err
126 }
127 dict.KeyValues = append(dict.KeyValues, &autoflowv1.KeyValue{Key: stringValue(key), Val: v})
128 }
129 if _, err := dec.Token(); err != nil {
130 return nil, err
131 }
132 return &autoflowv1.Value{Kind: &autoflowv1.Value_DictValue{DictValue: dict}}, nil
135func stringValue(s string) *autoflowv1.Value {
136 return &autoflowv1.Value{Kind: &autoflowv1.Value_StringValue{StringValue: s}}
Diagnostics7 git calls · 201 ms
CallStatusSizeTime0201 ms
discover200185 B4 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 KiB3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=3
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
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=2
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: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=2
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
fetchtree:02001.1 KiB · hit2 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=1165
git.response.cache=HIT
git.response.duration_ms=2
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=190
git.response.bytes=254
git.response.cache=HIT
git.response.duration_ms=3
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 KiB190 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=1332
git.response.cache=MISS
git.response.duration_ms=190
git.fetch.wants=f32eba404f355cf6e6dd7c06aede97ea24a9472f
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=1332
git.pkt.payload.max=1305
git.sideband.band1.bytes=1305
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
a5e2437a7dc0cf56
Request
c8feb058…
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