View: the pipelines page takes a limit, the newest 20 by default
The design gives list a limit with a default of 20; the view asked 20 always and neither the web page nor the terminal view could ask another. The web list takes a limit query parameter and the terminal view a -limit flag; a followed branch's list is read at the default, any other limit is read at the asking. Issue 1983, review round 1 finding 2. Builds: design 47 H2 H-A-467 (1)
This commit is contained in:
@@ -37,11 +37,16 @@ func run(args []string, socket string, out, errOut io.Writer) int {
|
||||
asJSON := fs.Bool("json", false, "print the rows as JSON")
|
||||
follow := fs.Bool("follow", false, "pipelines and pipeline: print again at each change the runner's events say, until interrupted")
|
||||
next := fs.String("next", "", "pipeline: the cursor of the next page a pipeline's answer named")
|
||||
limit := fs.Int("limit", view.DefaultPipelinesLimit, "pipelines: the newest this many pipelines of the branch")
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return 2
|
||||
}
|
||||
if fs.NArg() > 0 && (fs.Arg(0) == "pipelines" || fs.Arg(0) == "pipeline") {
|
||||
return pipelines(socket, fs.Args(), *next, *follow, *asJSON, out, errOut)
|
||||
if *limit < 1 {
|
||||
fmt.Fprintln(errOut, "mesh-delivery-cli: -limit is a number of at least one")
|
||||
return 2
|
||||
}
|
||||
return pipelines(socket, fs.Args(), *next, *limit, *follow, *asJSON, out, errOut)
|
||||
}
|
||||
if fs.NArg() > 0 && fs.Arg(0) == "holds" {
|
||||
return holds(socket, *asJSON, out, errOut)
|
||||
@@ -62,7 +67,7 @@ func run(args []string, socket string, out, errOut io.Writer) int {
|
||||
}
|
||||
if fs.NArg() > 0 {
|
||||
if fs.Arg(0) != "answer" || fs.NArg() < 3 {
|
||||
fmt.Fprintln(errOut, "mesh-delivery-cli shows the rows, or answers: mesh-delivery-cli answer <ask key> <option> [words]; holds; hold-release|hold-keep <module> <fingerprint> [words]; [-follow] pipelines [branch]; [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
||||
fmt.Fprintln(errOut, "mesh-delivery-cli shows the rows, or answers: mesh-delivery-cli answer <ask key> <option> [words]; holds; hold-release|hold-keep <module> <fingerprint> [words]; [-follow] [-limit <n>] pipelines [branch]; [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
||||
return 2
|
||||
}
|
||||
key, option := fs.Arg(1), fs.Arg(2)
|
||||
@@ -93,7 +98,7 @@ func run(args []string, socket string, out, errOut io.Writer) int {
|
||||
|
||||
// pipelines prints the pipelines page (design 47 H2 H-A-467): `pipelines [branch]` the newest pipelines of a branch (main by
|
||||
// default), `pipeline <pipeline> [mover]` one pipeline's mover rows or one mover's steps; with -follow again at each change.
|
||||
func pipelines(socket string, args []string, next string, follow, asJSON bool, out, errOut io.Writer) int {
|
||||
func pipelines(socket string, args []string, next string, limit int, follow, asJSON bool, out, errOut io.Writer) int {
|
||||
var branch, pipeline, mover string
|
||||
switch {
|
||||
case args[0] == "pipelines" && len(args) <= 2:
|
||||
@@ -106,11 +111,11 @@ func pipelines(socket string, args []string, next string, follow, asJSON bool, o
|
||||
mover = args[2]
|
||||
}
|
||||
default:
|
||||
fmt.Fprintln(errOut, "mesh-delivery-cli [-follow] pipelines [branch]; mesh-delivery-cli [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
||||
fmt.Fprintln(errOut, "mesh-delivery-cli [-follow] [-limit <n>] pipelines [branch]; mesh-delivery-cli [-follow] [-next <cursor>] pipeline <pipeline> [mover]")
|
||||
return 2
|
||||
}
|
||||
var failed error
|
||||
err := view.AskPipelines(socket, branch, pipeline, mover, next, follow, func(page view.PipelinesPage, show *seatShow) bool {
|
||||
err := view.AskPipelines(socket, branch, limit, pipeline, mover, next, follow, func(page view.PipelinesPage, show *seatShow) bool {
|
||||
if follow {
|
||||
fmt.Fprintf(out, "--- %s ---\n", time.Now().Format("15:04:05"))
|
||||
}
|
||||
|
||||
@@ -312,10 +312,13 @@ func TestThePipelinesCommands(t *testing.T) {
|
||||
call := func(key string, body any) (json.RawMessage, error) {
|
||||
switch key {
|
||||
case view.PipelinesListVerb:
|
||||
if in := body.(pseat.ListInput); in.Branch != "next" {
|
||||
in := body.(pseat.ListInput)
|
||||
if in.Branch != "next" {
|
||||
return json.Marshal(pseat.ListAnswer{})
|
||||
}
|
||||
return json.Marshal(pseat.ListAnswer{Rows: []pseat.PipelineRow{{Pipeline: "next.3", Source: 2, Revision: 3, Outcome: "passed", MoverCount: 1, Steps: map[string]int64{"passed": 4}}}})
|
||||
rows := []pseat.PipelineRow{{Pipeline: "next.3", Source: 2, Revision: 3, Outcome: "passed", MoverCount: 1, Steps: map[string]int64{"passed": 4}},
|
||||
{Pipeline: "next.2", Source: 2, Revision: 2, Outcome: "superseded", MoverCount: 1}}
|
||||
return json.Marshal(pseat.ListAnswer{Rows: rows[:min(int(in.Limit), len(rows))]})
|
||||
case view.PipelinesShowVerb:
|
||||
return json.Marshal(pseat.ShowAnswer{Pipeline: pseat.Pipeline{Pipeline: "next.3", Outcome: "passed", Movers: []pseat.Mover{{Module: "alpha", Fingerprint: "src2:aa", Version: "0.2.1"}}},
|
||||
Movers: []pseat.MoverRow{{Module: "alpha", Outcome: "passed"}}})
|
||||
@@ -341,6 +344,8 @@ func TestThePipelinesCommands(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{[]string{"pipelines", "next"}, "next.3 3 2 passed 1 4 0 0 0 0 0 0 0"},
|
||||
{[]string{"pipelines", "next"}, "next.2"}, // the newest 20 by default
|
||||
{[]string{"-limit", "1", "pipelines", "next"}, "next.3"},
|
||||
{[]string{"pipeline", "next.3"}, "alpha src2:aa 0.2.1 passed"},
|
||||
{[]string{"-json", "pipeline", "next.3"}, `"fingerprint": "src2:aa"`},
|
||||
} {
|
||||
@@ -350,7 +355,13 @@ func TestThePipelinesCommands(t *testing.T) {
|
||||
}
|
||||
}
|
||||
var out, errOut bytes.Buffer
|
||||
if code := run([]string{"pipeline"}, path, &out, &errOut); code != 2 {
|
||||
t.Errorf("pipeline naming none = %d", code)
|
||||
if code := run([]string{"-limit", "1", "pipelines", "next"}, path, &out, &errOut); code != 0 || strings.Contains(out.String(), "next.2") {
|
||||
t.Errorf("-limit 1 = %d %q, want only the newest", code, out.String())
|
||||
}
|
||||
for _, args := range [][]string{{"pipeline"}, {"-limit", "0", "pipelines"}} {
|
||||
out.Reset()
|
||||
if code := run(args, path, &out, &errOut); code != 2 {
|
||||
t.Errorf("%v = %d, want 2", args, code)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -896,7 +896,7 @@ func TestProcessWholeSaysTheSourceRevisionIsDelivered(t *testing.T) {
|
||||
pipelines.set(pseat.PipelineRow{Pipeline: "release.9", Source: rev, Revision: 9, Outcome: "passed", MoverCount: 1},
|
||||
pseat.PipelineRow{Pipeline: "release.8", Source: rev, Revision: 8, Outcome: "superseded", MoverCount: 1})
|
||||
var seen [][]string
|
||||
err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], catalogBranch, "", "", "", true, func(page view.PipelinesPage, _ *pseat.ShowAnswer) bool {
|
||||
err = view.AskPipelines(env["MESH_DELIVERY_SOCKET"], catalogBranch, 0, "", "", "", true, func(page view.PipelinesPage, _ *pseat.ShowAnswer) bool {
|
||||
var keys []string
|
||||
for _, r := range page.Rows {
|
||||
keys = append(keys, r.Pipeline)
|
||||
|
||||
@@ -71,9 +71,13 @@ func NewPipelines(call func(key string, body any) (json.RawMessage, error), bran
|
||||
lists: map[string]PipelinesPage{}, subs: map[chan string]struct{}{}, heard: map[string]uint64{}}
|
||||
}
|
||||
|
||||
// List asks the seat's verb list for one branch's newest pipelines in its short form.
|
||||
func (p *Pipelines) List(branch string) ([]seat.PipelineRow, error) {
|
||||
raw, err := p.call(PipelinesListVerb, seat.ListInput{Branch: branch, Limit: DefaultPipelinesLimit})
|
||||
// List asks the seat's verb list for one branch's newest limit pipelines in its short form; a limit below one is the
|
||||
// default's.
|
||||
func (p *Pipelines) List(branch string, limit int) ([]seat.PipelineRow, error) {
|
||||
if limit < 1 {
|
||||
limit = DefaultPipelinesLimit
|
||||
}
|
||||
raw, err := p.call(PipelinesListVerb, seat.ListInput{Branch: branch, Limit: int64(limit)})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s of %s: %w", PipelinesListVerb, branch, err)
|
||||
}
|
||||
@@ -119,22 +123,28 @@ func (p *Pipelines) followed() []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// Page is one branch's newest pipelines: a followed branch's as last read, any other's read now.
|
||||
func (p *Pipelines) Page(branch string) PipelinesPage {
|
||||
// Page is one branch's newest limit pipelines (the default's below one): a followed branch's at the default limit as last
|
||||
// read, any other branch or limit read now.
|
||||
func (p *Pipelines) Page(branch string, limit int) PipelinesPage {
|
||||
if branch = strings.TrimSpace(branch); branch == "" {
|
||||
branch = DefaultPipelinesBranch
|
||||
}
|
||||
p.mu.Lock()
|
||||
page, ok := p.lists[branch]
|
||||
p.mu.Unlock()
|
||||
if ok {
|
||||
return page
|
||||
if limit < 1 {
|
||||
limit = DefaultPipelinesLimit
|
||||
}
|
||||
return p.read(branch)
|
||||
if limit == DefaultPipelinesLimit {
|
||||
p.mu.Lock()
|
||||
page, ok := p.lists[branch]
|
||||
p.mu.Unlock()
|
||||
if ok {
|
||||
return page
|
||||
}
|
||||
}
|
||||
return p.read(branch, limit)
|
||||
}
|
||||
|
||||
func (p *Pipelines) read(branch string) PipelinesPage {
|
||||
rows, err := p.List(branch)
|
||||
func (p *Pipelines) read(branch string, limit int) PipelinesPage {
|
||||
rows, err := p.List(branch, limit)
|
||||
page := PipelinesPage{Branch: branch, Rows: rows}
|
||||
if err != nil {
|
||||
page.Error = err.Error()
|
||||
@@ -149,7 +159,7 @@ func (p *Pipelines) read(branch string) PipelinesPage {
|
||||
func (p *Pipelines) Refresh() {
|
||||
lists := map[string]PipelinesPage{}
|
||||
for _, b := range p.followed() {
|
||||
page := p.read(b)
|
||||
page := p.read(b, DefaultPipelinesLimit)
|
||||
if page.Error != "" {
|
||||
p.logf("the pipelines of %s are not read (read again at the runner's next event): %s", b, page.Error)
|
||||
}
|
||||
|
||||
@@ -31,11 +31,12 @@ func (f *fakeRunner) call(key string, body any) (json.RawMessage, error) {
|
||||
switch key {
|
||||
case PipelinesListVerb:
|
||||
in := body.(seat.ListInput)
|
||||
if in.Limit != DefaultPipelinesLimit || in.Full {
|
||||
if in.Limit < 1 || in.Full {
|
||||
return nil, fmt.Errorf("list asked with limit %d, full %v", in.Limit, in.Full)
|
||||
}
|
||||
f.lists++
|
||||
return json.Marshal(seat.ListAnswer{Rows: f.rows[in.Branch]})
|
||||
rows := f.rows[in.Branch]
|
||||
return json.Marshal(seat.ListAnswer{Rows: rows[:min(int(in.Limit), len(rows))]})
|
||||
case PipelinesShowVerb:
|
||||
in := body.(seat.ShowInput)
|
||||
k := in.Pipeline
|
||||
@@ -109,7 +110,7 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
want []string
|
||||
}{
|
||||
{"the terminal view's list counts the steps per outcome", func() string {
|
||||
return text(func(b *bytes.Buffer) { PipelinesTable(b, p.Page("")) })
|
||||
return text(func(b *bytes.Buffer) { PipelinesTable(b, p.Page("", 0)) })
|
||||
}, []string{"PIPELINES OF main", "PASSED FAILED COULD NOT RUN NOT ASKED WAITING WAITING FOR A BUILD NODE BYPASSED NOTHING TO RUN",
|
||||
"main.12 12 9 2026-10-18", "failed 2 5 1 1 0 0 2 0 0"}},
|
||||
{"the web list links each pipeline and reloads on the view's changes, never a timer", func() string { return web("/pipelines") }, []string{
|
||||
@@ -126,6 +127,10 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
}
|
||||
return text(func(b *bytes.Buffer) { PipelineTable(b, a, "") })
|
||||
}, []string{"PIPELINE main.12: failed, source 9, revision 12", "alpha src2:aa 0.1.4 passed", "beta src2:bb failed unit beta:program: could not run: no build node"}},
|
||||
{"the web list asks the newest limit of a branch", func() string { return web("/pipelines?branch=" + testBranch + "&limit=1") }, []string{
|
||||
"release.8", `name="limit" value="1"`}},
|
||||
{"the web list is the newest 20 by default", func() string { return web("/pipelines?branch=" + testBranch) }, []string{
|
||||
"release.8", "release.7", `name="limit" value="20"`}},
|
||||
{"a pipeline the runner does not hold says so", func() string { return web("/pipelines/show?pipeline=main.99") }, []string{"unreadable: ", "no pipeline main.99"}},
|
||||
{"a delivery links to the newest pipeline of its source revision", func() string {
|
||||
return text(func(b *bytes.Buffer) { Table(b, m.Snapshot()) }) + web("/")
|
||||
@@ -141,6 +146,16 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
if got := web("/pipelines?branch=" + testBranch + "&limit=1"); strings.Contains(got, "release.7") {
|
||||
t.Errorf("the newest 1 shows release.7: %s", got)
|
||||
}
|
||||
for _, l := range []string{"0", "x"} {
|
||||
rec := httptest.NewRecorder()
|
||||
Web(m).ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/pipelines?limit="+l, nil))
|
||||
if rec.Code != http.StatusBadRequest {
|
||||
t.Errorf("limit %s = %d, want 400", l, rec.Code)
|
||||
}
|
||||
}
|
||||
if strings.Contains(web("/pipelines"), "http-equiv=\"refresh\"") || strings.Contains(web("/pipelines/show?pipeline=main.12"), "http-equiv=\"refresh\"") {
|
||||
t.Error("a pipelines page reloads on a timer")
|
||||
}
|
||||
@@ -195,7 +210,7 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
sm.SetPipelines(p)
|
||||
var seen []string
|
||||
heard := false
|
||||
err := AskPipelines(path, "", "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
seen = append(seen, page.Rows[0].Pipeline)
|
||||
if !heard {
|
||||
heard = true
|
||||
@@ -211,13 +226,13 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
t.Fatalf("followed %v, %v", seen, err)
|
||||
}
|
||||
var show *seat.ShowAnswer
|
||||
if err := AskPipelines(path, "", "main.12", "beta", "", false, func(_ PipelinesPage, a *seat.ShowAnswer) bool { show = a; return true }); err != nil {
|
||||
if err := AskPipelines(path, "", 0, "main.12", "beta", "", false, func(_ PipelinesPage, a *seat.ShowAnswer) bool { show = a; return true }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(show.Pipeline.Steps) != 1 || show.Pipeline.Steps[0].Node != "n1" {
|
||||
t.Fatalf("the mover's steps on the socket = %+v", show)
|
||||
}
|
||||
if err := AskPipelines(path, "", "main.99", "", "", false, func(PipelinesPage, *seat.ShowAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
|
||||
if err := AskPipelines(path, "", 0, "main.99", "", "", false, func(PipelinesPage, *seat.ShowAnswer) bool { return true }); err == nil || !strings.Contains(err.Error(), "no pipeline main.99") {
|
||||
t.Fatalf("a pipeline the runner does not hold = %v", err)
|
||||
}
|
||||
})
|
||||
@@ -243,7 +258,7 @@ func TestThePipelinesPage(t *testing.T) {
|
||||
path, sm := served(t)
|
||||
sm.SetPipelines(up)
|
||||
var seen []PipelinesPage
|
||||
err := AskPipelines(path, "", "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
err := AskPipelines(path, "", 0, "", "", "", true, func(page PipelinesPage, _ *seat.ShowAnswer) bool {
|
||||
seen = append(seen, page)
|
||||
if len(seen) == 1 {
|
||||
mu.Lock()
|
||||
|
||||
@@ -152,7 +152,7 @@ const changesScript = `<script>new EventSource({{.Changes}}).onmessage=function(
|
||||
var pipelinesPage = template.Must(template.New("pl").Parse(`<!doctype html><html><head><meta charset="utf-8">
|
||||
<title>Pipelines of {{.Branch}}</title>` + pipelinesStyle + `</head>
|
||||
<body><p><a href="/">What each node runs</a></p><h1>PIPELINES OF {{.Branch}}</h1>
|
||||
<form method="get" action="/pipelines">branch <input name="branch" value="{{.Branch}}"> <button>show</button></form>
|
||||
<form method="get" action="/pipelines">branch <input name="branch" value="{{.Branch}}"> newest <input name="limit" value="{{.Limit}}" size="4"> <button>show</button></form>
|
||||
{{if .Error}}<p>unreadable: {{.Error}}</p>{{else}}<table><tr>{{range .Head}}<th>{{.}}</th>{{end}}</tr>
|
||||
{{range .Rows}}<tr><td><a href="{{.Link}}">{{index .Cells 0}}</a></td>{{range slice .Cells 1}}<td>{{.}}</td>{{end}}</tr>{{end}}</table>{{end}}
|
||||
` + changesScript + `</body></html>`))
|
||||
@@ -242,14 +242,23 @@ func webPipelines(m *Model, w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
pipelinePage.Execute(w, data)
|
||||
default:
|
||||
limit := DefaultPipelinesLimit
|
||||
if l := strings.TrimSpace(q.Get("limit")); l != "" {
|
||||
n, err := strconv.Atoi(l)
|
||||
if err != nil || n < 1 {
|
||||
http.Error(w, "limit is a number of at least one", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
limit = n
|
||||
}
|
||||
v := p.Version()
|
||||
page := p.Page(q.Get("branch"))
|
||||
page := p.Page(q.Get("branch"), limit)
|
||||
var rows []linkedRow
|
||||
for _, row := range page.Rows {
|
||||
rows = append(rows, linkedRow{Cells: PipelineRowText(row), Link: PipelineLink(row.Pipeline, "")})
|
||||
}
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
pipelinesPage.Execute(w, map[string]any{"Branch": page.Branch, "Error": page.Error, "Head": PipelinesHead, "Rows": rows, "Changes": changesLink("", v)})
|
||||
pipelinesPage.Execute(w, map[string]any{"Branch": page.Branch, "Error": page.Error, "Head": PipelinesHead, "Rows": rows, "Limit": limit, "Changes": changesLink("", v)})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ type ask struct {
|
||||
// The pipelines page's asks (design 47 H2 H-A-467): pipelines of a branch, or one pipeline, of a mover when named; follow
|
||||
// keeps the connection and answers again at each change the runner's events say.
|
||||
Branch string `json:"branch,omitempty"`
|
||||
Limit int `json:"limit,omitempty"` // the newest this many of the branch, the default's when left out
|
||||
Pipeline string `json:"pipeline,omitempty"`
|
||||
Mover string `json:"mover,omitempty"`
|
||||
Next string `json:"next,omitempty"`
|
||||
@@ -571,7 +572,7 @@ func answerPipelines(c net.Conn, m *Model, a ask) {
|
||||
v := p.Version()
|
||||
var err error
|
||||
if a.Ask == "pipelines" {
|
||||
err = enc.Encode(p.Page(a.Branch))
|
||||
err = enc.Encode(p.Page(a.Branch, a.Limit))
|
||||
} else if sa, serr := p.Show(a.Pipeline, a.Mover, a.Next); serr != nil {
|
||||
err = enc.Encode(pipelinesRefusal{Refused: serr.Error()})
|
||||
} else {
|
||||
@@ -590,15 +591,16 @@ type pipelinesRefusal struct {
|
||||
Refused string `json:"refused"`
|
||||
}
|
||||
|
||||
// AskPipelines asks the socket at path for one branch's pipelines, or with pipeline set for that pipeline (of mover when
|
||||
// named); with follow, each answers again at each change, handed to each until it answers false or the view leaves.
|
||||
func AskPipelines(path, branch, pipeline, mover, next string, follow bool, each func(PipelinesPage, *seat.ShowAnswer) bool) error {
|
||||
// AskPipelines asks the socket at path for one branch's newest limit pipelines (the default's below one), or with pipeline
|
||||
// set for that pipeline (of mover when named); with follow, each answers again at each change, handed to each until it
|
||||
// answers false or the view leaves.
|
||||
func AskPipelines(path, branch string, limit int, pipeline, mover, next string, follow bool, each func(PipelinesPage, *seat.ShowAnswer) bool) error {
|
||||
c, err := net.DialTimeout("unix", path, 5*time.Second)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot reach the view at %s: %w", path, err)
|
||||
}
|
||||
defer c.Close()
|
||||
a := ask{Ask: "pipelines", Branch: branch, Follow: follow}
|
||||
a := ask{Ask: "pipelines", Branch: branch, Limit: limit, Follow: follow}
|
||||
if pipeline != "" {
|
||||
a = ask{Ask: "pipeline", Pipeline: pipeline, Mover: mover, Next: next, Follow: follow}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user