• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tensorchord / envd / 19253185250

11 Nov 2025 02:43AM UTC coverage: 43.119% (-0.01%) from 43.129%
19253185250

push

github

web-flow
chore: bump lang & tools version (#2062)

* chore: bump lang & tools version

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* use conda-forge as the default channel

Signed-off-by: Keming <kemingyang@tensorchord.ai>

* rm all the defaults channel in tests

Signed-off-by: Keming <kemingyang@tensorchord.ai>

---------

Signed-off-by: Keming <kemingyang@tensorchord.ai>

9 of 9 new or added lines in 2 files covered. (100.0%)

5 existing lines in 1 file now uncovered.

5364 of 12440 relevant lines covered (43.12%)

176.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.32
/pkg/progress/progressui/printer.go
1
// Copyright 2023 The envd Authors
2
// Copyright 2023 The buildkit Authors
3
//
4
// Licensed under the Apache License, Version 2.0 (the "License");
5
// you may not use this file except in compliance with the License.
6
// You may obtain a copy of the License at
7
//
8
//      http://www.apache.org/licenses/LICENSE-2.0
9
//
10
// Unless required by applicable law or agreed to in writing, software
11
// distributed under the License is distributed on an "AS IS" BASIS,
12
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
// See the License for the specific language governing permissions and
14
// limitations under the License.
15

16
package progressui
17

18
import (
19
        "container/ring"
20
        "context"
21
        "fmt"
22
        "io"
23
        "os"
24
        "sort"
25
        "strings"
26
        "time"
27

28
        "github.com/opencontainers/go-digest"
29
        "github.com/tonistiigi/units"
30
)
31

32
const antiFlicker = 5 * time.Second
33
const maxDelay = 10 * time.Second
34
const minTimeDelta = 5 * time.Second
35
const minProgressDelta = 0.05 // %
36

37
const logsBufferSize = 10
38

39
type lastStatus struct {
40
        Current   int64
41
        Timestamp time.Time
42
}
43

44
type textMux struct {
45
        w         io.Writer
46
        current   digest.Digest
47
        last      map[string]lastStatus
48
        notFirst  bool
49
        nextIndex int
50
}
51

52
func (p *textMux) printVtx(t *trace, dgst digest.Digest) {
2,349✔
53
        if p.last == nil {
2,379✔
54
                p.last = make(map[string]lastStatus)
30✔
55
        }
30✔
56

57
        v, ok := t.byDigest[dgst]
2,349✔
58
        if !ok {
2,349✔
59
                return
×
60
        }
×
61

62
        if v.index == 0 {
3,432✔
63
                p.nextIndex++
1,083✔
64
                v.index = p.nextIndex
1,083✔
65
        }
1,083✔
66

67
        if dgst != p.current {
3,517✔
68
                if p.current != "" {
1,215✔
69
                        old := t.byDigest[p.current]
47✔
70
                        if old.logsPartial {
47✔
UNCOV
71
                                fmt.Fprintln(p.w, "")
×
UNCOV
72
                        }
×
73
                        old.logsOffset = 0
47✔
74
                        old.count = 0
47✔
75
                        fmt.Fprintf(p.w, "#%d ...\n", old.index)
47✔
76
                }
77

78
                if p.notFirst {
2,306✔
79
                        fmt.Fprintln(p.w, "")
1,138✔
80
                } else {
1,168✔
81
                        p.notFirst = true
30✔
82
                }
30✔
83

84
                if os.Getenv("PROGRESS_NO_TRUNC") == "0" {
1,168✔
85
                        fmt.Fprintf(p.w, "#%d %s\n", v.index, limitString(v.Name, 72))
×
86
                } else {
1,168✔
87
                        fmt.Fprintf(p.w, "#%d %s\n", v.index, v.Name)
1,168✔
88
                }
1,168✔
89
        }
90

91
        if len(v.events) != 0 {
2,349✔
92
                v.logsOffset = 0
×
93
        }
×
94
        for _, ev := range v.events {
2,349✔
95
                fmt.Fprintf(p.w, "#%d %s\n", v.index, ev)
×
96
        }
×
97
        v.events = v.events[:0]
2,349✔
98

2,349✔
99
        isOpenStatus := false // remote cache loading can currently produce status updates without active vertex
2,349✔
100
        for _, s := range v.statuses {
3,417✔
101
                if _, ok := v.statusUpdates[s.ID]; ok {
1,583✔
102
                        doPrint := true
515✔
103

515✔
104
                        if last, ok := p.last[s.ID]; ok && s.Completed == nil {
624✔
105
                                var progressDelta float64
109✔
106
                                if s.Total > 0 {
176✔
107
                                        progressDelta = float64(s.Current-last.Current) / float64(s.Total)
67✔
108
                                }
67✔
109
                                timeDelta := s.Timestamp.Sub(last.Timestamp)
109✔
110
                                if progressDelta < minProgressDelta && timeDelta < minTimeDelta {
191✔
111
                                        doPrint = false
82✔
112
                                }
82✔
113
                        }
114

115
                        if !doPrint {
597✔
116
                                continue
82✔
117
                        }
118

119
                        p.last[s.ID] = lastStatus{
433✔
120
                                Timestamp: s.Timestamp,
433✔
121
                                Current:   s.Current,
433✔
122
                        }
433✔
123

433✔
124
                        var bytes string
433✔
125
                        if s.Total != 0 {
548✔
126
                                bytes = fmt.Sprintf(" %.2f / %.2f", units.Bytes(s.Current), units.Bytes(s.Total))
115✔
127
                        } else if s.Current != 0 {
456✔
128
                                bytes = fmt.Sprintf(" %.2f", units.Bytes(s.Current))
23✔
129
                        }
23✔
130
                        var tm string
433✔
131
                        endTime := s.Timestamp
433✔
132
                        if s.Completed != nil {
768✔
133
                                endTime = *s.Completed
335✔
134
                        }
335✔
135
                        if s.Started != nil {
866✔
136
                                diff := endTime.Sub(*s.Started).Seconds()
433✔
137
                                if diff > 0.01 {
673✔
138
                                        tm = fmt.Sprintf(" %.1fs", diff)
240✔
139
                                }
240✔
140
                        }
141
                        if s.Completed != nil {
768✔
142
                                tm += " done"
335✔
143
                        } else {
433✔
144
                                isOpenStatus = true
98✔
145
                        }
98✔
146
                        fmt.Fprintf(p.w, "#%d %s%s%s\n", v.index, s.ID, bytes, tm)
433✔
147
                }
148
        }
149
        v.statusUpdates = map[string]struct{}{}
2,349✔
150

2,349✔
151
        for _, w := range v.warnings[v.warningIdx:] {
2,349✔
152
                fmt.Fprintf(p.w, "#%d WARN: %s\n", v.index, w.Short)
×
153
                v.warningIdx++
×
154
        }
×
155

156
        for i, l := range v.logs {
11,341✔
157
                if i == 0 {
9,931✔
158
                        l = l[v.logsOffset:]
939✔
159
                }
939✔
160
                fmt.Fprintf(p.w, "%s", l)
8,992✔
161
                if i != len(v.logs)-1 || !v.logsPartial {
17,475✔
162
                        fmt.Fprintln(p.w, "")
8,483✔
163
                }
8,483✔
164
                if v.logsBuffer == nil {
9,040✔
165
                        v.logsBuffer = ring.New(logsBufferSize)
48✔
166
                }
48✔
167
                v.logsBuffer.Value = l
8,992✔
168
                if !v.logsPartial {
13,688✔
169
                        v.logsBuffer = v.logsBuffer.Next()
4,696✔
170
                }
4,696✔
171
        }
172

173
        if len(v.logs) > 0 {
3,288✔
174
                if v.logsPartial {
1,448✔
175
                        v.logs = v.logs[len(v.logs)-1:]
509✔
176
                        v.logsOffset = len(v.logs[0])
509✔
177
                } else {
939✔
178
                        v.logs = nil
430✔
179
                        v.logsOffset = 0
430✔
180
                }
430✔
181
        }
182

183
        p.current = dgst
2,349✔
184
        if v.isCompleted() && !isOpenStatus {
3,470✔
185
                p.current = ""
1,121✔
186
                v.count = 0
1,121✔
187

1,121✔
188
                if v.Error != "" {
1,121✔
189
                        if v.logsPartial {
×
190
                                fmt.Fprintln(p.w, "")
×
191
                        }
×
192
                        if strings.HasSuffix(v.Error, context.Canceled.Error()) {
×
193
                                fmt.Fprintf(p.w, "#%d CANCELED\n", v.index)
×
194
                        } else {
×
195
                                fmt.Fprintf(p.w, "#%d ERROR: %s\n", v.index, v.Error)
×
196
                        }
×
197
                } else if v.Cached {
1,754✔
198
                        fmt.Fprintf(p.w, "#%d CACHED\n", v.index)
633✔
199
                } else {
1,121✔
200
                        tm := ""
488✔
201
                        var ivals []interval
488✔
202
                        for _, ival := range v.intervals {
1,027✔
203
                                ivals = append(ivals, ival)
539✔
204
                        }
539✔
205
                        ivals = mergeIntervals(ivals)
488✔
206
                        if len(ivals) > 0 {
976✔
207
                                var dt float64
488✔
208
                                for _, ival := range ivals {
1,027✔
209
                                        dt += ival.duration().Seconds()
539✔
210
                                }
539✔
211
                                tm = fmt.Sprintf(" %.1fs", dt)
488✔
212
                        }
213
                        fmt.Fprintf(p.w, "#%d DONE%s\n", v.index, tm)
488✔
214
                }
215
        }
216

217
        delete(t.updates, dgst)
2,349✔
218
}
219

220
func sortCompleted(t *trace, m map[digest.Digest]struct{}) []digest.Digest {
4,603✔
221
        out := make([]digest.Digest, 0, len(m))
4,603✔
222
        for k := range m {
5,725✔
223
                out = append(out, k)
1,122✔
224
        }
1,122✔
225
        sort.Slice(out, func(i, j int) bool {
6,539✔
226
                vtxi := t.byDigest[out[i]]
1,936✔
227
                vtxj := t.byDigest[out[j]]
1,936✔
228
                return vtxi.mostRecentInterval().stop.Before(*vtxj.mostRecentInterval().stop)
1,936✔
229
        })
1,936✔
230
        return out
4,603✔
231
}
232

233
func (p *textMux) print(t *trace) {
4,603✔
234
        completed := map[digest.Digest]struct{}{}
4,603✔
235
        rest := map[digest.Digest]struct{}{}
4,603✔
236

4,603✔
237
        for dgst := range t.updates {
7,343✔
238
                v, ok := t.byDigest[dgst]
2,740✔
239
                if !ok {
2,740✔
240
                        continue
×
241
                }
242
                if v.ProgressGroup != nil || v.hidden {
2,740✔
243
                        // skip vtxs in a group (they are merged into a single vtx) and hidden ones
×
244
                        continue
×
245
                }
246
                if v.isCompleted() {
3,862✔
247
                        completed[dgst] = struct{}{}
1,122✔
248
                } else {
2,740✔
249
                        rest[dgst] = struct{}{}
1,618✔
250
                }
1,618✔
251
        }
252

253
        current := p.current
4,603✔
254

4,603✔
255
        // items that have completed need to be printed first
4,603✔
256
        if _, ok := completed[current]; ok {
4,771✔
257
                p.printVtx(t, current)
168✔
258
        }
168✔
259

260
        for _, dgst := range sortCompleted(t, completed) {
5,725✔
261
                if dgst != current {
2,076✔
262
                        p.printVtx(t, dgst)
954✔
263
                }
954✔
264
        }
265

266
        if len(rest) == 0 {
7,854✔
267
                if current != "" {
6,477✔
268
                        if v := t.byDigest[current]; v.isStarted() && !v.isCompleted() {
6,372✔
269
                                return
3,146✔
270
                        }
3,146✔
271
                }
272
                // make any open vertex active
273
                for dgst, v := range t.byDigest {
3,478✔
274
                        if v.isStarted() && !v.isCompleted() && v.ProgressGroup == nil && !v.hidden {
3,385✔
275
                                p.printVtx(t, dgst)
12✔
276
                                return
12✔
277
                        }
12✔
278
                }
279
                return
93✔
280
        }
281

282
        // now print the active one
283
        if _, ok := rest[current]; ok {
2,370✔
284
                p.printVtx(t, current)
1,018✔
285
        }
1,018✔
286

287
        stats := map[digest.Digest]*vtxStat{}
1,352✔
288
        now := time.Now()
1,352✔
289
        sum := 0.0
1,352✔
290
        var max digest.Digest
1,352✔
291
        if current != "" {
2,595✔
292
                rest[current] = struct{}{}
1,243✔
293
        }
1,243✔
294
        for dgst := range rest {
3,195✔
295
                v, ok := t.byDigest[dgst]
1,843✔
296
                if !ok {
1,843✔
297
                        continue
×
298
                }
299
                if v.lastBlockTime == nil {
1,843✔
300
                        // shouldn't happen, but not worth crashing over
×
301
                        continue
×
302
                }
303
                tm := now.Sub(*v.lastBlockTime)
1,843✔
304
                speed := float64(v.count) / tm.Seconds()
1,843✔
305
                overLimit := tm > maxDelay && dgst != current
1,843✔
306
                stats[dgst] = &vtxStat{blockTime: tm, speed: speed, overLimit: overLimit}
1,843✔
307
                sum += speed
1,843✔
308
                if overLimit || max == "" || stats[max].speed < speed {
3,385✔
309
                        max = dgst
1,542✔
310
                }
1,542✔
311
        }
312
        for dgst := range stats {
3,195✔
313
                stats[dgst].share = stats[dgst].speed / sum
1,843✔
314
        }
1,843✔
315

316
        if _, ok := completed[current]; ok || current == "" {
1,549✔
317
                p.printVtx(t, max)
197✔
318
                return
197✔
319
        }
197✔
320

321
        // show items that were hidden
322
        for dgst := range rest {
2,670✔
323
                if stats[dgst].overLimit {
1,515✔
324
                        p.printVtx(t, dgst)
×
325
                        return
×
326
                }
×
327
        }
328

329
        // fair split between vertices
330
        if 1.0/(1.0-stats[current].share)*antiFlicker.Seconds() < stats[current].blockTime.Seconds() {
1,155✔
UNCOV
331
                p.printVtx(t, max)
×
UNCOV
332
                return
×
UNCOV
333
        }
×
334
}
335

336
type vtxStat struct {
337
        blockTime time.Duration
338
        speed     float64
339
        share     float64
340
        overLimit bool
341
}
342

343
func limitString(s string, l int) string {
×
344
        if len(s) > l {
×
345
                return s[:l] + "..."
×
346
        }
×
347
        return s
×
348
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc