Skip to content
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

feat(weave): adding charts to the traces page #2745

Merged
merged 59 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b3972d0
commenting
mbarrramsey Oct 21, 2024
760b5f9
commenting
mbarrramsey Oct 21, 2024
c57660e
.:
mbarrramsey Oct 22, 2024
b9537bd
.:
mbarrramsey Oct 22, 2024
cb47ee5
getting cost data
mbarrramsey Oct 22, 2024
27a297d
adding recharts lib
mbarrramsey Oct 23, 2024
361e1c2
adding custom colors to chart
mbarrramsey Oct 23, 2024
af30efb
chart working
mbarrramsey Oct 23, 2024
d339518
adding latency with recharts
mbarrramsey Oct 23, 2024
c8940d2
new packages
mbarrramsey Oct 23, 2024
3098383
Merge branch 'master' of github.com:wandb/weave into mbarrramsey/trac…
mbarrramsey Oct 23, 2024
3aae50c
added charts
mbarrramsey Oct 24, 2024
0056b52
adding visx charts
mbarrramsey Oct 24, 2024
3e55c47
fixing tooltip styling
mbarrramsey Oct 24, 2024
e0ea0b6
.
mbarrramsey Oct 24, 2024
d0885dd
switching back to plotly
mbarrramsey Oct 24, 2024
ae16f97
adding drawer
mbarrramsey Oct 24, 2024
9485af6
adding padding
mbarrramsey Oct 24, 2024
6c54311
.
mbarrramsey Oct 24, 2024
7940de2
fast
mbarrramsey Oct 25, 2024
abc65bc
cleanup
mbarrramsey Oct 25, 2024
5efc2cd
nit
mbarrramsey Oct 25, 2024
c62142d
linting
mbarrramsey Oct 25, 2024
6f31e96
untouched files, reverting
mbarrramsey Oct 25, 2024
7d0d9e1
lint
mbarrramsey Oct 25, 2024
f3ecefa
removing visx
mbarrramsey Oct 25, 2024
1e97527
removing unused packages
mbarrramsey Oct 25, 2024
9f6b521
removing react-plotly
mbarrramsey Oct 25, 2024
8e7fa77
adding d3 types
mbarrramsey Oct 25, 2024
9a37d11
.
mbarrramsey Oct 25, 2024
17743b7
code cleanup
mbarrramsey Oct 25, 2024
c7e6382
.
mbarrramsey Oct 25, 2024
9f8d248
Merge branch 'master' of github.com:wandb/weave into mbarrramsey/trac…
mbarrramsey Oct 25, 2024
2c1d20c
lint
mbarrramsey Oct 25, 2024
5b3f791
small pixel change to align insights
mbarrramsey Oct 25, 2024
f68eafb
code cleanup
mbarrramsey Oct 28, 2024
eb744ec
code cleanup
mbarrramsey Oct 28, 2024
966bd46
cleanup
mbarrramsey Oct 28, 2024
d5e173d
linting
mbarrramsey Oct 28, 2024
69d64a3
lint
mbarrramsey Oct 28, 2024
1400ab4
fixing padding on insights
mbarrramsey Oct 28, 2024
7fc4521
downgrading back to current plotly version
mbarrramsey Oct 28, 2024
ec462a7
.
mbarrramsey Oct 28, 2024
fed1e8b
d3
mbarrramsey Oct 28, 2024
9595855
fixing mismatched padding
mbarrramsey Oct 29, 2024
1898e27
.
mbarrramsey Oct 29, 2024
bb3c66c
linting
mbarrramsey Oct 29, 2024
25c44dd
updating binning logic
mbarrramsey Oct 29, 2024
69a9870
combining useCallsForQuery
mbarrramsey Oct 29, 2024
61526f5
lint
mbarrramsey Oct 29, 2024
47680f2
adding metrics toggle
mbarrramsey Oct 29, 2024
f03c547
adding loading state
mbarrramsey Oct 29, 2024
d3143bf
adding empty state
mbarrramsey Oct 29, 2024
0f15609
linting
mbarrramsey Oct 29, 2024
548146a
reverting old change
mbarrramsey Oct 29, 2024
e9f83ca
lint
mbarrramsey Oct 29, 2024
355a757
switching to small toggle
mbarrramsey Oct 29, 2024
2c8fb69
updating height to 250px and renaming constants in screaming case
mbarrramsey Oct 29, 2024
423c4f0
.
mbarrramsey Oct 29, 2024
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
1 change: 1 addition & 0 deletions weave-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"@types/color": "^3.0.0",
"@types/cytoscape": "^3.2.0",
"@types/cytoscape-dagre": "^2.2.2",
"@types/d3-array": "^3.2.1",
"@types/diff": "^5.0.3",
"@types/downloadjs": "^1.4.2",
"@types/is-buffer": "^2.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import {GridFilterModel, GridSortModel} from '@mui/x-data-grid-pro';
import React, {useMemo} from 'react';

