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

Service Dashboard Endpoint Sidepanel #193

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
106 changes: 106 additions & 0 deletions packages/api/src/clickhouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,112 @@ export const getMultiSeriesChartLegacyFormat = async ({
};
};

// This query needs to be generalized and replaced once use-case matures
export const getSpanPerformanceChart = async ({
parentSpanWhere,
childrenSpanWhere,
teamId,
tableVersion,
maxNumGroups,
propertyTypeMappingsModel,
startTime,
endTime,
}: {
parentSpanWhere: string;
childrenSpanWhere: string;
tableVersion: number | undefined;
teamId: string;
maxNumGroups: number;
endTime: number; // unix in ms,
startTime: number;
propertyTypeMappingsModel: LogsPropertyTypeMappingsModel;
}) => {
const tableName = getLogStreamTableName(tableVersion, teamId);

const parentSpanWhereCondition = await buildSearchQueryWhereCondition({
endTime,
propertyTypeMappingsModel,
query: parentSpanWhere,
startTime,
});

const childrenSpanWhereCondition = await buildSearchQueryWhereCondition({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can do this concurrently ?

endTime,
propertyTypeMappingsModel,
query: childrenSpanWhere,
startTime,
});

// This needs to return in a format that matches multi-series charts
const query = SqlString.format(
`WITH trace_ids AS (
SELECT
distinct trace_id
FROM ??
WHERE (?)
)
SELECT
[span_name] as "group",
sum(_duration) as "series_0.data",
count(*) as "series_1.data",
avg(_duration) as "series_2.data",
min(_duration) as "series_3.data",
max(_duration) as "series_4.data",
count(distinct trace_id) as "series_5.data",
"series_1.data" / "series_5.data" as "series_6.data",
'0' as "ts_bucket"
FROM ??
WHERE
(?)
AND trace_id IN (SELECT trace_id FROM trace_ids)
GROUP BY span_name
ORDER BY "series_0.data" DESC
LIMIT ?`,
[
tableName,
SqlString.raw(parentSpanWhereCondition),
tableName,
SqlString.raw(childrenSpanWhereCondition),
maxNumGroups,
],
);

return await tracer.startActiveSpan(
'clickhouse.getSpanPerformanceChart',
async span => {
try {
span.setAttribute('query', query);
logger.info({ query });

const rows = await client.query({
query,
format: 'JSON',
clickhouse_settings: {
additional_table_filters: buildLogStreamAdditionalFilters(
tableVersion,
teamId,
),
},
});
const result = await rows.json<
ResponseJSON<{
data: string;
ts_bucket: number;
group: string[];
}>
>();
return result;
} catch (e) {
span.recordException(e as any);
span.end();
throw e;
} finally {
span.end();
}
},
);
};

export const getLogsChart = async ({
aggFn,
endTime,
Expand Down
3 changes: 0 additions & 3 deletions packages/api/src/routers/api/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@ router.post(
if (teamId == null) {
return res.sendStatus(403);
}
if (!isNumber(startTime) || !isNumber(endTime)) {
return res.sendStatus(400);
}

const team = await getTeam(teamId);
if (team == null) {
Expand Down
61 changes: 61 additions & 0 deletions packages/api/src/routers/api/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,67 @@ router.get('/chart/histogram', async (req, res, next) => {
}
});

// This endpoint needs to be generalized replaced once use-case matures
router.post(
'/chart/spanPerformance',
validateRequest({
body: z.object({
parentSpanWhere: z.string().max(1024),
childrenSpanWhere: z.string().max(1024),
endTime: z.number(),
startTime: z.number(),
maxGroups: z.optional(z.number().min(1).max(20)),
}),
}),
async (req, res, next) => {
try {
const teamId = req.user?.team;
const {
endTime,
startTime,
parentSpanWhere,
childrenSpanWhere,
maxGroups,
} = req.body;

if (teamId == null) {
return res.sendStatus(403);
}

const team = await getTeam(teamId);
if (team == null) {
return res.sendStatus(403);
}

const propertyTypeMappingsModel =
await clickhouse.buildLogsPropertyTypeMappingsModel(
team.logStreamTableVersion,
teamId.toString(),
startTime,
endTime,
);

res.json(
await clickhouse.getSpanPerformanceChart({
endTime: endTime,
maxNumGroups: maxGroups ?? 20,
startTime: startTime,
tableVersion: team.logStreamTableVersion,
teamId: teamId.toString(),
parentSpanWhere,
childrenSpanWhere,
propertyTypeMappingsModel,
}),
);
} catch (e) {
const span = opentelemetry.trace.getActiveSpan();
span?.recordException(e as Error);
span?.setStatus({ code: SpanStatusCode.ERROR });
next(e);
}
},
);

router.get(
'/chart',
validateRequest({
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/ChartUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export function seriesColumns({
seriesReturnType === 'ratio'
? [
{
dataKey: `series_0.data`,
dataKey: `series_0.data` as `series_${number}.data`,
displayName:
'displayName' in series[0] && series[0].displayName != null
? series[0].displayName
Expand All @@ -135,7 +135,7 @@ export function seriesColumns({
]
: series.map((s, i) => {
return {
dataKey: `series_${i}.data`,
dataKey: `series_${i}.data` as `series_${number}.data`,
displayName: seriesDisplayName(s, {
showField,
showWhere,
Expand Down
3 changes: 2 additions & 1 deletion packages/app/src/EndpointLatencyTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function EndpointLatencyTile({
return (
<Card p="md">
<Card.Section p="md" py="xs" withBorder>
<Flex justify="space-between">
<Flex justify="space-between" align="center">
<span>Request Latency</span>
<Box>
<Button.Group>
Expand Down Expand Up @@ -90,6 +90,7 @@ export default function EndpointLatencyTile({
],
seriesReturnType: 'column',
}}
showDisplaySwitcher={false}
/>
) : (
<HDXHistogramChart
Expand Down
Loading
Loading