-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(block-scheduler): status page shows completed jobs #15580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: i guess we could just remove
status_test.go
since this is a better way to preview the page