-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Errors (versions) #3187
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
base: main
Are you sure you want to change the base?
Errors (versions) #3187
Changes from all commits
b6ead44
307f968
1b05a0b
5e44b5f
82a5ea0
de3a49f
e609e8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import * as Ariakit from "@ariakit/react"; | ||
| import { SelectTrigger } from "~/components/primitives/Select"; | ||
| import { useSearchParams } from "~/hooks/useSearchParam"; | ||
| import { appliedSummary, FilterMenuProvider } from "~/components/runs/v3/SharedFilters"; | ||
| import { filterIcon, VersionsDropdown } from "~/components/runs/v3/RunFilters"; | ||
| import { AppliedFilter } from "~/components/primitives/AppliedFilter"; | ||
|
|
||
| const shortcut = { key: "v" }; | ||
|
|
||
| export function LogsVersionFilter() { | ||
| const { values, del } = useSearchParams(); | ||
| const selectedVersions = values("versions"); | ||
|
|
||
| if (selectedVersions.length === 0 || selectedVersions.every((v) => v === "")) { | ||
| return ( | ||
| <FilterMenuProvider> | ||
| {(search, setSearch) => ( | ||
| <VersionsDropdown | ||
| trigger={ | ||
| <SelectTrigger | ||
| icon={filterIcon("versions")} | ||
| variant="secondary/small" | ||
| shortcut={shortcut} | ||
| tooltipTitle="Filter by version" | ||
| > | ||
| <span className="ml-0.5">Versions</span> | ||
| </SelectTrigger> | ||
| } | ||
| searchValue={search} | ||
| clearSearchValue={() => setSearch("")} | ||
| /> | ||
| )} | ||
| </FilterMenuProvider> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <FilterMenuProvider> | ||
| {(search, setSearch) => ( | ||
| <VersionsDropdown | ||
| trigger={ | ||
| <Ariakit.Select render={<div className="group cursor-pointer focus-custom" />}> | ||
| <AppliedFilter | ||
| label="Versions" | ||
| icon={filterIcon("versions")} | ||
| value={appliedSummary(selectedVersions)} | ||
| onRemove={() => del(["versions", "cursor", "direction"])} | ||
| variant="secondary/small" | ||
| /> | ||
| </Ariakit.Select> | ||
| } | ||
| searchValue={search} | ||
| clearSearchValue={() => setSearch("")} | ||
| /> | ||
| )} | ||
| </FilterMenuProvider> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { z } from "zod"; | |
| import { type ClickHouse, msToClickHouseInterval } from "@internal/clickhouse"; | ||
| import { TimeGranularity } from "~/utils/timeGranularity"; | ||
| import { ErrorId } from "@trigger.dev/core/v3/isomorphic"; | ||
| import { type PrismaClientOrTransaction } from "@trigger.dev/database"; | ||
| import { type ErrorGroupStatus, type PrismaClientOrTransaction } from "@trigger.dev/database"; | ||
| import { timeFilterFromTo } from "~/components/runs/v3/SharedFilters"; | ||
| import { type Direction, DirectionSchema } from "~/components/ListPagination"; | ||
| import { findDisplayableEnvironment } from "~/models/runtimeEnvironment.server"; | ||
|
|
@@ -27,6 +27,7 @@ export type ErrorGroupOptions = { | |
| userId?: string; | ||
| projectId: string; | ||
| fingerprint: string; | ||
| versions?: string[]; | ||
| runsPageSize?: number; | ||
| period?: string; | ||
| from?: number; | ||
|
|
@@ -39,6 +40,7 @@ export const ErrorGroupOptionsSchema = z.object({ | |
| userId: z.string().optional(), | ||
| projectId: z.string(), | ||
| fingerprint: z.string(), | ||
| versions: z.array(z.string()).optional(), | ||
| runsPageSize: z.number().int().positive().max(1000).optional(), | ||
| period: z.string().optional(), | ||
| from: z.number().int().nonnegative().optional(), | ||
|
|
@@ -59,6 +61,18 @@ function parseClickHouseDateTime(value: string): Date { | |
| return new Date(value.replace(" ", "T") + "Z"); | ||
| } | ||
|
|
||
| export type ErrorGroupState = { | ||
| status: ErrorGroupStatus; | ||
| resolvedAt: Date | null; | ||
| resolvedInVersion: string | null; | ||
| resolvedBy: string | null; | ||
| ignoredUntil: Date | null; | ||
| ignoredReason: string | null; | ||
| ignoredByUserId: string | null; | ||
| ignoredUntilOccurrenceRate: number | null; | ||
| ignoredUntilTotalOccurrences: number | null; | ||
| }; | ||
|
|
||
| export type ErrorGroupSummary = { | ||
| fingerprint: string; | ||
| errorType: string; | ||
|
|
@@ -68,10 +82,12 @@ export type ErrorGroupSummary = { | |
| firstSeen: Date; | ||
| lastSeen: Date; | ||
| affectedVersions: string[]; | ||
| state: ErrorGroupState; | ||
| }; | ||
|
|
||
| export type ErrorGroupOccurrences = Awaited<ReturnType<ErrorGroupPresenter["getOccurrences"]>>; | ||
| export type ErrorGroupActivity = ErrorGroupOccurrences["data"]; | ||
| export type ErrorGroupActivityVersions = ErrorGroupOccurrences["versions"]; | ||
|
|
||
| export class ErrorGroupPresenter extends BasePresenter { | ||
| constructor( | ||
|
|
@@ -89,6 +105,7 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| userId, | ||
| projectId, | ||
| fingerprint, | ||
| versions, | ||
| runsPageSize = DEFAULT_RUNS_PAGE_SIZE, | ||
| period, | ||
| from, | ||
|
|
@@ -110,23 +127,36 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| defaultPeriod: "7d", | ||
| }); | ||
|
|
||
| const [summary, affectedVersions, runList] = await Promise.all([ | ||
| const [summary, affectedVersions, runList, stateRow] = await Promise.all([ | ||
| this.getSummary(organizationId, projectId, environmentId, fingerprint), | ||
| this.getAffectedVersions(organizationId, projectId, environmentId, fingerprint), | ||
| this.getRunList(organizationId, environmentId, { | ||
| userId, | ||
| projectId, | ||
| fingerprint, | ||
| versions, | ||
| pageSize: runsPageSize, | ||
| from: time.from.getTime(), | ||
| to: time.to.getTime(), | ||
| cursor, | ||
| direction, | ||
| }), | ||
| this.getState(environmentId, fingerprint), | ||
| ]); | ||
|
|
||
| if (summary) { | ||
| summary.affectedVersions = affectedVersions; | ||
| summary.state = stateRow ?? { | ||
| status: "UNRESOLVED", | ||
| resolvedAt: null, | ||
| resolvedInVersion: null, | ||
| resolvedBy: null, | ||
| ignoredUntil: null, | ||
| ignoredReason: null, | ||
| ignoredByUserId: null, | ||
| ignoredUntilOccurrenceRate: null, | ||
| ignoredUntilTotalOccurrences: null, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
|
|
@@ -140,23 +170,26 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| } | ||
|
|
||
| /** | ||
| * Returns bucketed occurrence counts for a single fingerprint over a time range. | ||
| * Granularity is determined automatically from the range span. | ||
| * Returns bucketed occurrence counts for a single fingerprint over a time range, | ||
| * grouped by task_version for stacked charts. | ||
| */ | ||
| public async getOccurrences( | ||
| organizationId: string, | ||
| projectId: string, | ||
| environmentId: string, | ||
| fingerprint: string, | ||
| from: Date, | ||
| to: Date | ||
| to: Date, | ||
| versions?: string[] | ||
| ): Promise<{ | ||
| data: Array<{ date: Date; count: number }>; | ||
| data: Array<Record<string, number | Date>>; | ||
| versions: string[]; | ||
| }> { | ||
| const granularityMs = errorGroupGranularity.getTimeGranularityMs(from, to); | ||
| const intervalExpr = msToClickHouseInterval(granularityMs); | ||
|
|
||
| const queryBuilder = this.logsClickhouse.errors.createOccurrencesQueryBuilder(intervalExpr); | ||
| const queryBuilder = | ||
| this.logsClickhouse.errors.createOccurrencesByVersionQueryBuilder(intervalExpr); | ||
|
|
||
| queryBuilder.where("organization_id = {organizationId: String}", { organizationId }); | ||
| queryBuilder.where("project_id = {projectId: String}", { projectId }); | ||
|
|
@@ -169,7 +202,11 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| toTimeMs: to.getTime(), | ||
| }); | ||
|
|
||
| queryBuilder.groupBy("error_fingerprint, bucket_epoch"); | ||
| if (versions && versions.length > 0) { | ||
| queryBuilder.where("task_version IN {versions: Array(String)}", { versions }); | ||
| } | ||
|
|
||
| queryBuilder.groupBy("error_fingerprint, task_version, bucket_epoch"); | ||
| queryBuilder.orderBy("bucket_epoch ASC"); | ||
|
|
||
| const [queryError, records] = await queryBuilder.execute(); | ||
|
|
@@ -186,17 +223,27 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| buckets.push(epoch); | ||
| } | ||
|
|
||
| const byBucket = new Map<number, number>(); | ||
| // Collect distinct versions and index results by (epoch, version) | ||
| const versionSet = new Set<string>(); | ||
| const byBucketVersion = new Map<string, number>(); | ||
| for (const row of records ?? []) { | ||
| byBucket.set(row.bucket_epoch, (byBucket.get(row.bucket_epoch) ?? 0) + row.count); | ||
| const version = row.task_version || "unknown"; | ||
| versionSet.add(version); | ||
| const key = `${row.bucket_epoch}:${version}`; | ||
| byBucketVersion.set(key, (byBucketVersion.get(key) ?? 0) + row.count); | ||
| } | ||
|
|
||
| return { | ||
| data: buckets.map((epoch) => ({ | ||
| date: new Date(epoch * 1000), | ||
| count: byBucket.get(epoch) ?? 0, | ||
| })), | ||
| }; | ||
| const sortedVersions = sortVersionsDescending([...versionSet]); | ||
|
|
||
| const data = buckets.map((epoch) => { | ||
| const point: Record<string, number | Date> = { date: new Date(epoch * 1000) }; | ||
| for (const version of sortedVersions) { | ||
| point[version] = byBucketVersion.get(`${epoch}:${version}`) ?? 0; | ||
| } | ||
| return point; | ||
| }); | ||
|
Comment on lines
+238
to
+244
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Version string used as Record key can collide with reserved In Prompt for agentsWas this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| return { data, versions: sortedVersions }; | ||
| } | ||
|
|
||
| private async getSummary( | ||
|
|
@@ -268,13 +315,39 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| return sortVersionsDescending(versions).slice(0, 5); | ||
| } | ||
|
|
||
| private async getState( | ||
| environmentId: string, | ||
| fingerprint: string | ||
| ): Promise<ErrorGroupState | null> { | ||
| const row = await this.replica.errorGroupState.findFirst({ | ||
| where: { | ||
| environmentId, | ||
| errorFingerprint: fingerprint, | ||
| }, | ||
| select: { | ||
| status: true, | ||
| resolvedAt: true, | ||
| resolvedInVersion: true, | ||
| resolvedBy: true, | ||
| ignoredUntil: true, | ||
| ignoredReason: true, | ||
| ignoredByUserId: true, | ||
| ignoredUntilOccurrenceRate: true, | ||
| ignoredUntilTotalOccurrences: true, | ||
| }, | ||
| }); | ||
|
|
||
| return row; | ||
| } | ||
|
|
||
| private async getRunList( | ||
| organizationId: string, | ||
| environmentId: string, | ||
| options: { | ||
| userId?: string; | ||
| projectId: string; | ||
| fingerprint: string; | ||
| versions?: string[]; | ||
| pageSize: number; | ||
| from?: number; | ||
| to?: number; | ||
|
|
@@ -289,6 +362,7 @@ export class ErrorGroupPresenter extends BasePresenter { | |
| projectId: options.projectId, | ||
| rootOnly: false, | ||
| errorId: ErrorId.toFriendlyId(options.fingerprint), | ||
| versions: options.versions, | ||
| pageSize: options.pageSize, | ||
| from: options.from, | ||
| to: options.to, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
State lookup needs the task identifier.
ErrorGroupStateis keyed by environment +taskIdentifier+ fingerprint elsewhere in this PR, but this query only filters by environment and fingerprint. If the same fingerprint exists under multiple tasks, the page can show the wrong resolved/ignored state; fetchingsummaryandstateRowin the samePromise.allalso prevents you from disambiguating it.Also applies to: 318-340
🤖 Prompt for AI Agents