Skip to content

Commit

Permalink
feat: add result summary & filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Oct 6, 2024
1 parent d5ed4cb commit 759b9dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
17 changes: 16 additions & 1 deletion packages/api/src/lib/invocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,26 @@ const getStatusCodeFromSpan = (span) => {
return null;
};

const getResultSummaryFromSpan = (span) => {
let mainStatus = "Successful";
if (span.error) {
mainStatus = span.error?.type || "Invocation failed";
}

const statusCode = getStatusCodeFromSpan(span);
if (statusCode) {
mainStatus += ` (${statusCode})`;
}

return mainStatus;
};

export const saveInvocation = async (span) => {
await put(
return put(
{
...span,
statusCode: getStatusCodeFromSpan(span),
resultSummary: getResultSummaryFromSpan(span),
pk: `function#${span.region}#${span.name}`,
sk: `invocation#${span.started}#${span.id}`,
type: "invocation",
Expand Down
21 changes: 18 additions & 3 deletions packages/api/src/routes/explore/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ app.get("/functions/:region/:name/invocations", async (c) => {
const endTs = end.getTime();

const startKey = c.req.query("startKey");
const { Items, LastEvaluatedKey } = await query({

const params = {
KeyConditionExpression: "#pk = :pk AND #sk BETWEEN :skStart AND :skEnd",
ExclusiveStartKey: startKey ? JSON.parse(startKey) : undefined,
ExpressionAttributeNames: {
Expand All @@ -77,17 +78,31 @@ app.get("/functions/:region/:name/invocations", async (c) => {
"#region": "region",
"#name": "name",
"#statusCode": "statusCode",
"#resultSummary": "resultSummary",
},
ExpressionAttributeValues: {
":pk": `function#${c.req.param("region")}#${c.req.param("name")}`,
":skStart": `invocation#${startTs}`,
":skEnd": `invocation#${endTs}`,
},
ProjectionExpression:
"#pk, #sk, #type, #error, #id, #region, #name, #statusCode, transactionId, started, ended, readiness, memoryAllocated",
"#pk, #sk, #type, #error, #id, #region, #name, #statusCode, #resultSummary, transactionId, started, ended, readiness, memoryAllocated",
Limit: 50,
ScanIndexForward: false,
});
};

const resultSummaryFilters = c.req.query("resultSummaryFilters")?.split(',') || [];
if (resultSummaryFilters.length) {
const filterExpression = [];
for (const filter of resultSummaryFilters) {
const variableName = `:f${filterExpression.length}`;
filterExpression.push(`#resultSummary = ${variableName}`);
params.ExpressionAttributeValues[variableName] = filter;
}
params.FilterExpression = filterExpression.join(" OR ");
}

const { Items, LastEvaluatedKey } = await query(params);

return c.json({
invocations: Items,
Expand Down

0 comments on commit 759b9dd

Please sign in to comment.