Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 7 additions & 2 deletions apps/web/src/components/errors/errors-hub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import {
} from "@/lib/services/atoms/warehouse-query-atoms"
import { retainedQueryV2 } from "@/lib/services/common/v2-atom-client"
import { errorIssueFromV2 } from "@/lib/services/error-issues"
import { buildErrorSignals, indexInvestigationsByIssue, type ErrorSignal } from "@/lib/models/error-signal"
import {
buildErrorSignals,
indexInvestigationsByIssue,
sparkFingerprintHashes,
type ErrorSignal,
} from "@/lib/models/error-signal"
import {
clearedSelection,
type IssueSelectionMsg,
Expand Down Expand Up @@ -277,7 +282,7 @@ export function ErrorsHub(props: ErrorsHubProps) {

// The sparkline set follows the rows actually on screen, so a filtered view
// never pays for fingerprints it will not draw.
const fingerprintHashes = useMemo(() => issues.map((issue) => issue.fingerprintHash), [issues])
const fingerprintHashes = useMemo(() => sparkFingerprintHashes(issues), [issues])

const bucketSeconds = useMemo(() => {
const startMs = Date.parse(props.range.startTime.replace(" ", "T") + "Z")
Expand Down
17 changes: 16 additions & 1 deletion apps/web/src/lib/models/error-signal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, expect, it } from "vitest"
import type { WorkflowState } from "@maple/domain/http"
import type { V2Investigation } from "@maple/domain/http/v2"

import { densifySpark, resolveSignalState, surgeRatio } from "./error-signal"
import { densifySpark, resolveSignalState, sparkFingerprintHashes, surgeRatio } from "./error-signal"

const HOUR_MS = 3_600_000

Expand Down Expand Up @@ -48,6 +48,21 @@ describe("resolveSignalState", () => {
})
})

describe("sparkFingerprintHashes", () => {
it("keeps only the issues whose fingerprint the warehouse can parse", () => {
// Alert and integration issues reuse the fingerprint column for a
// synthetic key. Sending one to the batched spark query makes ClickHouse
// reject `toUInt64('alert:…')` and fails the sparklines for every row.
const hashes = sparkFingerprintHashes([
{ kind: "error", fingerprintHash: "753390793895937054" },
{ kind: "alert", fingerprintHash: "alert:550bb2c5-8fe0-4ab9-b2f8-e566674cb0a2:scraper" },
{ kind: "integration", fingerprintHash: "planetscale:maple:branch.out_of_memory" },
{ kind: "error", fingerprintHash: "1037926342141719040" },
])
expect(hashes).toEqual(["753390793895937054", "1037926342141719040"])
})
})

describe("densifySpark", () => {
const window = { startMs: 0, endMs: 4 * HOUR_MS, bucketMs: HOUR_MS }

Expand Down
24 changes: 23 additions & 1 deletion apps/web/src/lib/models/error-signal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
//
// An `ErrorSignal` is those three joined on the fingerprint hash.

import type { ErrorIssueDocument, ErrorIssueId, IssueSeverity, WorkflowState } from "@maple/domain/http"
import type {
ErrorIssueDocument,
ErrorIssueId,
IssueKind,
IssueSeverity,
WorkflowState,
} from "@maple/domain/http"
import type { V2Investigation } from "@maple/domain/http/v2"

import type { ErrorByType } from "@/api/warehouse/errors"
Expand Down Expand Up @@ -126,6 +132,22 @@ export function resolveSignalState(
return { kind: "workflow", state: issue.workflowState }
}

/**
* The fingerprints a sparkline can actually be drawn for.
*
* Only `kind === "error"` issues carry a real ClickHouse fingerprint (a decimal
* UInt64 string). Alert and integration issues reuse the column for a synthetic
* key — `alert:{ruleId}:{groupKey}`, `planetscale:{database}:{event}` — which
* `toUInt64()` rejects, failing the whole batched spark query for every row on
* screen. `ErrorIssueReadModelsService.getIssue` skips the warehouse for the
* same reason.
*/
export function sparkFingerprintHashes(
issues: ReadonlyArray<{ readonly kind: IssueKind; readonly fingerprintHash: string }>,
): ReadonlyArray<string> {
return issues.filter((issue) => issue.kind === "error").map((issue) => issue.fingerprintHash)
}

/**
* Join issues (the spine) with warehouse volume and trend.
*
Expand Down
Loading