import {MOON_400} from '../../../../../../common/css/color.styles';
import {IconInfo} from '../../../../../Icon';
import {WaveLoader} from '../../../../../Loaders/WaveLoader';
import {Tailwind} from '../../../../../Tailwind';
import {WFHighLevelCallFilter} from './callsTableFilter';
import {useCallsForQuery} from './callsTableQuery';
import {
ErrorPlotlyChart,
LatencyPlotlyChart,
RequestsPlotlyChart,
} from './Charts';

type CallsChartsProps = {
entity: string;
project: string;
filterModelProp: GridFilterModel;
filter: WFHighLevelCallFilter;
};

const Chart = ({
isLoading,
chartData,
title,
}: {
isLoading: boolean;
chartData: any;
title: string;
}) => {
const CHART_CONTAINER_STYLES =
'flex-1 rounded-lg border border-moon-250 bg-white p-10';
const CHART_TITLE_STYLES = 'ml-12 mt-8 text-base font-semibold text-moon-750';
const CHART_HEIGHT = 250;
const LOADING_CONTAINER_STYLES = `flex h-[${CHART_HEIGHT}px] items-center justify-center`;

let chart = null;
if (isLoading) {
chart = (
<div className={LOADING_CONTAINER_STYLES}>
<WaveLoader size="small" />
</div>
);
} else if (chartData.length > 0) {
switch (title) {
case 'Latency':
chart = (
<LatencyPlotlyChart chartData={chartData} height={CHART_HEIGHT} />
);
break;
case 'Errors':
chart = (
<ErrorPlotlyChart chartData={chartData} height={CHART_HEIGHT} />
);
break;
case 'Requests':
chart = (
<RequestsPlotlyChart chartData={chartData} height={CHART_HEIGHT} />
);
break;
}
} else {
chart = (
<div className={LOADING_CONTAINER_STYLES}>
<div className="flex flex-col items-center justify-center">
<IconInfo color={MOON_400} />
<div className="text-moon-500">
No data available for the selected time frame
</div>
</div>
</div>
);
}
return (
<div className={CHART_CONTAINER_STYLES}>
<div className={CHART_TITLE_STYLES}>{title}</div>
{chart}
</div>
);
};

