Skip to content

Commit

Permalink
Endpoint dashboard, fix line chart colors, add search custom columns,…
Browse files Browse the repository at this point in the history
… fix table column number format
  • Loading branch information
MikeShi42 committed Jan 5, 2024
1 parent 51c7207 commit c46f4d1
Show file tree
Hide file tree
Showing 9 changed files with 488 additions and 21 deletions.
23 changes: 23 additions & 0 deletions packages/app/src/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export function seriesColumns({
})}`,
sortOrder:
'sortOrder' in series[0] ? series[0].sortOrder : undefined,
numberFormat:
'numberFormat' in series[0] ? series[0].numberFormat : undefined,
},
]
: series.map((s, i) => {
Expand All @@ -139,6 +141,7 @@ export function seriesColumns({
showWhere,
}),
sortOrder: 'sortOrder' in s ? s.sortOrder : undefined,
numberFormat: 'numberFormat' in s ? s.numberFormat : undefined,
};
});

Expand Down Expand Up @@ -1186,6 +1189,26 @@ export function timeBucketByGranularity(
return buckets;
}

export const INTEGER_NUMBER_FORMAT: NumberFormat = {
factor: 1,
output: 'number',
mantissa: 0,
thousandSeparated: true,
};

export const MS_NUMBER_FORMAT: NumberFormat = {
factor: 1,
output: 'number',
mantissa: 2,
thousandSeparated: true,
unit: 'ms',
};

export const ERROR_RATE_PERCENTAGE_NUMBER_FORMAT: NumberFormat = {
output: 'percent',
mantissa: 0,
};

export const K8S_CPU_PERCENTAGE_NUMBER_FORMAT: NumberFormat = {
output: 'percent',
mantissa: 0,
Expand Down
107 changes: 107 additions & 0 deletions packages/app/src/EndpointLatencyTile.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import * as React from 'react';
import { Box, Button, Card, Flex } from '@mantine/core';

import {
convertDateRangeToGranularityString,
MS_NUMBER_FORMAT,
} from './ChartUtils';
import HDXHistogramChart from './HDXHistogramChart';
import HDXMultiSeriesLineChart from './HDXMultiSeriesTimeChart';
import { Histogram } from './SVGIcons';

export default function EndpointLatencyTile({
height = 300,
dateRange,
scopeWhereQuery = (where: string) => where,
}: {
height?: number;
dateRange: [Date, Date];
scopeWhereQuery?: (where: string) => string;
}) {
const [chartType, setChartType] = React.useState<'line' | 'histogram'>(
'line',
);

return (
<Card p="md">
<Card.Section p="md" py="xs" withBorder>
<Flex justify="space-between">
<span>Request Latency</span>
<Box>
<Button.Group>
<Button
variant="subtle"
color={chartType === 'line' ? 'green' : 'dark.2'}
size="xs"
title="Line Chart"
onClick={() => setChartType('line')}
>
<i className="bi bi-graph-up" />
</Button>

<Button
variant="subtle"
color={chartType === 'histogram' ? 'green' : 'dark.2'}
size="xs"
title="Histogram"
onClick={() => setChartType('histogram')}
>
<Histogram width={12} color="currentColor" />
</Button>
</Button.Group>
</Box>
</Flex>
</Card.Section>
<Card.Section p="md" py="sm" h={height}>
{chartType === 'line' ? (
<HDXMultiSeriesLineChart
config={{
dateRange,
granularity: convertDateRangeToGranularityString(dateRange, 60),
series: [
{
displayName: '95th Percentile',
table: 'logs',
type: 'time',
aggFn: 'p95',
field: 'duration',
where: scopeWhereQuery('span.kind:"server"'),
groupBy: [],
numberFormat: MS_NUMBER_FORMAT,
},
{
displayName: 'Median',
table: 'logs',
type: 'time',
aggFn: 'p50',
field: 'duration',
where: scopeWhereQuery('span.kind:"server"'),
groupBy: [],
},
{
displayName: 'Average',
table: 'logs',
type: 'time',
aggFn: 'avg',
field: 'duration',
where: scopeWhereQuery('span.kind:"server"'),
groupBy: [],
},
],
seriesReturnType: 'column',
}}
/>
) : (
<HDXHistogramChart
config={{
table: 'logs',
field: 'duration',
where: scopeWhereQuery('span.kind:"server"'),
dateRange,
}}
/>
)}
</Card.Section>
</Card>
);
}
103 changes: 103 additions & 0 deletions packages/app/src/HDXListBarChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { memo } from 'react';
import { Box, Flex, Text } from '@mantine/core';

import api from './api';
import { Granularity } from './ChartUtils';
import type { ChartSeries, NumberFormat } from './types';
import { semanticKeyedColor } from './utils';

function ListItem({
title,
value,
color,
percent,
}: {
title: string;
value: string;
color: string;
percent: number;
}) {
return (
<Box>
<Flex justify="space-between">
<Text size="sm">{title}</Text>
<Text size="sm">{value}</Text>
</Flex>
<Box pt="xs">
<Box
style={{
width: `${percent}%`,
height: 8,
backgroundColor: color,
borderRadius: 4,
}}
/>
</Box>
</Box>
);
}

const HDXListBarChart = memo(
({
config: { series, seriesReturnType = 'column', dateRange },
}: {
config: {
series: [ChartSeries];
granularity: Granularity;
dateRange: [Date, Date];
seriesReturnType?: 'ratio' | 'column';
numberFormat?: NumberFormat;
groupColumnName?: string;
};
onSettled?: () => void;
}) => {
const { data, isError, isLoading } = api.useMultiSeriesChart({
series,
endDate: dateRange[1] ?? new Date(),
startDate: dateRange[0] ?? new Date(),
seriesReturnType,
});

const rows: undefined | any[] = data?.data;

const values = (rows ?? []).map((row: any) => row['series_0.data']);
const maxValue = Math.max(...values);
const totalValue = values.reduce((a, b) => a + b, 0);

return isLoading ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
Loading Chart Data...
</div>
) : isError ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
Error loading chart, please try again or contact support.
</div>
) : data?.data?.length === 0 ? (
<div className="d-flex h-100 w-100 align-items-center justify-content-center text-muted">
No data found within time range.
</div>
) : (
<Box className="overflow-auto" h="100%">
{rows?.map((row: any) => {
const value = row['series_0.data'];
const percentOfMax = (value / maxValue) * 100;
const percentOfTotal = (value / totalValue) * 100;
const group = `${row.group}`;

return (
<Box mb="sm" key={group}>
<ListItem
title={group}
value={`${percentOfTotal.toFixed(2)}%`}
color={semanticKeyedColor(group)}
percent={percentOfMax}
/>
</Box>
);
})}
</Box>
);
},
);

export default HDXListBarChart;
16 changes: 3 additions & 13 deletions packages/app/src/HDXMultiSeriesTableChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { formatNumber } from './utils';
const Table = ({
data,
groupColumnName,
numberFormat,
columns,
getRowSearchLink,
onSortClick,
Expand All @@ -35,9 +34,9 @@ const Table = ({
dataKey: string;
displayName: string;
sortOrder?: 'asc' | 'desc';
numberFormat?: NumberFormat;
}[];
groupColumnName: string;
numberFormat?: NumberFormat;
getRowSearchLink?: (row: any) => string;
onSortClick?: (columnNumber: number) => void;
}) => {
Expand All @@ -52,7 +51,7 @@ const Table = ({
header: groupColumnName,
size: tableWidth != null ? tableWidth / numColumns : 200,
},
...columns.map(({ dataKey, displayName }, i) => ({
...columns.map(({ dataKey, displayName, numberFormat }, i) => ({
accessorKey: dataKey,
header: displayName,
accessorFn: (row: any) => row[dataKey],
Expand Down Expand Up @@ -272,13 +271,7 @@ const Table = ({

const HDXMultiSeriesTableChart = memo(
({
config: {
series,
seriesReturnType = 'column',
dateRange,
numberFormat,
groupColumnName,
},
config: { series, seriesReturnType = 'column', dateRange, groupColumnName },
onSettled,
onSortClick,
}: {
Expand All @@ -287,8 +280,6 @@ const HDXMultiSeriesTableChart = memo(
granularity: Granularity;
dateRange: [Date, Date];
seriesReturnType: 'ratio' | 'column';
sortOrder: 'asc' | 'desc';
numberFormat?: NumberFormat;
groupColumnName?: string;
};
onSettled?: () => void;
Expand Down Expand Up @@ -340,7 +331,6 @@ const HDXMultiSeriesTableChart = memo(
: 'Group')
}
columns={seriesMeta}
numberFormat={numberFormat}
getRowSearchLink={getRowSearchLink}
onSortClick={onSortClick}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/HDXMultiSeriesTimeChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const MemoChart = memo(function MemoChart({
type="monotone"
dataKey={key}
name={lineNames[i] ?? key}
fill={semanticKeyedColor(key)}
fill={semanticKeyedColor(lineNames[i] ?? key)}
stackId="1"
/>
) : (
Expand All @@ -76,7 +76,7 @@ const MemoChart = memo(function MemoChart({
type="monotone"
dataKey={key}
name={lineNames[i] ?? key}
stroke={semanticKeyedColor(key)}
stroke={semanticKeyedColor(lineNames[i] ?? key)}
dot={false}
/>
),
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/LogTableWithSidePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function LogTableWithSidePanel({
config: {
where: string;
dateRange: [Date, Date];
columns?: string[];
};
isUTC: boolean;
isLive: boolean;
Expand Down Expand Up @@ -84,7 +85,7 @@ export function LogTableWithSidePanel({
const voidFn = useCallback(() => {}, []);

const { displayedColumns, setDisplayedColumns, toggleColumn } =
useDisplayedColumns();
useDisplayedColumns(config.columns);

return (
<>
Expand Down
Loading

0 comments on commit c46f4d1

Please sign in to comment.