Skip to content

Commit 02c7a72

Browse files
authored
fix: ensure thresholds are using role-specific metric names (#124)
1 parent 52ce189 commit 02c7a72

6 files changed

Lines changed: 67 additions & 25 deletions

File tree

report/src/components/ChartGrid.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ import LineChart from "./LineChart";
55

66
interface ProvidedProps {
77
data: DataSeries[];
8+
role: "sequencer" | "validator" | null;
89
}
910

10-
const ChartGrid: React.FC<ProvidedProps> = ({ data }: ProvidedProps) => {
11+
const ChartGrid: React.FC<ProvidedProps> = ({ data, role }: ProvidedProps) => {
1112
return (
1213
<div className="charts-container">
1314
{Object.entries(CHART_CONFIG).map(([metricKey, config]) => {
15+
// sequencer and validator have different thresholds
16+
console.log(role, metricKey);
17+
const thresholdKey = role ? `${role}/${metricKey}` : null;
1418
const chartData = data.flatMap((s) => s.data);
1519
const thresholds = data[0]?.thresholds;
1620
const executionMetrics = chartData
@@ -32,7 +36,7 @@ const ChartGrid: React.FC<ProvidedProps> = ({ data }: ProvidedProps) => {
3236

3337
return (
3438
<div key={metricKey} className="chart-container">
35-
<LineChart {...chartProps} />
39+
<LineChart thresholdKey={thresholdKey} {...chartProps} />
3640
</div>
3741
);
3842
})}

report/src/components/ChartSelector.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ export interface SelectedData {
2424

2525
interface ChartSelectorProps {
2626
benchmarkRuns: BenchmarkRuns;
27-
onChangeDataQuery: (data: SelectedData[]) => void;
27+
onChangeDataQuery: (data: DataSelection) => void;
2828
}
2929

30+
export interface DataSelection {
31+
data: SelectedData[];
32+
role: "sequencer" | "validator" | null;
33+
}
34+
35+
export const EmptyDataSelection: DataSelection = {
36+
data: [],
37+
role: null,
38+
};
39+
3040
const ChartSelector = ({
3141
benchmarkRuns,
3242
onChangeDataQuery,
@@ -51,6 +61,7 @@ const ChartSelector = ({
5161
filterSelections,
5262
setFilters,
5363
setByMetric,
64+
role,
5465
} = useBenchmarkFilters(runsWithRoles, "role");
5566

5667
const lastSentDataRef = useRef<SelectedData[]>([]);
@@ -106,9 +117,9 @@ const ChartSelector = ({
106117

107118
if (!isEqual(dataToSend, lastSentDataRef.current)) {
108119
lastSentDataRef.current = dataToSend;
109-
onChangeDataQuery(dataToSend);
120+
onChangeDataQuery({ data: dataToSend, role });
110121
}
111-
}, [matchedRuns, filterSelections.byMetric, onChangeDataQuery]);
122+
}, [matchedRuns, filterSelections.byMetric, role, onChangeDataQuery]);
112123

113124
return (
114125
<div className="flex items-start">

report/src/components/LineChart.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { isEqual } from "lodash";
1616

1717
interface LineChartProps {
1818
series: DataSeries[];
19+
thresholdKey: string | null;
1920
metricKey: string;
2021
title?: string;
2122
description?: string;
@@ -48,6 +49,7 @@ const MAX_TICKS = 10;
4849

4950
const LineChart: React.FC<LineChartProps> = ({
5051
series,
52+
thresholdKey,
5153
metricKey,
5254
title,
5355
description,
@@ -342,14 +344,14 @@ const LineChart: React.FC<LineChartProps> = ({
342344
const maxThreshold = useMemo(() => {
343345
let maxThreshold = 0;
344346
for (const thresholdMap of [thresholds?.warning, thresholds?.error]) {
345-
if (thresholdMap) {
346-
if (thresholdMap[metricKey] > maxThreshold) {
347-
maxThreshold = thresholdMap[metricKey];
347+
if (thresholdMap && thresholdKey) {
348+
if (thresholdMap[thresholdKey] > maxThreshold) {
349+
maxThreshold = thresholdMap[thresholdKey];
348350
}
349351
}
350352
}
351353
return maxThreshold;
352-
}, [thresholds, metricKey]);
354+
}, [thresholds, thresholdKey]);
353355

354356
return (
355357
<BaseChart
@@ -409,9 +411,10 @@ const LineChart: React.FC<LineChartProps> = ({
409411
// Add warning threshold line (yellow)
410412
if (
411413
thresholds.warning &&
412-
thresholds.warning[metricKey] !== undefined
414+
thresholdKey &&
415+
thresholds.warning[thresholdKey] !== undefined
413416
) {
414-
const warningY = y(thresholds.warning[metricKey]);
417+
const warningY = y(thresholds.warning[thresholdKey]);
415418
svg
416419
.append("line")
417420
.attr("class", "threshold-line warning")
@@ -425,8 +428,12 @@ const LineChart: React.FC<LineChartProps> = ({
425428
}
426429

427430
// Add error threshold line (red)
428-
if (thresholds.error && thresholds.error[metricKey] !== undefined) {
429-
const errorY = y(thresholds.error[metricKey]);
431+
if (
432+
thresholds.error &&
433+
thresholdKey &&
434+
thresholds.error[thresholdKey] !== undefined
435+
) {
436+
const errorY = y(thresholds.error[thresholdKey]);
430437
svg
431438
.append("line")
432439
.attr("class", "threshold-line error")

report/src/components/RunList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ const RunList = ({
135135
// Handle threshold displays for specific columns
136136
if (column === "getPayload") {
137137
const warningThreshold =
138-
(run.thresholds?.warning?.["latency/get_payload"] ?? 0) / 1e9;
138+
(run.thresholds?.warning?.["sequencer/latency/get_payload"] ?? 0) / 1e9;
139139
const errorThreshold =
140-
(run.thresholds?.error?.["latency/get_payload"] ?? 0) / 1e9;
140+
(run.thresholds?.error?.["sequencer/latency/get_payload"] ?? 0) / 1e9;
141141

142142
return (
143143
<ThresholdDisplay
@@ -152,9 +152,9 @@ const RunList = ({
152152

153153
if (column === "newPayload") {
154154
const warningThreshold =
155-
(run.thresholds?.warning?.["latency/new_payload"] ?? 0) / 1e9;
155+
(run.thresholds?.warning?.["validator/latency/new_payload"] ?? 0) / 1e9;
156156
const errorThreshold =
157-
(run.thresholds?.error?.["latency/new_payload"] ?? 0) / 1e9;
157+
(run.thresholds?.error?.["validator/latency/new_payload"] ?? 0) / 1e9;
158158

159159
return (
160160
<ThresholdDisplay

report/src/hooks/useBenchmarkFilters.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,25 @@ export function useBenchmarkFilters(
9696
[setRawFilterSelections],
9797
);
9898

99+
// get the role if not grouped by role
100+
const role = useMemo(() => {
101+
if (filterSelections.byMetric === "role") {
102+
return null;
103+
}
104+
105+
return (
106+
(filterSelections.params.role as "sequencer" | "validator") ??
107+
variables.role[0]
108+
);
109+
}, [filterSelections.byMetric, filterSelections.params.role, variables]);
110+
99111
return {
100112
variables,
101113
filterOptions,
102114
matchedRuns,
103115
filterSelections, // Return current selections for UI binding
104116
setFilters, // Return the simplified setter
105117
setByMetric,
118+
role,
106119
};
107120
}

report/src/pages/RunComparison.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useMemo, useState } from "react";
2-
import ChartSelector, { SelectedData } from "../components/ChartSelector";
2+
import ChartSelector, {
3+
DataSelection,
4+
EmptyDataSelection,
5+
} from "../components/ChartSelector";
36
import ChartGrid from "../components/ChartGrid";
47
import { useTestMetadata, useMultipleDataSeries } from "../utils/useDataSeries";
58
import { DataSeries } from "../types";
@@ -13,7 +16,7 @@ function RunComparison() {
1316
throw new Error("Benchmark run ID is required");
1417
}
1518

16-
const [selection, setSelection] = useState<SelectedData[]>([]);
19+
const [selection, setSelection] = useState<DataSelection>(EmptyDataSelection);
1720

1821
const { data: allBenchmarkRuns, isLoading: isLoadingBenchmarkRuns } =
1922
useTestMetadata();
@@ -42,15 +45,15 @@ function RunComparison() {
4245
}, [allBenchmarkRuns, benchmarkRunId]);
4346

4447
const dataQueryKey = useMemo(() => {
45-
return selection.map((query) => {
48+
return selection.data.map((query) => {
4649
// Find the run that matches this outputDir to get the runId
4750
const run = benchmarkRuns.runs.find(
4851
(r) => r.outputDir === query.outputDir,
4952
);
5053
const runId = run?.id || query.outputDir; // Fallback to outputDir if no ID found
5154
return [runId, query.outputDir, query.role] as [string, string, string];
5255
});
53-
}, [selection, benchmarkRuns]);
56+
}, [selection.data, benchmarkRuns]);
5457

5558
const { data: dataPerFile, isLoading } = useMultipleDataSeries(dataQueryKey);
5659
const data = useMemo(() => {
@@ -59,15 +62,15 @@ function RunComparison() {
5962
}
6063

6164
return dataPerFile.map((data, index): DataSeries => {
62-
const { name, color } = selection[index];
65+
const { name, color } = selection.data[index];
6366
return {
6467
name,
6568
data,
6669
color,
67-
thresholds: selection[index].thresholds,
70+
thresholds: selection.data[index].thresholds,
6871
};
6972
});
70-
}, [dataPerFile, selection]);
73+
}, [dataPerFile, selection.data]);
7174

7275
if (!benchmarkRuns || isLoadingBenchmarkRuns) {
7376
return <div>Loading...</div>;
@@ -82,7 +85,11 @@ function RunComparison() {
8285
onChangeDataQuery={setSelection}
8386
benchmarkRuns={benchmarkRuns}
8487
/>
85-
{isLoading ? "Loading..." : <ChartGrid data={data ?? []} />}
88+
{isLoading ? (
89+
"Loading..."
90+
) : (
91+
<ChartGrid role={selection.role} data={data ?? []} />
92+
)}
8693
</div>
8794
</div>
8895
</div>

0 commit comments

Comments
 (0)