export const CallsCharts = ({
entity,
project,
filter,
filterModelProp,
}: CallsChartsProps) => {
const columns = useMemo(
() => ['started_at', 'ended_at', 'exception', 'id'],
[]
);
const columnSet = useMemo(() => new Set(columns), [columns]);
const sortCalls: GridSortModel = useMemo(
() => [{field: 'started_at', sort: 'desc'}],
[]
);
const page = useMemo(
() => ({
pageSize: 1000,
page: 0,
}),
[]
);

const calls = useCallsForQuery(
entity,
project,
filter,
filterModelProp,
page,
sortCalls,
columnSet,
columns
);

const chartData = useMemo(() => {
if (calls.loading || !calls.result || calls.result.length === 0) {
return {latency: [], errors: [], requests: []};
}

const data: {
latency: Array<{started_at: string; latency: number}>;
errors: Array<{started_at: string; isError: boolean}>;
requests: Array<{started_at: string}>;
} = {
latency: [],
errors: [],
requests: [],
};

calls.result.forEach(call => {
const started_at = call.traceCall?.started_at;
if (!started_at) {
return;
}
const ended_at = call.traceCall?.ended_at;

const isError =
call.traceCall?.exception !== null &&
call.traceCall?.exception !== undefined &&
call.traceCall?.exception !== '';

data.requests.push({started_at});

if (isError) {
data.errors.push({started_at, isError});
} else {
data.errors.push({started_at, isError: false});
}

if (ended_at !== undefined) {
const startTime = new Date(started_at).getTime();
const endTime = new Date(ended_at).getTime();
const latency = endTime - startTime;
data.latency.push({started_at, latency});
}
});
return data;
}, [calls.result, calls.loading]);

const charts = (
<div className="m-10 flex flex-row gap-10">
<Chart
isLoading={calls.loading}
chartData={chartData.latency}
title="Latency"
/>
<Chart
isLoading={calls.loading}
chartData={chartData.errors}
title="Errors"
/>
<Chart
isLoading={calls.loading}
chartData={chartData.requests}
title="Requests"
/>
</div>
);

return (
<Tailwind>
{/* setting the width to the width of the screen minus the sidebar width because of overflow: 'hidden' properties in SimplePageLayout causing issues */}
<div className="md:w-[calc(100vw-56px)]">
<div className="mb-20 mt-10">{charts}</div>
</div>
</Tailwind>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
useGridApiRef,
} from '@mui/x-data-grid-pro';
import {MOON_200, TEAL_300} from '@wandb/weave/common/css/color.styles';
import {Switch} from '@wandb/weave/components';
import {Checkbox} from '@wandb/weave/components/Checkbox/Checkbox';
import {Icon} from '@wandb/weave/components/Icon';
import React, {
Expand Down Expand Up @@ -69,6 +70,7 @@ import {traceCallToUICallSchema} from '../wfReactInterface/tsDataModelHooks';
import {EXPANDED_REF_REF_KEY} from '../wfReactInterface/tsDataModelHooksCallRefExpansion';
import {objectVersionNiceString} from '../wfReactInterface/utilities';
import {CallSchema} from '../wfReactInterface/wfDataModelHooksInterface';
import {CallsCharts} from './CallsCharts';
import {CallsCustomColumnMenu} from './CallsCustomColumnMenu';
import {
BulkDeleteButton,
Expand Down Expand Up @@ -168,6 +170,7 @@ export const CallsTable: FC<{
allowedColumnPatterns,
}) => {
const {loading: loadingUserInfo, userInfo} = useViewerInfo();
const [isMetricsChecked, setMetricsChecked] = useState(false);

const isReadonly =
loadingUserInfo || !userInfo?.username || !userInfo?.teams.includes(entity);
Expand Down Expand Up @@ -245,8 +248,8 @@ export const CallsTable: FC<{
project,
effectiveFilter,
filterModelResolved,
sortModelResolved,
paginationModelResolved,
sortModelResolved,
expandedRefCols
);

Expand Down Expand Up @@ -742,6 +745,15 @@ export const CallsTable: FC<{
clearSelectedCalls={clearSelectedCalls}
/>
)}
<div className="flex items-center gap-6">
<Switch.Root
size="small"
checked={isMetricsChecked}
onCheckedChange={setMetricsChecked}>
<Switch.Thumb size="small" checked={isMetricsChecked} />
</Switch.Root>
Metrics
</div>
{selectedInputObjectVersion && (
<Chip
label={`Input: ${objectVersionNiceString(
Expand Down Expand Up @@ -849,6 +861,14 @@ export const CallsTable: FC<{
)}
</TailwindContents>
}>
{isMetricsChecked && (
<CallsCharts
entity={entity}
project={project}
filter={filter}
filterModelProp={filterModelResolved}
/>
)}
<StyledDataGrid
// Start Column Menu
// ColumnMenu is needed to support pinning and column visibility
Expand Down
Loading
Loading