GitLabgitlab-org
cli
main
1package cilog
3import (
4 "encoding/json"
5 "os"
6 "path/filepath"
7 "time"
9 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/fsx"
10 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/verdict"
11)
13type Session struct {
14 StartedAt string `json:"startedAt"`
15 Command string `json:"command"`
16}
18type Log struct {
19 SchemaVersion int `json:"schemaVersion"`
20 Session Session `json:"session"`
21 Entries []verdict.Entry `json:"entries"`
23 seen map[string]struct{}
24}
26// DirEnv names a directory whose CI log ci-summary reads in addition to the
27// working directory's. `job-proxy start` sets it to where the job-level proxy
28// writes, so a job that changes directory before ci-summary still sees blocks.
29const DirEnv = "GLAB_DF_CI_LOG_DIR"
31func Path(baseDir string) string {
32 return filepath.Join(baseDir, ".gitlab", "df", "ci-log.json")
33}
35// LockPath is the sidecar advisory-lock file guarding the Load -> Append ->
36// Save sequence against concurrent "glab df run" invocations in one job. It is
37// kept separate from the log file so the lock never conflicts with Save's
38// whole-file atomic rename, which replaces the log's inode.
39func LockPath(baseDir string) string {
40 return filepath.Join(baseDir, ".gitlab", "df", "ci-log.lock")
41}
43func New(command string) *Log {
44 return &Log{
45 SchemaVersion: 1,
46 Session: Session{StartedAt: time.Now().UTC().Format(time.RFC3339), Command: command},
47 seen: map[string]struct{}{},
48 }
49}
51func Load(baseDir string) (*Log, error) {
52 l := &Log{SchemaVersion: 1, seen: map[string]struct{}{}}
53 raw, err := os.ReadFile(Path(baseDir))
54 if os.IsNotExist(err) {
55 return l, nil
56 }
57 if err != nil {
58 return nil, err
59 }
60 if err := json.Unmarshal(raw, l); err != nil {
61 return nil, err
62 }
63 l.seen = map[string]struct{}{}
64 for _, e := range l.Entries {
65 l.seen[e.Key()] = struct{}{}
66 }
67 return l, nil
68}
70func (l *Log) Append(e verdict.Entry) {
71 if l.seen == nil {
72 l.seen = map[string]struct{}{}
73 }
74 if _, ok := l.seen[e.Key()]; ok {
75 return
76 }
77 if e.Timestamp == "" {
78 e.Timestamp = time.Now().UTC().Format(time.RFC3339)
79 }
80 l.seen[e.Key()] = struct{}{}
81 l.Entries = append(l.Entries, e)
82}
84// Save writes the CI log atomically with owner-only (0o600) permissions.
85// The log records which packages a shared CI runner requested and how the
86// firewall ruled on each; ci-summary reads it back to set the job's exit
87// code. A co-tenant who can rewrite the log could flip that gate, so the
88// file must not be left group/world-writable even when an earlier run (or a
89// pre-planted file) created it with a looser mode. WriteOwnerOnly enforces
90// 0o600 on every rewrite; WriteJSONFile cannot, because renameio.WriteFile
91// preserves a pre-existing target's mode.
92func Save(baseDir string, l *Log) error {
93 path := Path(baseDir)
94 if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
95 return err
96 }
97 raw, err := json.MarshalIndent(l, "", " ") //nolint:forbidigo // serializing the CI log to disk, not stdout output
98 if err != nil {
99 return err
100 }
101 return fsx.WriteOwnerOnly(path, append(raw, '\n'))
102}
Diagnostics7 git calls · 244 ms
CallStatusSizeTime0244 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=2 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 · 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=32926 git.response.cache=HIT git.response.duration_ms=2 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=44Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 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=4273 git.response.cache=HIT git.response.duration_ms=3 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 · 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=361 git.response.cache=HIT git.response.duration_ms=2 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=26d32585a3a474717e00a318584ccd16918c9d32Open pack map
fetchtree:0200137 B · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=233 git.response.bytes=137 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=tree:0 git.fetch.wants=61174527a21f13b5af311b19bb371e96d216e20f 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=137 git.pkt.payload.max=110 git.sideband.band1.bytes=110 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=1 git.pack.bytes=110 git.pack.trailer=e54777d2032c75e231b67dbe8ed253cbed5066e6Open pack map
fetch2001.4 KiB233 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=1463 git.response.cache=MISS git.response.duration_ms=233 git.fetch.wants=aeea9605d79a0b823ee21c2cfc988fdb51637033 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=1463 git.pkt.payload.max=1436 git.sideband.band1.bytes=1436 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
- a5e2bf55fd1389da
- Request
- d291585b…
- 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