Skip to content

Web UI: Add optional base url for locust requests to an external API #3094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion locust/webui/src/components/StateButtons/ResetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button } from '@mui/material';

export default function ResetButton() {
const onResetStatsClick = () => {
fetch('stats/reset');
fetch((window.baseUrl ? `${window.baseUrl}/` : '') + 'stats/reset');
};

return (
Expand Down
2 changes: 1 addition & 1 deletion locust/webui/src/components/StateButtons/StopButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function StopButton() {
}, []);

const onStopButtonClick = () => {
fetch('stop');
fetch((window.baseUrl ? `${window.baseUrl}/` : '') + 'stop');
setIsLoading(true);
};

Expand Down
4 changes: 3 additions & 1 deletion locust/webui/src/components/SwarmForm/SwarmForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ function SwarmForm({
</Accordion>
</>
)}
{!isEmpty(extraOptions) && <CustomParameters extraOptions={extraOptions} />}
{!!extraOptions && !isEmpty(extraOptions) && (
<CustomParameters extraOptions={extraOptions} />
)}
{alert && !errorMessage && (
<Alert severity={alert.level || 'info'}>{alert.message}</Alert>
)}
Expand Down
2 changes: 1 addition & 1 deletion locust/webui/src/constants/swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const swarmTemplateArgs = window.templateArgs
export const htmlReportProps: IReport | false = !!(swarmTemplateArgs as IReportTemplateArgs)
.isReport && {
...(swarmTemplateArgs as IReportTemplateArgs),
charts: swarmTemplateArgs.history?.reduce(
charts: (swarmTemplateArgs.history || []).reduce(
(charts, { currentResponseTimePercentiles, ...history }) =>
updateArraysAtProps(charts, { ...currentResponseTimePercentiles, ...history }),
{} as ICharts,
Expand Down
12 changes: 11 additions & 1 deletion locust/webui/src/redux/api/swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ import {
import { createFormData } from 'utils/object';
import { camelCaseKeys, snakeCaseKeys } from 'utils/string';

const baseQuery = (args: any, api: any, extraOptions: any) =>
fetchBaseQuery(
window.baseUrl
? {
baseUrl: window.baseUrl,
credentials: 'include',
}
: undefined,
)(args, api, extraOptions);

export const api = createApi({
baseQuery: fetchBaseQuery(),
baseQuery: baseQuery,
endpoints: builder => ({
getStats: builder.query<IStatsResponse, void>({
query: () => 'stats/requests',
Expand Down
1 change: 1 addition & 0 deletions locust/webui/src/types/window.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export interface IWindow {
templateArgs: IReportTemplateArgs | ISwarmState;
authArgs: IAuthArgs;
theme?: PaletteMode;
baseUrl?: string;
}