Apply saved-search filters to alert sample queries - #3106
Conversation
🦋 Changeset detectedLatest commit: 3b15bea The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@Tyagiquamar is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @Tyagiquamar, thanks for the pull request! Before we review code from a first-time contributor we ask that a maintainer vouches for you, and you're not on our list yet. This PR stays open — it just isn't in the review queue until someone vouches. To get vouched, open an issue saying hello and what you're working on: https://github.com/hyperdxio/hyperdx/issues/new?template=introduce-yourself.md A maintainer will usually reply within a day or two, and then this PR gets picked up as normal. More detail in our contributing guide. |
Greptile SummaryThe PR routes saved-search alert sample queries through the shared search-chart builder so pinned and source-level filters match the evaluated row set.
Confidence Score: 4/5The PR should not merge until the ClickHouse test mock is assignable to the The production query change consistently applies the shared saved-search configuration, but the test's new Files Needing Attention: packages/api/src/tasks/checkAlerts/tests/renderAlertTemplate.int.test.ts
|
| Filename | Overview |
|---|---|
| packages/api/src/tasks/checkAlerts/template.ts | Replaces hand-built sample-query configuration with the shared saved-search chart builder and passes pinned filters. |
| packages/api/src/tasks/checkAlerts/tests/renderAlertTemplate.int.test.ts | Adds pinned-filter SQL coverage, but the newly narrowed client type is incompatible with the function parameter. |
| .changeset/silent-pandas-search.md | Records the alert sample-query correction as an API patch release. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[Saved search] --> B[Shared search chart-config builder]
B --> C[Alert evaluation query]
B --> D[Notification sample query]
C --> E[Alert count]
D --> F[Filtered sample log lines]
Reviews (2): Last reviewed commit: "fix(alerts): reuse search config for sam..." | Re-trigger Greptile
Deep Review✅ No critical issues found. The core change is correct: the sample-log fetch in the Verified independently:
🔵 P3 nitpicks (1)
Reviewers (5): correctness, testing, project-standards, kieran-typescript, previous-comments. Previous comments: The major "sample query still isn't the counted row set ( |
| whereLanguage: savedSearch.whereLanguage, | ||
| // The alert evaluation counts the filtered row set, so the sample | ||
| // query must apply the same pinned filters or it shows unrelated lines. | ||
| filters: savedSearch.filters?.map(f => ({ ...f })), |
There was a problem hiding this comment.
🟠 major — Sample query still isn't the counted row set: tableFilterExpression (and bodyExpression) are missing
Build this config with buildSearchChartConfig(source, { where, whereLanguage, filters, select: savedSearch.select, orderBy, connection: '', dateRange: [startTime, endTime], dateRangeStartInclusive: true, dateRangeEndInclusive: false }) (packages/common-utils/src/core/searchChartConfig.ts:120) and then add limit/with, instead of adding filters to a hand-built twin. The evaluation path goes through that builder (packages/api/src/tasks/checkAlerts/index.ts:817), which (a) prepends a Log source's tableFilterExpression as the first SQL filter — pinned by checkAlerts.int.test.ts:2486, so a source with tableFilterExpression: "ServiceName != 'excluded'" counts 1 row while this sample query still returns the excluded row into the webhook body — and (b) passes bodyExpression, without which a Log source that sets only bodyExpression (no implicitColumnExpression) makes getColumnForField throw "Can not search bare text without an implicit column set" (packages/common-utils/src/queryParser.ts:1942) for a bare-text Lucene search or Lucene filter; the throw is swallowed by the catch at line 853 and the notification renders an empty code block. Reusing the builder also removes the duplicated select fallback at line 800 (resolveSelect, searchChartConfig.ts:94).
PR Review3 finding(s): 🔴 0 critical · 🟠 2 major · 🔵 1 minor 2 posted as inline comment(s) on the changed lines. 1 listed below. Findings outside the changed lines
Severity is the reviewer's own estimate and is used for ordering, not filtering. |
|
/vouch @Tyagiquamar |
|
Please fix the lint errors (unused and out of order imports, and an incorrect type for capturingClickhouseClient) |
Fixes #3059.
Why
A saved search scoped through the filter bar evaluated correctly, but the sample events rendered into the notification came from an unfiltered query, so alerts showed unrelated log lines as evidence next to a correct count.
What changed
The sample fetch in renderAlertTemplate hand-built its chart config from where/whereLanguage only. It now also passes savedSearch.filters, the same input the evaluation path feeds buildSearchChartConfig, so renderChartConfig narrows both queries to the same row set. TILE and INLINE paths are untouched. Includes a changeset (patch, @hyperdx/api).
Tests