Skip to content

Commit 8642e20

Browse files
authored
perf: Optimize container task log output (#11393)
1 parent 2b81f7e commit 8642e20

File tree

2 files changed

+6
-32
lines changed

2 files changed

+6
-32
lines changed

agent/utils/docker/docker.go

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func (c Client) PullImageWithProcessAndOptions(task *task.Task, imageName string
212212
}
213213
if status == "Pull complete" || status == "Download complete" {
214214
id, _ := progress["id"].(string)
215-
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
215+
progressStr := fmt.Sprintf("%s %s", status, id)
216216
_ = setLog(id, progressStr, task)
217217
}
218218
}
@@ -246,7 +246,7 @@ func (c Client) PushImageWithProcessAndOptions(task *task.Task, imageName string
246246
logProcess(progress, task)
247247
case "Pushed":
248248
id, _ := progress["id"].(string)
249-
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
249+
progressStr := fmt.Sprintf("%s %s", status, id)
250250
_ = setLog(id, progressStr, task)
251251
default:
252252
progressStr, _ := json.Marshal(progress)
@@ -290,7 +290,7 @@ func (c Client) BuildImageWithProcessAndOptions(task *task.Task, tar io.ReadClos
290290
logProcess(progress, task)
291291
case "Pull complete", "Download complete", "Verifying Checksum":
292292
id, _ := progress["id"].(string)
293-
progressStr := fmt.Sprintf("%s [%s] --- %.2f%%", status, id, 100.0)
293+
progressStr := fmt.Sprintf("%s %s", status, id)
294294
_ = setLog(id, progressStr, task)
295295
default:
296296
progressStr, _ := json.Marshal(progress)
@@ -304,38 +304,12 @@ func (c Client) PullImageWithProcess(task *task.Task, imageName string) error {
304304
return c.PullImageWithProcessAndOptions(task, imageName, image.PullOptions{})
305305
}
306306

307-
func formatBytes(bytes uint64) string {
308-
const (
309-
KB = 1024
310-
MB = 1024 * KB
311-
GB = 1024 * MB
312-
TB = 1024 * GB
313-
)
314-
315-
switch {
316-
case bytes < MB:
317-
return fmt.Sprintf("%.0fKB", float64(bytes)/KB)
318-
case bytes < GB:
319-
return fmt.Sprintf("%.1fMB", float64(bytes)/MB)
320-
case bytes < TB:
321-
return fmt.Sprintf("%.1fGB", float64(bytes)/GB)
322-
default:
323-
return fmt.Sprintf("%.2fTB", float64(bytes)/TB)
324-
}
325-
}
326-
327307
func logProcess(progress map[string]interface{}, task *task.Task) {
328308
status, _ := progress["status"].(string)
329309
id, _ := progress["id"].(string)
330-
progressDetail, _ := progress["progressDetail"].(map[string]interface{})
331-
current, _ := progressDetail["current"].(float64)
310+
progressItem, _ := progress["progress"].(string)
332311
progressStr := ""
333-
total, ok := progressDetail["total"].(float64)
334-
if ok {
335-
progressStr = fmt.Sprintf("%s [%s] --- %.2f%%", status, id, (current/total)*100)
336-
} else {
337-
progressStr = fmt.Sprintf("%s [%s] --- %s ", status, id, formatBytes(uint64(current)))
338-
}
312+
progressStr = fmt.Sprintf("%s %s %s", status, id, progressItem)
339313
_ = setLog(id, progressStr, task)
340314
}
341315

frontend/src/views/container/image/push/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const formRef = ref<FormInstance>();
8080
8181
const handleChange = () => {
8282
let repoURL = loadDetailInfo(form.repoID);
83-
form.name = form.tagName.indexOf(repoURL) !== -1 ? form.tagName.replaceAll(repoURL, '') : form.tagName;
83+
form.name = form.tagName.indexOf(repoURL) !== -1 ? form.tagName.replaceAll(repoURL + '/', '') : form.tagName;
8484
};
8585
8686
const onSubmit = async (formEl: FormInstance | undefined) => {

0 commit comments

Comments
 (0)