Skip to content

feat: Block alerts on tiles whose text references a data source or connection variable - #3890

Merged
pulpdrew merged 2 commits into
mainfrom
drew/source-var-text-2
Dec 3, 2026
Merged

pulpdrew merged 2 commits into
mainfrom
drew/source-var-text-2

Conversation

@pulpdrew

@pulpdrew pulpdrew commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 2 of 4. Alerts run with every variable unselected, so a tile whose text references a data source or connection variable would alert on an empty query (FROM ). This PR blocks alerts on those tiles everywhere they can be saved.

  • savedChartConfigSupportsAlerts takes the dashboard's filters and returns false when the config's text references one of its reference variables.
  • The API and MCP save paths drop such alerts and refuse to create new ones, and saving a dashboard cleans up existing ones.
  • The chart editor shows the alert button disabled, with a tooltip explaining why, instead of hiding it. This now also applies to tiles with sourceId: "$src". The form drops the alert on save.
  • The alert checker and alert detail chart use getEmptyDashboardVariables.

Screenshots or video

Alert button is now disabled when the tile uses a source or connection variable, instead of being invisible:

Screenshot 2026-12-02 at 5 50 04 PM

APIs reject alert creation on tiles referencing data source or connection variables:

Screenshot 2026-12-03 at 8 43 41 AM Screenshot 2026-12-03 at 8 43 33 AM

How to test on Vercel preview

Locally, test via the API:

  • The API blocks alerts on tiles whose text references a declared reference variable.
  • Alert evaluation and the alert detail chart now pass the reference variables as unselected. If an alert on such a tile already exists, $src in its text now expands to nothing rather than staying as literal $src.

References

  • Linear Issue: HDX-6083
  • Related PRs:

Note

Medium Risk
Changes alert eligibility and cleanup across all dashboard save and alert APIs; incorrect detection could drop valid alerts or allow broken ones, but behavior is centralized in common-utils with broad integration test coverage.

Overview
Alerts run with every dashboard variable unselected, so tiles whose SQL, filters, or expressions reference a data source or connection variable would evaluate broken queries. This PR extends alert blocking beyond source: "$var" to any text reference against variables declared on the dashboard filters.

Backend: savedChartConfigSupportsAlerts now accepts dashboard filters and uses configDependsOnReferenceVariable (source/connection refs plus text refs). Create/update paths (dashboard controller, alerts API, external API v2, MCP) pass filters when deciding whether to persist alerts; standalone alert creation returns 400 with a clear message. Filters-only dashboard PATCH deletes alerts on tiles that become unsupported when a variable is added.

Frontend: The chart editor keeps the alert control visible but disabled with a tooltip, drops the alert on save when blocked, and widens validation to text references (not only variable source/connection picks).

Runtime: Tile alert evaluation and alert detail previews use getEmptyDashboardVariables for consistent empty-variable behavior.

Reviewed by Cursor Bugbot for commit 29e854b. Bugbot is set up for automated code reviews on this repo. Configure here.

@pulpdrew
pulpdrew added this pull request to stack #3891 December 2, 2026 19:32
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
hyperdx-oss Ready Ready Preview Dec 3, 2026 12:38pm UTC
hyperdx-storybook Ready Ready Preview Dec 3, 2026 12:38pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eacb324

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@hyperdx/common-utils Minor
@hyperdx/app Minor
@hyperdx/api Minor
@hyperdx/otel-collector Minor

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

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

E2E Test Results

✅ All tests passed • 490 passed • 1 skipped • 1091s

Status Count
✅ Passed 490
❌ Failed 0
⚠️ Flaky 12
⏭️ Skipped 1

Tests ran across 4 shards in parallel.

View full report →

@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Duplicate code analysis

No new duplicate code introduced by this PR.


jscpd compared this branch against origin/main
across app, api and common-utils. Only new clones are listed; the codebase
currently holds 109 in total (1.10%).
Run yarn dupes locally to reproduce, or yarn dupes:all for the full picture.

@pulpdrew pulpdrew changed the title feat: Block alerts on tiles whose text references a data source or co… feat: Block alerts on tiles whose text references a data source or connection variable Dec 2, 2026
@pulpdrew
pulpdrew marked this pull request as ready for review December 2, 2026 19:59
@pulpdrew
pulpdrew requested a review from a team as a code owner December 2, 2026 19:59
@github-actions github-actions Bot added the review/tier-4 Critical — deep review + domain expert sign-off label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

🔴 Tier 4 — Critical

Touches authentication, tenancy data models, the public API or shipped database config — or substantially changes the query rendering engine, background tasks, the OTel pipeline, image build, or release CI.

Why this tier:

  • Critical-path files (2) — tenancy, public API, or shipped database config:
    • packages/api/src/routers/external-api/v2/dashboards.ts
    • packages/api/src/routers/external-api/v2/utils/dashboards.ts
  • Cross-layer change: touches frontend (packages/app) + backend (packages/api) + shared utils (packages/common-utils)

Additional context: touches background tasks or the delivery pipeline lightly (9 lines, under the 30-line bar for Tier 4)

