Skip to content

Commit

Permalink
Fix html report stats table
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbaldwin44 committed Jul 24, 2024
1 parent b330e76 commit 8141e1a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion locust/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

try:
# import locust_plugins if it is installed, to allow it to register custom arguments etc
import locust_cloud # pyright: ignore[reportMissingImports]
import locust_plugins # pyright: ignore[reportMissingImports]
except ModuleNotFoundError:
pass

Expand Down
3 changes: 3 additions & 0 deletions locust/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,10 @@ def to_dict(self, escape_string_values=False):
"max_response_time": proper_round(self.max_response_time),
"current_rps": self.current_rps,
"current_fail_per_sec": self.current_fail_per_sec,
"avg_response_time": self.avg_response_time,
"median_response_time": self.median_response_time,
"total_rps": self.total_rps,
"total_fail_per_sec": self.total_fail_per_sec,
**response_time_percentiles,
"avg_content_length": self.avg_content_length,
}
Expand Down
10 changes: 8 additions & 2 deletions locust/webui/src/components/StatsTable/StatsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ViewColumnSelector from 'components/ViewColumnSelector/ViewColumnSelector
import { swarmTemplateArgs } from 'constants/swarm';
import useSelectViewColumns from 'hooks/useSelectViewColumns';
import { IRootState } from 'redux/store';
import { ITableStructure } from 'types/table.types';
import { ISwarmStat } from 'types/ui.types';

const percentilesToStatisticsRows = swarmTemplateArgs.percentilesToStatistics
Expand All @@ -14,7 +15,7 @@ const percentilesToStatisticsRows = swarmTemplateArgs.percentilesToStatistics
}))
: [];

const tableStructure = [
export const baseTableStructure = [
{ key: 'method', title: 'Type' },
{ key: 'name', title: 'Name' },
{ key: 'numRequests', title: '# Requests' },
Expand All @@ -29,7 +30,12 @@ const tableStructure = [
{ key: 'currentFailPerSec', title: 'Current Failures/s', round: 2 },
];

export function StatsTable({ stats }: { stats: ISwarmStat[] }) {
interface IStatsTable {
stats: ISwarmStat[];
tableStructure: ITableStructure[];
}

export function StatsTable({ stats, tableStructure = baseTableStructure }: IStatsTable) {
const { selectedColumns, addColumn, removeColumn, filteredStructure } =
useSelectViewColumns(tableStructure);

Expand Down
15 changes: 14 additions & 1 deletion locust/webui/src/pages/HtmlReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ import { formatLocaleString } from 'utils/date';

const theme = createTheme(window.theme || INITIAL_THEME);

const statsReportTableStructure = [
{ key: 'method', title: 'Type' },
{ key: 'name', title: 'Name' },
{ key: 'numRequests', title: '# Requests' },
{ key: 'numFailures', title: '# Fails' },
{ key: 'avgResponseTime', title: 'Average (ms)', round: 2 },
{ key: 'minResponseTime', title: 'Min (ms)' },
{ key: 'maxResponseTime', title: 'Max (ms)' },
{ key: 'avgContentLength', title: 'Average size (bytes)', round: 2 },
{ key: 'totalRps', title: 'RPS', round: 2 },
{ key: 'totalFailPerSec', title: 'Failures/s', round: 2 },
];

export default function HtmlReport({
locustfile,
showDownloadLink,
Expand Down Expand Up @@ -72,7 +85,7 @@ export default function HtmlReport({
<Typography component='h2' mb={1} noWrap variant='h4'>
Request Statistics
</Typography>
<StatsTable stats={requestsStatistics} />
<StatsTable stats={requestsStatistics} tableStructure={statsReportTableStructure} />
</Box>
{!!responseTimeStatistics.length && (
<Box>
Expand Down

0 comments on commit 8141e1a

Please sign in to comment.