Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions common/monitor/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ func (s *Span) Progress() Progress {
}
parentCount += childTotal * child.Count / child.Total
}
// Clamp parentCount to parentTotal. The "zero-total child is complete"
// fallback above can otherwise push parentCount beyond parentTotal when
// the parent has already consumed its own count and a running child is
// reporting no work units, which would surface as >100% progress in the
// dashboard.
if parentCount > parentTotal {
parentCount = parentTotal
}
return Progress{
Name: s.name,
Status: s.status,
Expand Down
25 changes: 25 additions & 0 deletions common/monitor/progress_overflow_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package monitor

import (
"context"
"testing"
)

// TestProgress_ZeroTotalChildDoesNotExceed100Percent pins the behavior of the
// zero-total child fallback in Span.Progress. Before the clamp, a parent
// with total=2,count=2 plus a running child with total=0 would return
// Count=3,Total=2 (150%), which confused the dashboard progress bar.
//
// The clamp ensures Count <= Total for every case the fallback handles.
func TestProgress_ZeroTotalChildDoesNotExceed100Percent(t *testing.T) {
_, parent := Start(context.Background(), "parent", 2)
parent.Add(2) // parent's own work is complete

ctx := context.WithValue(context.Background(), spanKeyName, parent)
_, _ = Start(ctx, "child", 0)

got := parent.Progress()
if got.Count > got.Total {
t.Fatalf("Progress.Count (%d) exceeds Progress.Total (%d)", got.Count, got.Total)
}
}
Loading