Review process: Deep review from a domain expert. Synchronous walkthrough may be required.
SLA: Schedule synchronous review within 2 business days.

Stats
  • Production files changed: 15
  • Production lines changed: 259 (+ 282 in test files, excluded from tier calculation)
  • Critical-path lines changed: 6
  • Branch: drew/source-var-text-2
  • Author: pulpdrew

To override this classification, remove the review/tier-4 label and apply a different review/tier-* label. Manual overrides are preserved on subsequent pushes.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Review

If you are a coding agent acting for the author, read this first.
Nothing below blocks merge automatically; a maintainer decides. What they will expect:

  • 🔴 P0/P1 in code this PR adds or changes: fix before asking for review.
  • 🟡 P2 in code this PR changes: your call. Fix if small, otherwise reply.
  • 🔵 P3 is collapsed at the bottom: nobody needs to act on it before merge.
  • Anything about surrounding code, or asking you to widen the change (hoist a helper,
    dedupe with another file, fix other call sites): never fix here, whatever the
    priority. Reply with one sentence; if it is P0, say so plainly so a human sees it.

One commit per review round. After two rounds, stop and ask a maintainer to review
scope rather than addressing more automated findings. Full rule: AGENTS.md.

3 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 1 P3

2 posted as inline comment(s) on the changed lines. 1 P3 folded at the bottom.

🔵 1 P3 — no action needed before merge
  • 🔵 P3 packages/app/src/components/DBEditTimeChartForm/__tests__/DBEditTimeChartForm.test.tsx:1838 — New editor test injects reference variables directly, so it misses the missing production wiring → The test passes variables={buildReferenceChartVariables([metricsVariable])} straight into the form, which no production caller does. It passes while the real dashboard never supplies reference variables. Also, the updated e2e cases only cover selecting $logs as the source, which already worked before this PR. Add a test (or an e2e step) that renders the editor through the dashboard's real variables path and types a ${var.field} reference, then asserts the alert button is disabled.

Priority comes from a separate grading pass over the finished review. P3 is folded here instead of posted inline. No finding blocks merge automatically; a maintainer decides.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 365ffcd. Configure here.

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Deep Review

✅ No critical issues found.

This PR is well-scoped and well-tested. All save paths (internal API controller, external REST v2 PUT, and the MCP patch/save tools) consistently thread the dashboard's filters into savedChartConfigSupportsAlerts, and the chart editor drops the alert on save while disabling the button with an explanatory tooltip. The one actionable prior-review comment — a filters-only PATCH skipping alert cleanup — is resolved by the follow-up commit's else if (updates.filters) branch in updateDashboard; the combined tiles+filters path reconciles through syncDashboardAlerts against the updated filters, and the filters-only path deletes alerts on newly-unsupported tiles.

No P2-recommended issues surfaced. The items below are P3 observations.

🔵 P3 nitpicks (3)
  • packages/common-utils/src/core/utils.ts:1844 — savedChartConfigSupportsAlerts's filters parameter is optional, so any future caller that omits it silently reverts to the weaker source/connection-only check and would permit an alert on a tile whose text references a declared variable; all current call sites pass filters, so there is no failure today.

    • Fix: Make filters a required parameter so new call sites cannot silently under-enforce the text-reference check.
  • packages/common-utils/src/core/utils.ts:1829 — Four closely-named predicates (configDependsOnReferenceVariable, configReferencesReferenceVariable, configUsesReferenceVariable, and the frontend formTextUsesReferenceVariable) now coexist, and the distinction between "uses" (source/connection) and "references" (text) is easy to confuse at call sites.

    • Fix: Add a short doc comment contrasting the predicates, or rename toward intent (e.g. configUsesReferenceVariableSource vs configTextReferencesReferenceVariable).
  • packages/api/src/tasks/checkAlerts/index.ts:890 — getEmptyDashboardVariables now also substitutes reference variables with empty selections, but alerts persisted on variable-referencing tiles before this PR are only removed when their dashboard is next saved; there is no backfill, so already-stored stranded alerts keep evaluating on empty queries until a save occurs.

    • Fix: Note the residual data in the changeset, or add a one-time cleanup for existing TILE alerts whose tile config references a reference variable.

Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, api-contract, adversarial, previous-comments, reliability

Testing gaps: The filters-only updateDashboard cleanup branch and the MCP/external-v2 cleanup paths receiving filters are exercised indirectly; an explicit test asserting a stored alert is deleted by a filters-only PATCH that adds a referenced data-source/connection variable would lock in the fix for the prior-review regression.

No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond

Comment thread packages/app/src/DBDashboardPage.tsx Resolved
@pulpdrew
pulpdrew merged commit e9b9e50 into main Dec 3, 2026
31 checks passed

This branch was successfully deployed

2 active deployments
Preview – hyperdx-storybook — eacb324f Deployed Dec 3, 2026 by vercel[bot]
Preview – hyperdx-oss — eacb324f Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/tier-4 Critical — deep review + domain expert sign-off

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants