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

tensorchord / envd / 12865642584

20 Jan 2025 10:08AM UTC coverage: 43.964% (-0.07%) from 44.034%
12865642584

Pull #1949

github

web-flow
chore(deps): bump github.com/syncthing/syncthing from 1.23.7 to 1.29.2

Bumps [github.com/syncthing/syncthing](https://github.com/syncthing/syncthing) from 1.23.7 to 1.29.2.
- [Release notes](https://github.com/syncthing/syncthing/releases)
- [Commits](https://github.com/syncthing/syncthing/compare/v1.23.7...v1.29.2)

---
updated-dependencies:
- dependency-name: github.com/syncthing/syncthing
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #1949: chore(deps): bump github.com/syncthing/syncthing from 1.23.7 to 1.29.2

6304 of 14339 relevant lines covered (43.96%)

567.32 hits per line

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

85.17
/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) {
4,162✔
53
        if p.last == nil {
4,207✔
54
                p.last = make(map[string]lastStatus)
45✔
55
        }
45✔
56

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

62
        if v.index == 0 {
6,064✔
63
                p.nextIndex++
1,902✔
64
                v.index = p.nextIndex
1,902✔
65
        }
1,902✔
66

67
        if dgst != p.current {
6,185✔
68
                if p.current != "" {
2,070✔
69
                        old := t.byDigest[p.current]
47✔
70
                        if old.logsPartial {
49✔
71
                                fmt.Fprintln(p.w, "")
2✔
72
                        }
2✔
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 {
4,001✔
79
                        fmt.Fprintln(p.w, "")
1,978✔
80
                } else {
2,023✔
81
                        p.notFirst = true
45✔
82
                }
45✔
83

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

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

4,162✔
99
        isOpenStatus := false // remote cache loading can currently produce status updates without active vertex
4,162✔
100
        for _, s := range v.statuses {
5,423✔
101
                if _, ok := v.statusUpdates[s.ID]; ok {
2,078✔
102
                        doPrint := true
817✔
103

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

115
                        if !doPrint {
918✔
116
                                continue
101✔
117
                        }
118

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

716✔
124
                        var bytes string
716✔
125
                        if s.Total != 0 {
790✔
126
                                bytes = fmt.Sprintf(" %.2f / %.2f", units.Bytes(s.Current), units.Bytes(s.Total))
74✔
127
                        } else if s.Current != 0 {
763✔
128
                                bytes = fmt.Sprintf(" %.2f", units.Bytes(s.Current))
47✔
129
                        }
47✔
130
                        var tm string
716✔
131
                        endTime := s.Timestamp
716✔
132
                        if s.Completed != nil {
1,275✔
133
                                endTime = *s.Completed
559✔
134
                        }
559✔
135
                        if s.Started != nil {
1,432✔
136
                                diff := endTime.Sub(*s.Started).Seconds()
716✔
137
                                if diff > 0.01 {
1,146✔
138
                                        tm = fmt.Sprintf(" %.1fs", diff)
430✔
139
                                }
430✔
140
                        }
141
                        if s.Completed != nil {
1,275✔
142
                                tm += " done"
559✔
143
                        } else {
716✔
144
                                isOpenStatus = true
157✔
145
                        }
157✔
146
                        fmt.Fprintf(p.w, "#%d %s%s%s\n", v.index, s.ID, bytes, tm)
716✔
147
                }
148
        }
149
        v.statusUpdates = map[string]struct{}{}
4,162✔
150

4,162✔
151
        for _, w := range v.warnings[v.warningIdx:] {
4,162✔
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 {
37,286✔
157
                if i == 0 {
34,920✔
158
                        l = l[v.logsOffset:]
1,796✔
159
                }
1,796✔
160
                fmt.Fprintf(p.w, "%s", l)
33,124✔
161
                if i != len(v.logs)-1 || !v.logsPartial {
65,446✔
162
                        fmt.Fprintln(p.w, "")
32,322✔
163
                }
32,322✔
164
                if v.logsBuffer == nil {
33,322✔
165
                        v.logsBuffer = ring.New(logsBufferSize)
198✔
166
                }
198✔
167
                v.logsBuffer.Value = l
33,124✔
168
                if !v.logsPartial {
43,572✔
169
                        v.logsBuffer = v.logsBuffer.Next()
10,448✔
170
                }
10,448✔
171
        }
172

173
        if len(v.logs) > 0 {
5,958✔
174
                if v.logsPartial {
2,598✔
175
                        v.logs = v.logs[len(v.logs)-1:]
802✔
176
                        v.logsOffset = len(v.logs[0])
802✔
177
                } else {
1,796✔
178
                        v.logs = nil
994✔
179
                        v.logsOffset = 0
994✔
180
                }
994✔
181
        }
182

183
        p.current = dgst
4,162✔
184
        if v.isCompleted() && !isOpenStatus {
6,138✔
185
                p.current = ""
1,976✔
186
                v.count = 0
1,976✔
187

1,976✔
188
                if v.Error != "" {
1,976✔
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 {
2,937✔
198
                        fmt.Fprintf(p.w, "#%d CACHED\n", v.index)
961✔
199
                } else {
1,976✔
200
                        tm := ""
1,015✔
201
                        var ivals []interval
1,015✔
202
                        for _, ival := range v.intervals {
2,313✔
203
                                ivals = append(ivals, ival)
1,298✔
204
                        }
1,298✔
205
                        ivals = mergeIntervals(ivals)
1,015✔
206
                        if len(ivals) > 0 {
2,030✔
207
                                var dt float64
1,015✔
208
                                for _, ival := range ivals {
2,313✔
209
                                        dt += ival.duration().Seconds()
1,298✔
210
                                }
1,298✔
211
                                tm = fmt.Sprintf(" %.1fs", dt)
1,015✔
212
                        }
213
                        fmt.Fprintf(p.w, "#%d DONE%s\n", v.index, tm)
1,015✔
214
                }
215
        }
216

217
        delete(t.updates, dgst)
4,162✔
218
}
219

220
func sortCompleted(t *trace, m map[digest.Digest]struct{}) []digest.Digest {
12,300✔
221
        out := make([]digest.Digest, 0, len(m))
12,300✔
222
        for k := range m {
14,276✔
223
                out = append(out, k)
1,976✔
224
        }
1,976✔
225
        sort.Slice(out, func(i, j int) bool {
15,527✔
226
                vtxi := t.byDigest[out[i]]
3,227✔
227
                vtxj := t.byDigest[out[j]]
3,227✔
228
                return vtxi.mostRecentInterval().stop.Before(*vtxj.mostRecentInterval().stop)
3,227✔
229
        })
3,227✔
230
        return out
12,300✔
231
}
232

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

12,300✔
237
        for dgst := range t.updates {
16,882✔
238
                v, ok := t.byDigest[dgst]
4,582✔
239
                if !ok {
4,582✔
240
                        continue
×
241
                }
242
                if v.ProgressGroup != nil || v.hidden {
4,582✔
243
                        // skip vtxs in a group (they are merged into a single vtx) and hidden ones
×
244
                        continue
×
245
                }
246
                if v.isCompleted() {
6,558✔
247
                        completed[dgst] = struct{}{}
1,976✔
248
                } else {
4,582✔
249
                        rest[dgst] = struct{}{}
2,606✔
250
                }
2,606✔
251
        }
252

253
        current := p.current
12,300✔
254

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

260
        for _, dgst := range sortCompleted(t, completed) {
14,276✔
261
                if dgst != current {
3,598✔
262
                        p.printVtx(t, dgst)
1,622✔
263
                }
1,622✔
264
        }
265

266
        if len(rest) == 0 {
22,323✔
267
                if current != "" {
19,963✔
268
                        if v := t.byDigest[current]; v.isStarted() && !v.isCompleted() {
19,724✔
269
                                return
9,784✔
270
                        }
9,784✔
271
                }
272
                // make any open vertex active
273
                for dgst, v := range t.byDigest {
9,370✔
274
                        if v.isStarted() && !v.isCompleted() && v.ProgressGroup == nil && !v.hidden {
9,149✔
275
                                p.printVtx(t, dgst)
18✔
276
                                return
18✔
277
                        }
18✔
278
                }
279
                return
221✔
280
        }
281

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

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

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

321
        // show items that were hidden
322
        for dgst := range rest {
4,125✔
323
                if stats[dgst].overLimit {
2,215✔
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,910✔
331
                p.printVtx(t, max)
×
332
                return
×
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

© 2026 Coveralls, Inc