Skip to content

Commit 309df9f

Browse files
Copilotcschleiden
andcommitted
Add queue display to diag UI - backend and frontend changes
Co-authored-by: cschleiden <[email protected]>
1 parent 8cc8dc5 commit 309df9f

File tree

10 files changed

+112
-9
lines changed

10 files changed

+112
-9
lines changed

diag/app/build/asset-manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"files": {
33
"main.css": "./static/css/main.8b0db0ad.css",
4-
"main.js": "./static/js/main.92464401.js",
4+
"main.js": "./static/js/main.b95745dd.js",
55
"index.html": "./index.html",
66
"main.8b0db0ad.css.map": "./static/css/main.8b0db0ad.css.map",
7-
"main.92464401.js.map": "./static/js/main.92464401.js.map"
7+
"main.b95745dd.js.map": "./static/js/main.b95745dd.js.map"
88
},
99
"entrypoints": [
1010
"static/css/main.8b0db0ad.css",
11-
"static/js/main.92464401.js"
11+
"static/js/main.b95745dd.js"
1212
]
1313
}

diag/app/build/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>go-workflows</title><script defer="defer" src="./static/js/main.92464401.js"></script><link href="./static/css/main.8b0db0ad.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
1+
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><title>go-workflows</title><script defer="defer" src="./static/js/main.b95745dd.js"></script><link href="./static/css/main.8b0db0ad.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>

diag/app/build/static/js/main.92464401.js.map

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

diag/app/build/static/js/main.b95745dd.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

diag/app/src/Home.tsx

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import React from "react";
55
import useFetch from "react-fetch-hook";
66
import { LinkContainer } from "react-router-bootstrap";
77
import { WorkflowInstance, WorkflowInstanceState } from "./Components";
8-
import { WorkflowInstanceRef } from "./client";
8+
import { WorkflowInstanceRef, Stats } from "./client";
99

1010
function useQuery() {
1111
const { search } = useLocation();
@@ -26,12 +26,78 @@ function Home() {
2626
(afterId ? `&after=${afterId}` : "")
2727
);
2828

29+
const { data: stats } = useFetch<Stats>(
30+
document.location.pathname + "api/stats"
31+
);
32+
2933
return (
3034
<div className="App">
3135
<header className="App-header">
3236
<h2>Instances</h2>
3337
</header>
3438

39+
{stats && (
40+
<div className="mb-3">
41+
<h5>Queue Statistics</h5>
42+
<div className="row">
43+
<div className="col-md-6">
44+
<h6>Workflow Queues</h6>
45+
{Object.keys(stats.PendingWorkflowTasks || {}).length > 0 ? (
46+
<Table striped bordered size="sm">
47+
<thead>
48+
<tr>
49+
<th>Queue Name</th>
50+
<th>Pending Tasks</th>
51+
</tr>
52+
</thead>
53+
<tbody>
54+
{Object.entries(stats.PendingWorkflowTasks || {}).map(
55+
([queue, count]) => (
56+
<tr key={queue}>
57+
<td>
58+
<code>{queue}</code>
59+
</td>
60+
<td>{count}</td>
61+
</tr>
62+
)
63+
)}
64+
</tbody>
65+
</Table>
66+
) : (
67+
<p className="text-muted">No workflow queues with pending tasks</p>
68+
)}
69+
</div>
70+
<div className="col-md-6">
71+
<h6>Activity Queues</h6>
72+
{Object.keys(stats.PendingActivityTasks || {}).length > 0 ? (
73+
<Table striped bordered size="sm">
74+
<thead>
75+
<tr>
76+
<th>Queue Name</th>
77+
<th>Pending Tasks</th>
78+
</tr>
79+
</thead>
80+
<tbody>
81+
{Object.entries(stats.PendingActivityTasks || {}).map(
82+
([queue, count]) => (
83+
<tr key={queue}>
84+
<td>
85+
<code>{queue}</code>
86+
</td>
87+
<td>{count}</td>
88+
</tr>
89+
)
90+
)}
91+
</tbody>
92+
</Table>
93+
) : (
94+
<p className="text-muted">No activity queues with pending tasks</p>
95+
)}
96+
</div>
97+
</div>
98+
</div>
99+
)}
100+
35101
{isLoading && <div>Loading...</div>}
36102

37103
{!isLoading && (
@@ -41,6 +107,7 @@ function Home() {
41107
<tr>
42108
<th>Instance ID</th>
43109
<th>Parent Instance ID</th>
110+
<th>Queue</th>
44111
<th>Created At</th>
45112
<th>Completed At</th>
46113
<th style={{ textAlign: "center" }}>State</th>
@@ -65,6 +132,9 @@ function Home() {
65132
</Link>
66133
)}
67134
</td>
135+
<td>
136+
<code>{i.queue}</code>
137+
</td>
68138
<td>
69139
<code>{i.created_at}</code>
70140
</td>

diag/app/src/Instance.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,16 @@ function Instance() {
184184
<code>{event.attributes?.name}</code>
185185
</div>
186186
)}
187+
{(event.type === "ActivityScheduled" && event.attributes?.queue) && (
188+
<div className="flex-grow-1 text-secondary small">
189+
Queue: <code>{event.attributes.queue}</code>
190+
</div>
191+
)}
192+
{(event.type === "SubWorkflowScheduled" && event.attributes?.sub_workflow_queue) && (
193+
<div className="flex-grow-1 text-secondary small">
194+
Queue: <code>{event.attributes.sub_workflow_queue}</code>
195+
</div>
196+
)}
187197
<div>{event.timestamp}</div>
188198
</h5>
189199
</Accordion.Header>

diag/app/src/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,9 @@ export type WorkflowInstanceTree = WorkflowInstanceRef & {
4747
error?: boolean;
4848
children: WorkflowInstanceTree[];
4949
};
50+
51+
export interface Stats {
52+
ActiveWorkflowInstances: number;
53+
PendingActivityTasks: Record<string, number>;
54+
PendingWorkflowTasks: Record<string, number>;
55+
}

diag/diag.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ func NewServeMux(backend Backend) *http.ServeMux {
2929

3030
relativeURL := strings.TrimPrefix(r.URL.Path, "/api/")
3131

32+
// /api/stats
33+
if relativeURL == "stats" {
34+
stats, err := backend.GetStats(r.Context())
35+
if err != nil {
36+
w.WriteHeader(http.StatusInternalServerError)
37+
return
38+
}
39+
40+
w.Header().Add("Content-Type", "application/json")
41+
if err := json.NewEncoder(w).Encode(stats); err != nil {
42+
w.WriteHeader(http.StatusInternalServerError)
43+
return
44+
}
45+
46+
return
47+
}
48+
3249
// /api/
3350
if relativeURL == "" {
3451
// Index

0 commit comments

Comments
 (0)