Skip to content

Commit

Permalink
alerts_pub
Browse files Browse the repository at this point in the history
  • Loading branch information
epompeii committed Aug 26, 2024
1 parent aa8a5a6 commit 27b1ce2
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 68 deletions.
120 changes: 120 additions & 0 deletions services/console/src/config/project/alerts_pub.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import type { Params } from "astro";
import { Button, Card, Display } from "../types";

const alertsPubConfig = {
header: {
keys: [["benchmark", "name"]],
buttons: [
{
kind: Button.CONSOLE,
resource: "alerts",
param: "alert",
},
{ kind: Button.PERF },
],
},
deck: {
url: (params: Params) =>
`/v0/projects/${params?.project}/alerts/${params?.alert}`,
cards: [
{
kind: Card.NESTED_FIELD,
label: "Status",
keys: ["status"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Branch",
keys: ["threshold", "branch", "name"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Testbed",
keys: ["threshold", "testbed", "name"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Benchmark",
keys: ["benchmark", "name"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Measure",
keys: ["threshold", "measure", "name"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Metric",
keys: ["benchmark", "metric", "value"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Boundary Limit Violation",
keys: ["limit"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Boundary Baseline",
keys: ["benchmark", "boundary", "baseline"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Lower Boundary Limit",
keys: ["benchmark", "boundary", "lower_limit"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Upper Boundary Limit",
keys: ["benchmark", "boundary", "upper_limit"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Threshold Model Test",
keys: ["threshold", "model", "test"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Lower Boundary",
keys: ["threshold", "model", "lower_boundary"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Upper Boundary",
keys: ["threshold", "model", "upper_boundary"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Minimum Sample Size",
keys: ["threshold", "model", "min_sample_size"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Maximum Sample Size",
keys: ["threshold", "model", "max_sample_size"],
display: Display.RAW,
},
{
kind: Card.NESTED_FIELD,
label: "Window Size (seconds)",
keys: ["threshold", "model", "window"],
display: Display.RAW,
},
],
},
};

export default alertsPubConfig;
81 changes: 14 additions & 67 deletions services/console/src/pages/perf/[project]/alerts/[alert].astro
Original file line number Diff line number Diff line change
@@ -1,73 +1,20 @@
---
export const prerender = false;
import PerfLayout from "../../../../layouts/perf/PerfLayout.astro";
import { AlertStatus, type JsonAlert } from "../../../../types/bencher";
import PublicAlert from "../../../../components/perf/PublicAlert";
import Tetris from "../../../../components/site/Tetris.astro";
import { fetchSSR } from "../../../../components/perf/util";
import * as Sentry from "@sentry/astro";
// Using `meta.env` requires `prerender = false`
const BENCHER_API_URL = import.meta.env.BENCHER_API_URL;
const INTERNAL_API_URL = import.meta.env.INTERNAL_API_URL;
const params = Astro.params;
const getAlertUrl = `${INTERNAL_API_URL ?? BENCHER_API_URL}/v0/projects/${
params.project
}/alerts/${params.alert}`;
let jsonAlert: undefined | JsonAlert;
let title = "Public Alert";
let description = "View a continuous benchmarking alert";
let notFound = false;
if (params.project && params.project !== "undefined") {
try {
const alertResponse = await fetchSSR(getAlertUrl);
jsonAlert = await alertResponse.json();
if (jsonAlert?.uuid) {
title = `${jsonAlert?.benchmark?.name} Alert (${
jsonAlert?.status === AlertStatus.Active ? "🔔" : "🔕"
})`;
description = `View a continuous benchmarking alert for the ${jsonAlert?.benchmark?.name} benchmark on Bencher`;
} else {
title = "Not Found";
description = "Public Project Alert not found";
notFound = true;
}
} catch (e) {
console.error(`Failed to fetch alert data: ${e}`);
Sentry.captureException(e);
}
}
import PerfResource from "../../../../layouts/perf/PerfResource.astro";
import alertsPubConfig from "../../../../config/project/alerts_pub";
import { AlertStatus } from "../../../../types/bencher";
---

<PerfLayout
title={title}
<PerfResource
title={(json) => json ? `${json?.benchmark?.name} Alert (${
json?.status === AlertStatus.Active ? "🔔" : "🔕"
})` : "Public Alert"}
titleFmt={(title) => `🚨 ${title}`}
description={description}
published={jsonAlert?.created}
modified={jsonAlert?.modified}
>
{ notFound ?
<section class="section">
<div class="container">
<div class="columns is-mobile">
<div class="column">
<h1 class="title is-1">Alert Not Found</h1>
<hr />
<p>Could not find Alert <code>{params.alert}</code> for Project <code>{params.project}</code></p>
<p>The Project may be private or the Alert may not exist.</p>
<br />
<a class="button" href={`/perf/${params.project}`}>Go to Project</a>
</div>
<div class="column">
<Tetris />
</div>
</div>
</div>
</section>
:
<PublicAlert client:only="solid-js" apiUrl={BENCHER_API_URL} params={params} data={jsonAlert} />
}
</PerfLayout>
description={(json) => json ? `View a continuous benchmarking alert for the ${json?.benchmark?.name} benchmark on Bencher` : "View a continuous benchmarking alert"}
created={(json) => json ? json.created : ""}
modified={(json) => json ? json.modified : ""}
url={(params) => `/v0/projects/${params.project}/alerts/${params.alert}`}
param="alert"
config={alertsPubConfig}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export const prerender = false;
import PerfResource from "../../../../layouts/perf/PerfResource.astro";
import metricsPubConfig from "../../../../config/project/metrics_pub";
import { Button, Operation } from "../../../../config/types";
---

<PerfResource
Expand Down

0 comments on commit 27b1ce2

Please sign in to comment.