Skip to content

Commit

Permalink
fix: hot-patching bugs from last release
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Jun 11, 2024
1 parent 3fbe33a commit 7d4494f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions core/components/StatsManager/svRuntime/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class SvRuntimeStatsManager {
}

//Check if first collection, boundaries changed
if (!this.lastPerfData || !this.lastPerfSaved || !this.lastPerfBoundaries) {
if (!this.lastPerfBoundaries) {
console.verbose.debug('First perf collection.');
this.lastPerfBoundaries = perfBoundaries;
this.resetPerfState();
Expand Down Expand Up @@ -317,8 +317,8 @@ export default class SvRuntimeStatsManager {
* Returns the data for charting the performance of a specific thread
*/
public getChartData(threadName: string): PerfChartApiResp {
if (!isValidPerfThreadName(threadName)) return { error: 'invalid_thread_name' };
if (!this.statsLog.length || !this.lastPerfBoundaries?.length) return { error: 'data_unavailable' };
if (!isValidPerfThreadName(threadName)) return { fail_reason: 'invalid_thread_name' };
if (!this.statsLog.length || !this.lastPerfBoundaries?.length) return { fail_reason: 'data_unavailable' };

//Processing data
return {
Expand Down
10 changes: 5 additions & 5 deletions core/webroutes/perfChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const console = consoleFactory(modulename);

//Types
export type PerfChartApiErrorResp = {
error: string;
fail_reason: string;
};
export type PerfChartApiSuccessResp = {
boundaries: SvRtPerfBoundariesType;
Expand All @@ -31,11 +31,11 @@ export default async function perfChart(ctx: AuthedCtx) {
//Validating input
const schemaRes = paramsSchema.safeParse(ctx.request.params);
if (!schemaRes.success) {
return sendTypedResp({ error: 'bad_request' });
return sendTypedResp({ fail_reason: 'bad_request' });
}

const chartData = ctx.txAdmin.statsManager.svRuntime.getChartData(schemaRes.data.thread);
if ('error' in chartData) {
if ('fail_reason' in chartData) {
return sendTypedResp(chartData);
}
const { threadPerfLog, boundaries } = chartData;
Expand All @@ -47,11 +47,11 @@ export default async function perfChart(ctx: AuthedCtx) {
const oldestDataLogged = filteredThreadPerfLog.find((log) => log.type === 'data');
if (!oldestDataLogged) {
return sendTypedResp({
error: 'not_enough_data',
fail_reason: 'not_enough_data',
});
} else if (oldestDataLogged.ts > Date.now() - requiredMinDataAge) {
return sendTypedResp({
error: 'not_enough_data',
fail_reason: 'not_enough_data',
});
}
return sendTypedResp({
Expand Down
11 changes: 8 additions & 3 deletions docs/dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@
- [x] redact discord api webhook urls from reports
- [x] MUST `//FIXME: update_txdiagnostics`
- [x] add fxserver version to txDiagnostics
- [ ] commit stashed changes
- [ ] merge #952 manually
- [x] commit stashed changes
- [x] merge #952 manually




==================================================
Expand Down Expand Up @@ -130,14 +132,17 @@ for log in statsLog:
## Next up... ish
- Dashboard stuff:
- [ ] add testing for getServerStatsData
- [ ] StatsManager.svRuntime: write log optimizer and remove the webroute 30h filter
- StatsManager.svRuntime:
- [ ] write log optimizer and remove the webroute 30h filter
- [ ] fix: it's not wiping the log when detecting new boundaries
- [ ] fix getMinTickIntervalMarker behavior when 0.2
- [ ] buttons to show memory usage, maybe hide player count
- [ ] calculate initial zoom of 30h, maybe some linear interpolation
- [ ] warning for top servers
- thread perf chart:
- [ ] color should change correctly at the min interval marker point
- full perf chart:
- [ ] increase `h-[26rem]` back to 28 after removing the new chart warning
- [ ] use semi-transparent arrows on the sides to indicate there is more to pan to
- [ ] don't clear canvas on render, use d3 joins
- [ ] swr disable revalidateOnFocus and use interval
Expand Down
2 changes: 1 addition & 1 deletion panel/src/components/BanForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default forwardRef(function BanForm({ banTemplates, disabled, onNavigateA
reasonRef.current?.focus();
}
};
}, []);
}, [reasonRef, customMultiplierRef, currentDuration, customUnits]);

const handleTemplateSelectChange = (value: string) => {
if (value === ADD_NEW_SELECT_OPTION) {
Expand Down
25 changes: 15 additions & 10 deletions panel/src/pages/Dashboard/FullPerfCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { ReactNode, memo, useEffect, useMemo, useRef, useState } from 're
import DebouncedResizeContainer from '@/components/DebouncedResizeContainer';
import drawFullPerfChart from './drawFullPerfChart';
import { BackendApiError, useBackendApi } from '@/hooks/fetch';
import type { PerfChartApiSuccessResp } from "@shared/otherTypes";
import type { PerfChartApiResp, PerfChartApiSuccessResp } from "@shared/otherTypes";
import useSWR from 'swr';
import { PerfSnapType, formatTickBoundary, getBucketTicketsEstimatedTime, getServerStatsData, getTimeWeightedHistogram, processPerfLog } from './chartingUtils';
import { dashServerStatsAtom, useThrottledSetCursor } from './dashboardHooks';
Expand Down Expand Up @@ -143,7 +143,7 @@ const FullPerfChart = memo(({ threadName, apiData, width, height, isDarkMode }:
</>);
});

function ChartErrorMessage({ error }: { error: Error | BackendApiError }) {
function ChartErrorMessage({ error }: { error: Error | string }) {
const errorMessageMaps: Record<string, ReactNode> = {
bad_request: 'Chart data loading failed: bad request.',
invalid_thread_name: 'Chart data loading failed: invalid thread name.',
Expand All @@ -156,10 +156,10 @@ function ChartErrorMessage({ error }: { error: Error | BackendApiError }) {
</p>),
};

if (error instanceof BackendApiError) {
if (typeof error === 'string') {
return (
<div className="absolute inset-0 flex flex-col items-center justify-center text-2xl text-muted-foreground">
{errorMessageMaps[error.message] ?? 'Unknown BackendApiError'}
{errorMessageMaps[error] ?? 'Unknown BackendApiError'}
</div>
);
} else {
Expand All @@ -175,19 +175,24 @@ function ChartErrorMessage({ error }: { error: Error | BackendApiError }) {
export default function FullPerfCard() {
const [chartSize, setChartSize] = useState({ width: 0, height: 0 });
const [selectedThread, setSelectedThread] = useState('svMain');
const [apiFailReason, setApiFailReason] = useState('');
const isDarkMode = useIsDarkMode();

const chartApi = useBackendApi<PerfChartApiSuccessResp>({
const chartApi = useBackendApi<PerfChartApiResp>({
method: 'GET',
path: `/perfChartData/:thread/`,
throwGenericErrors: true,
});

const swrChartApiResp = useSWR('/perfChartData/:thread', async () => {
setApiFailReason('');
const data = await chartApi({
pathParams: { thread: selectedThread },
});
if (!data) throw new Error('empty_response');
if ('fail_reason' in data) {
setApiFailReason(data.fail_reason);
return null;
}
return data;
}, {});

Expand All @@ -201,7 +206,7 @@ export default function FullPerfCard() {
if (swrChartApiResp.data) {
contentNode = <FullPerfChart
threadName={selectedThread}
apiData={swrChartApiResp.data}
apiData={swrChartApiResp.data as PerfChartApiSuccessResp}
width={chartSize.width}
height={chartSize.height}
isDarkMode={isDarkMode}
Expand All @@ -210,12 +215,12 @@ export default function FullPerfCard() {
contentNode = <div className="absolute inset-0 flex flex-col items-center justify-center">
<Loader2Icon className="animate-spin size-16 text-muted-foreground" />
</div>;
} else if (swrChartApiResp.error) {
contentNode = <ChartErrorMessage error={swrChartApiResp.error} />;
} else if (apiFailReason || swrChartApiResp.error) {
contentNode = <ChartErrorMessage error={apiFailReason || swrChartApiResp.error} />;
}

return (
<div className="w-full h-[28rem] py-2 md:rounded-lg border bg-card shadow-sm flex flex-col fill-primary">
<div className="w-full h-[26rem] py-2 md:rounded-xl border bg-card shadow-sm flex flex-col fill-primary">
<div className="px-4 flex flex-row items-center justify-between space-y-0 pb-2 text-muted-foreground">
<h3 className="tracking-tight text-sm font-medium line-clamp-1">
Server performance
Expand Down
2 changes: 1 addition & 1 deletion panel/src/pages/Dashboard/PlayerDropCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export default function PlayerDropCard() {
}

return (
<div className="col-span-3 sm:col-span-2 2xl:col-span-3 py-2 md:rounded-lg border bg-card shadow-sm flex flex-col min-w-64 h-[20rem] max-h-[20rem]">
<div className="col-span-3 sm:col-span-2 2xl:col-span-3 py-2 md:rounded-xl border bg-card shadow-sm flex flex-col min-w-64 h-[20rem] max-h-[20rem]">
<div className="px-4 flex flex-row items-center justify-between space-y-0 pb-2 text-muted-foreground">
<h3 className="tracking-tight text-sm font-medium line-clamp-1">Player drop reasons (last 6h)</h3>
<div className='hidden sm:block'><PieChartIcon /></div>
Expand Down
2 changes: 1 addition & 1 deletion panel/src/pages/Dashboard/ServerStatsCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default function ServerStatsCard() {
}

return (
<div className="col-span-3 sm:col-span-1 2xl:col-span-2 min-w-52 py-2 px-4 flex flex-col md:rounded-lg border shadow-sm bg-card">
<div className="col-span-3 sm:col-span-1 2xl:col-span-2 min-w-52 py-2 px-4 flex flex-col md:rounded-xl border shadow-sm bg-card">
<div className="flex flex-row items-center justify-between space-y-0 pb-2 text-muted-foreground">
<h3 className="tracking-tight text-sm font-medium line-clamp-1">
Server stats {titleNode}
Expand Down
2 changes: 1 addition & 1 deletion panel/src/pages/Dashboard/ThreadPerfCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default function ThreadPerfCard() {


return (
<div className="py-2 md:rounded-lg border bg-card shadow-sm flex flex-col col-span-3 fill-primary h-[20rem] max-h-[20rem]">
<div className="py-2 md:rounded-xl border bg-card shadow-sm flex flex-col col-span-3 fill-primary h-[20rem] max-h-[20rem]">
<div className="px-4 flex flex-row items-center justify-between space-y-0 pb-2 text-muted-foreground">
<h3 className="tracking-tight text-sm font-medium line-clamp-1">
{cursorThreadLabel ?? selectedThread} performance {titleTimeIndicator}
Expand Down

0 comments on commit 7d4494f

Please sign in to comment.