Skip to content

Commit 2e5952a

Browse files
authored
Display crawl time usage history table (#1304)
Partially resolves #1223, fixes #1298 - Adds crawl usage table in dashboard under metrics - Shows skeleton loading indicator when metrics are loading (@Shrinks99 feel free to adjust how this looks) - Shows max number of concurrent crawls running if any are running ("`running` / `max` Crawls Running")
1 parent e274462 commit 2e5952a

File tree

2 files changed

+85
-8
lines changed

2 files changed

+85
-8
lines changed

frontend/src/pages/org/dashboard.ts

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { when } from "lit/directives/when.js";
44
import { ifDefined } from "lit/directives/if-defined.js";
55
import { msg, localized, str } from "@lit/localize";
66
import type { SlSelectEvent } from "@shoelace-style/shoelace";
7+
import humanizeDuration from "pretty-ms";
78

89
import LiteElement, { html } from "../../utils/LiteElement";
910
import type { AuthState } from "../../utils/AuthService";
@@ -180,7 +181,10 @@ export class Dashboard extends LiteElement {
180181
(metrics) => html`
181182
<dl>
182183
${this.renderStat({
183-
value: metrics.workflowsRunningCount,
184+
value:
185+
metrics.workflowsRunningCount && metrics.maxConcurrentCrawls
186+
? `${metrics.workflowsRunningCount} / ${metrics.maxConcurrentCrawls}`
187+
: metrics.workflowsRunningCount,
184188
singleLabel: msg("Crawl Running"),
185189
pluralLabel: msg("Crawls Running"),
186190
iconProps: {
@@ -224,6 +228,7 @@ export class Dashboard extends LiteElement {
224228
`
225229
)}
226230
</div>
231+
<section class="mt-10">${this.renderUsageHistory()}</section>
227232
</main> `;
228233
}
229234

@@ -337,17 +342,16 @@ export class Dashboard extends LiteElement {
337342
renderFooter?: (metric: Metrics) => TemplateResult
338343
) {
339344
return html`
340-
<section
341-
class="flex-1 flex flex-col border rounded p-4 transition-opacity delay-75 ${this
342-
.metrics
343-
? "opacity-100"
344-
: "opacity-0"}"
345-
>
345+
<section class="flex-1 flex flex-col border rounded p-4">
346346
<h2 class="text-lg font-semibold leading-none border-b pb-3 mb-3">
347347
${title}
348348
</h2>
349349
<div class="flex-1">
350-
${when(this.metrics, () => renderContent(this.metrics!))}
350+
${when(
351+
this.metrics,
352+
() => renderContent(this.metrics!),
353+
this.renderCardSkeleton
354+
)}
351355
</div>
352356
${when(renderFooter && this.metrics, () =>
353357
renderFooter!(this.metrics!)
@@ -394,6 +398,71 @@ export class Dashboard extends LiteElement {
394398
`;
395399
}
396400

401+
private renderCardSkeleton = () =>
402+
html`
403+
<sl-skeleton class="mb-3" effect="sheen"></sl-skeleton>
404+
<sl-skeleton class="mb-3" effect="sheen"></sl-skeleton>
405+
<sl-skeleton class="mb-3" effect="sheen"></sl-skeleton>
406+
<sl-skeleton class="mb-3" effect="sheen"></sl-skeleton>
407+
`;
408+
409+
// TODO fix style when data-table is converted to slots
410+
readonly usageTableCols = [
411+
msg("Month"),
412+
html`
413+
${msg("Execution Time")}
414+
<sl-tooltip>
415+
<div slot="content" style="text-transform: initial">
416+
${msg("Total running time of all crawler instances")}
417+
</div>
418+
<sl-icon name="info-circle" style="vertical-align: -.175em"></sl-icon>
419+
</sl-tooltip>
420+
`,
421+
html`
422+
${msg("Total Crawl Duration")}
423+
<sl-tooltip>
424+
<div slot="content" style="text-transform: initial">
425+
${msg("Total time elapsed between when crawl starts and ends")}
426+
</div>
427+
<sl-icon name="info-circle" style="vertical-align: -.175em"></sl-icon>
428+
</sl-tooltip>
429+
`,
430+
];
431+
432+
private renderUsageHistory() {
433+
if (!this.org) return;
434+
const rows = Object.entries(this.org.usage || {})
435+
// Sort latest
436+
.reverse()
437+
.map(([mY, crawlTime]) => {
438+
const value = this.org!.crawlExecSeconds?.[mY];
439+
return [
440+
html`
441+
<sl-format-date
442+
date="${mY}-01T00:00:00.000Z"
443+
time-zone="utc"
444+
month="long"
445+
year="numeric"
446+
>
447+
</sl-format-date>
448+
`,
449+
value ? humanizeDuration(value * 1000) : "--",
450+
humanizeDuration((crawlTime || 0) * 1000),
451+
];
452+
});
453+
return html`
454+
<h2 class="text-lg font-semibold leading-none mb-6">
455+
${msg("Usage History")}
456+
</h2>
457+
<div class="border rounded overflow-hidden">
458+
<btrix-data-table
459+
.columns=${this.usageTableCols}
460+
.rows=${rows}
461+
></btrix-data-table>
462+
</div>
463+
`;
464+
}
465+
397466
private renderPercentage(ratio: number) {
398467
const percent = ratio * 100;
399468
if (percent < 1) return `<1%`;

frontend/src/types/org.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export type OrgData = {
1414
slug: string;
1515
quotas: Record<string, number>;
1616
bytesStored: number;
17+
usage: {
18+
// Keyed by {4-digit year}-{2-digit month}
19+
[key: string]: number;
20+
} | null;
21+
crawlExecSeconds: {
22+
// Keyed by {4-digit year}-{2-digit month}
23+
[key: string]: number;
24+
} | null;
1725
users?: {
1826
[id: string]: {
1927
role: (typeof AccessCode)[UserRole];

0 commit comments

Comments
 (0)