Skip to content

Commit

Permalink
Add filtering the the scheduler's operations page
Browse files Browse the repository at this point in the history
This change adds buttons to the operations page to filter operation by
ones that are queued, executing, or completed. It also adds the ability
to filter operations by an invocation ID, meaning operations belonging
to a certain user or build can be displayed.
  • Loading branch information
EdSchouten committed Oct 14, 2022
1 parent 0cc2c3f commit 91bd2fa
Show file tree
Hide file tree
Showing 7 changed files with 482 additions and 349 deletions.
54 changes: 39 additions & 15 deletions cmd/bb_scheduler/build_queue_state_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,26 @@ func (s *buildQueueStateService) handleGetOperation(w http.ResponseWriter, req *
}

func (s *buildQueueStateService) handleListOperations(w http.ResponseWriter, req *http.Request) {
query := req.URL.Query()
var filterInvocationID *anypb.Any
if filterInvocationIDString := query.Get("filter_invocation_id"); filterInvocationIDString != "" {
var invocationID anypb.Any
if err := protojson.Unmarshal([]byte(filterInvocationIDString), &invocationID); err != nil {
renderError(w, status.Error(codes.InvalidArgument, "Invalid filter invocation ID"))
return
}
filterInvocationID = &invocationID
}

filterStageString := query.Get("filter_stage")
filterStageValue, ok := remoteexecution.ExecutionStage_Value_value[filterStageString]
if !ok {
renderError(w, status.Error(codes.InvalidArgument, "Invalid filter stage"))
return
}

var startAfter *buildqueuestate.ListOperationsRequest_StartAfter
if startAfterParameter := req.URL.Query().Get("start_after"); startAfterParameter != "" {
if startAfterParameter := query.Get("start_after"); startAfterParameter != "" {
var startAfterMessage buildqueuestate.ListOperationsRequest_StartAfter
if err := protojson.Unmarshal([]byte(startAfterParameter), &startAfterMessage); err != nil {
renderError(w, util.StatusWrapWithCode(err, codes.InvalidArgument, "Failed to parse start after message"))
Expand All @@ -288,8 +306,10 @@ func (s *buildQueueStateService) handleListOperations(w http.ResponseWriter, req

ctx := req.Context()
response, err := s.buildQueue.ListOperations(ctx, &buildqueuestate.ListOperationsRequest{
PageSize: pageSize,
StartAfter: startAfter,
FilterInvocationId: filterInvocationID,
FilterStage: remoteexecution.ExecutionStage_Value(filterStageValue),
PageSize: pageSize,
StartAfter: startAfter,
})
if err != nil {
renderError(w, util.StatusWrap(err, "Failed to list operations"))
Expand All @@ -305,19 +325,23 @@ func (s *buildQueueStateService) handleListOperations(w http.ResponseWriter, req
}

if err := templates.ExecuteTemplate(w, "list_operation_state.html", struct {
BrowserURL *url.URL
Now time.Time
PaginationInfo *buildqueuestate.PaginationInfo
EndIndex int
StartAfter *buildqueuestate.ListOperationsRequest_StartAfter
Operations []*buildqueuestate.OperationState
BrowserURL *url.URL
Now time.Time
PaginationInfo *buildqueuestate.PaginationInfo
EndIndex int
FilterInvocationID *anypb.Any
FilterStage string
StartAfter *buildqueuestate.ListOperationsRequest_StartAfter
Operations []*buildqueuestate.OperationState
}{
BrowserURL: s.browserURL,
Now: s.clock.Now(),
PaginationInfo: response.PaginationInfo,
EndIndex: int(response.PaginationInfo.StartIndex) + len(response.Operations),
StartAfter: nextStartAfter,
Operations: response.Operations,
BrowserURL: s.browserURL,
Now: s.clock.Now(),
PaginationInfo: response.PaginationInfo,
EndIndex: int(response.PaginationInfo.StartIndex) + len(response.Operations),
FilterInvocationID: filterInvocationID,
FilterStage: filterStageString,
StartAfter: nextStartAfter,
Operations: response.Operations,
}); err != nil {
log.Print(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/bb_scheduler/templates/get_build_queue_state.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h1 class="my-4">Build queue</h1>
<table class="table" style="table-layout: fixed">
<tr>
<th style="width: 25%">Total number of operations:</th>
<td style="width: 75%"><a href="operations">{{.OperationsCount}}</a></td>
<td style="width: 75%"><a href="operations?filter_stage=UNKNOWN">{{.OperationsCount}}</a></td>
</tr>
</table>

Expand Down
2 changes: 1 addition & 1 deletion cmd/bb_scheduler/templates/get_operation_state.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h1 class="my-4">Operation {{.OperationName}}</h1>
<td style="width: 75%; word-break: break-all">
<ul>
{{range $invocationName.Ids}}
<li>{{proto_to_json .}}</li>
<li><a href="operations?filter_invocation_id={{proto_to_json .}}&amp;filter_stage=UNKNOWN">{{proto_to_json .}}</a></li>
{{end}}
</ul>
</td>
Expand Down
105 changes: 78 additions & 27 deletions cmd/bb_scheduler/templates/list_operation_state.html
Original file line number Diff line number Diff line change
@@ -1,34 +1,85 @@
{{template "header.html" "success"}}

<h1 class="my-4">All operations</h1>
<h1 class="my-4">Operations</h1>

<nav>
<ul class="justify-content-end pagination">
{{if eq .PaginationInfo.StartIndex 0}}
<li class="disabled page-item">
<span class="page-link">◀◀</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?">◀◀</a>
</li>
{{end}}
<li class="active page-item">
<span class="page-link text-nowrap">
Showing operations [{{.PaginationInfo.StartIndex}}, {{.EndIndex}}) of {{.PaginationInfo.TotalEntries}} in total
</span>
</li>
{{with .StartAfter}}
<li class="page-item">
<a class="page-link" href="?start_after={{proto_to_json .}}"></a>
</li>
{{else}}
<li class="disabled page-item">
<span class="page-link"></span>
{{with .FilterInvocationID}}
<table class="table" style="table-layout: fixed">
<tr>
<th style="width: 25%">Invocation ID:</th>
<td style="width: 75%; word-break: break-all">{{proto_to_json .}}</td>
</tr>
</table>
{{end}}

<div class="d-flex justify-content-between">
<nav>
<ul class="pagination">
{{if eq .FilterStage "QUEUED"}}
<li class="active page-item">
<span class="page-link">Queued</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage=QUEUED">Queued</a>
</li>
{{end}}
{{if eq .FilterStage "EXECUTING"}}
<li class="active page-item">
<span class="page-link">Executing</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage=EXECUTING">Executing</a>
</li>
{{end}}
{{if eq .FilterStage "COMPLETED"}}
<li class="active page-item">
<span class="page-link">Completed</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage=COMPLETED">Completed</a>
</li>
{{end}}
{{if eq .FilterStage "UNKNOWN"}}
<li class="active page-item">
<span class="page-link">All</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage=UNKNOWN">All</a>
</li>
{{end}}
</ul>
</nav>
<nav>
<ul class="pagination">
{{if eq .PaginationInfo.StartIndex 0}}
<li class="disabled page-item">
<span class="page-link">◀◀</span>
</li>
{{else}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage={{.FilterStage}}">◀◀</a>
</li>
{{end}}
<li class="active page-item">
<span class="page-link text-nowrap">
Showing operations [{{.PaginationInfo.StartIndex}}, {{.EndIndex}}) of {{.PaginationInfo.TotalEntries}} in total
</span>
</li>
{{end}}
</ul>
</nav>
{{if .StartAfter}}
<li class="page-item">
<a class="page-link" href="?{{with .FilterInvocationID}}filter_invocation_id={{proto_to_json .}}&amp;{{end}}filter_stage={{.FilterStage}}&amp;start_after={{proto_to_json .StartAfter}}"></a>
</li>
{{else}}
<li class="disabled page-item">
<span class="page-link"></span>
</li>
{{end}}
</ul>
</nav>
</div>

<div class="table-responsive">
<table class="align-middle border-dark table table-bordered table-sm">
Expand Down
Loading

0 comments on commit 91bd2fa

Please sign in to comment.