-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(block-scheduler): status page shows completed jobs (#15580)
Signed-off-by: Owen Diehl <[email protected]> Co-authored-by: Ashwanth <[email protected]>
- Loading branch information
1 parent
780173a
commit 10194f7
Showing
7 changed files
with
225 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package scheduler | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCircularBuffer_Range(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
capacity int | ||
input []int | ||
want []int | ||
}{ | ||
{ | ||
name: "empty buffer", | ||
capacity: 3, | ||
input: []int{}, | ||
want: []int{}, | ||
}, | ||
{ | ||
name: "partially filled buffer", | ||
capacity: 3, | ||
input: []int{1, 2}, | ||
want: []int{1, 2}, | ||
}, | ||
{ | ||
name: "full buffer", | ||
capacity: 3, | ||
input: []int{1, 2, 3}, | ||
want: []int{1, 2, 3}, | ||
}, | ||
{ | ||
name: "buffer with eviction", | ||
capacity: 3, | ||
input: []int{1, 2, 3, 4, 5}, | ||
want: []int{3, 4, 5}, // oldest elements (1,2) were evicted | ||
}, | ||
{ | ||
name: "buffer with multiple evictions", | ||
capacity: 2, | ||
input: []int{1, 2, 3, 4, 5}, | ||
want: []int{4, 5}, // only newest elements remain | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
// Create and fill buffer | ||
buf := NewCircularBuffer[int](tt.capacity) | ||
for _, v := range tt.input { | ||
buf.Push(v) | ||
} | ||
|
||
// Use Range to collect elements | ||
got := make([]int, 0) | ||
buf.Range(func(v int) bool { | ||
got = append(got, v) | ||
return true | ||
}) | ||
|
||
require.Equal(t, tt.want, got, "Range should iterate in order from oldest to newest") | ||
}) | ||
} | ||
} | ||
|
||
func TestCircularBuffer_Range_EarlyStop(t *testing.T) { | ||
buf := NewCircularBuffer[int](5) | ||
for i := 1; i <= 5; i++ { | ||
buf.Push(i) | ||
} | ||
|
||
var got []int | ||
buf.Range(func(v int) bool { | ||
got = append(got, v) | ||
return v != 3 // stop after seeing 3 | ||
}) | ||
|
||
require.Equal(t, []int{1, 2, 3}, got, "Range should stop when function returns false") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//go:build preview | ||
|
||
package scheduler | ||
|
||
import ( | ||
"fmt" | ||
"net/http/httptest" | ||
"testing" | ||
"time" | ||
|
||
"github.com/twmb/franz-go/pkg/kadm" | ||
|
||
"github.com/grafana/loki/v3/pkg/blockbuilder/types" | ||
) | ||
|
||
// TestPreview is a utility test that runs a local server with the status page. | ||
// Run it with: go test -tags=preview -v -run TestPreview | ||
func TestPreview(t *testing.T) { | ||
// Setup mock data with varied timestamps | ||
now := time.Now() | ||
mockLister := &mockQueueLister{ | ||
pendingJobs: []JobWithMetadata{ | ||
{Job: types.NewJob(11, types.Offsets{Min: 11, Max: 20}), UpdateTime: now.Add(-2 * time.Hour), Priority: 23}, | ||
{Job: types.NewJob(22, types.Offsets{Min: 21, Max: 30}), UpdateTime: now.Add(-1 * time.Hour), Priority: 42}, | ||
{Job: types.NewJob(33, types.Offsets{Min: 22, Max: 40}), UpdateTime: now.Add(-30 * time.Minute), Priority: 11}, | ||
}, | ||
inProgressJobs: []JobWithMetadata{ | ||
{Job: types.NewJob(44, types.Offsets{Min: 1, Max: 10}), StartTime: now.Add(-4 * time.Hour), UpdateTime: now.Add(-3 * time.Hour)}, | ||
{Job: types.NewJob(55, types.Offsets{Min: 11, Max: 110}), StartTime: now.Add(-5 * time.Hour), UpdateTime: now.Add(-4 * time.Hour)}, | ||
}, | ||
completedJobs: []JobWithMetadata{ | ||
{Job: types.NewJob(66, types.Offsets{Min: 1, Max: 50}), StartTime: now.Add(-8 * time.Hour), UpdateTime: now.Add(-7 * time.Hour), Status: types.JobStatusComplete}, | ||
{Job: types.NewJob(77, types.Offsets{Min: 51, Max: 100}), StartTime: now.Add(-6 * time.Hour), UpdateTime: now.Add(-5 * time.Hour), Status: types.JobStatusComplete}, | ||
{Job: types.NewJob(88, types.Offsets{Min: 101, Max: 150}), StartTime: now.Add(-4 * time.Hour), UpdateTime: now.Add(-3 * time.Hour), Status: types.JobStatusFailed}, | ||
{Job: types.NewJob(99, types.Offsets{Min: 151, Max: 200}), StartTime: now.Add(-2 * time.Hour), UpdateTime: now.Add(-1 * time.Hour), Status: types.JobStatusComplete}, | ||
}, | ||
} | ||
|
||
mockReader := &mockOffsetReader{ | ||
groupLag: map[int32]kadm.GroupMemberLag{ | ||
0: { | ||
Lag: 10, | ||
Partition: 3, | ||
End: kadm.ListedOffset{Offset: 100}, | ||
Commit: kadm.Offset{At: 90}, | ||
}, | ||
1: { | ||
Lag: 0, | ||
Partition: 1, | ||
End: kadm.ListedOffset{Offset: 100}, | ||
Commit: kadm.Offset{At: 100}, | ||
}, | ||
2: { | ||
Lag: 233, | ||
Partition: 2, | ||
End: kadm.ListedOffset{Offset: 333}, | ||
Commit: kadm.Offset{At: 100}, | ||
}, | ||
}, | ||
} | ||
|
||
handler := newStatusPageHandler(mockLister, mockReader, time.Hour) | ||
|
||
// Start local server | ||
server := httptest.NewServer(handler) | ||
defer server.Close() | ||
|
||
fmt.Printf("\n\n=== Preview server running ===\nOpen this URL in your browser:\n%s\nPress Ctrl+C to stop the server\n\n", server.URL) | ||
|
||
// Keep server running until interrupted | ||
select {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters