Skip to content

feat(mcp): emerging_signals compares both windows in one Drain tree and reports new variants - #3753

Draft
bcanvural wants to merge 1 commit into
ClickHouse:mainfrom
bcanvural:feat/emerging-signals-one-tree
Draft

bcanvural wants to merge 1 commit into
ClickHouse:mainfrom
bcanvural:feat/emerging-signals-one-tree

Conversation

@bcanvural

Copy link
Copy Markdown
Contributor

Summary

Refs #3556, #3544 (option 2). Replaces draft #3557, which was stacked on the pre-merge version of #3551; this is the same change on current main.

emerging_signals mines the baseline and current windows in two separate Drain trees and matches their templates as strings. The two trees can generalize the same message differently: a token that is constant in one window stays literal there and becomes <*> in the other, so one unchanged pattern is reported as both "new" and "gone". Date masking (#3551) removed the most common cause; this removes the rest.

This PR:

  • fetches both windows in parallel, then mines them in one TemplateMiner, baseline first, and compares them by cluster id. The order is fixed, so the result doesn't depend on which query finishes first.
  • New variants. One tree can hide a new message that Drain merges into a similar baseline pattern (e.g. user login failed: account locked into user login failed: invalid password). Baseline templates are copied after the baseline is mined. A current row whose cluster came from the baseline but doesn't match that baseline template (token compare, no regex) is reported in emerging with status: "new_variant", baselinePattern, variantShare, and the new line as its sample. Baseline clusters with fewer than 3 sampled rows are skipped.
  • makes the earlier window half-open (dateRangeEndInclusive: false), so a row at the boundary is counted once.

Supporting changes: minePatterns takes an optional miner and returns rowClusterIds (the cluster of each input row); TemplateMiner.tokenize returns the masked tokens Drain compares. mineWindowPatterns is split into fetchWindowSample + mineWindowSample and kept as a wrapper, so event_patterns is unchanged.

Cost: on test data with 100 changed patterns, the variant step takes about 10 ms per 10K rows, and the whole call went from 496 ms to 221 ms (one tree instead of two).

How to reproduce

Starting point: make dev-int.

On main:

  1. Add packages/api/src/mcp/__tests__/emergingSignalsOrder.test.ts from this PR.
  2. npx jest src/mcp/__tests__/emergingSignalsOrder.test.ts in packages/api: it fails, because main has no fetchWindowSample / mineWindowSample and reports no new_variant.

On this branch:

  1. emergingSignalsOrder.test.ts passes (17 tests): the login example → new_variant; dated lines on two days → nothing; identical windows → nothing; a token varying only in the current window; same result whichever query finishes first; small baseline clusters skipped; a variant never shows in disappeared.
  2. drain-masking.test.ts (shared miner, rowClusterIds, tokenize) passes; common-utils 3,412, MCP unit 654 and MCP integration (queryTool, emergingSignalsTool, eventPatterns, dashboard) 370 tests pass.

How to test on Vercel preview

N/A — non-UI change.

References

…nd reports new variants

Both windows are mined in one tree, baseline first, and compared by cluster, so
a token that is constant in one window and varies in the other no longer splits
a pattern. New messages that Drain merges into a baseline pattern are found from
Drain's own row assignment with a token compare against the baseline template,
and reported as new_variant. The baseline window excludes its end.
@changeset-bot

changeset-bot Bot commented Nov 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 95a4ed5

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 Patch
@hyperdx/api Patch
@hyperdx/app Patch
@hyperdx/otel-collector Patch

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

@vercel

vercel Bot commented Nov 21, 2026

Copy link
Copy Markdown

@bcanvural is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant