Repository navigation
Conversation
…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 detectedLatest commit: c8582fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
|
@bcanvural is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
…-one-tree # Conflicts: # packages/api/src/mcp/tools/query/emergingSignals.ts # packages/api/src/mcp/tools/query/runEventPatterns.ts
|
No description provided. |
PR Review
4 finding(s): 🔴 0 P0/P1 · 🟡 2 P2 · 🔵 2 P3 1 posted as inline comment(s) on the changed lines. 1 listed below. 2 P3 folded at the bottom. Findings outside the changed lines
🔵 2 P3 — no action needed before merge
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. |
|
No description provided. |
1 similar comment
|
No description provided. |
| baseCount: a.baseCount, | ||
| sample: b?.sample ?? baselinePattern, | ||
| }; | ||
| if (classifyShift(rest, ratio, newPatternShareFloor) === 'disappeared') |
There was a problem hiding this comment.
Two variant rows hide a surge of the baseline message
Once a cluster has a variant above the floor, rest is only checked for disappeared. If the old message also grows past minShareRatio, that growth is dropped. Only the variant is reported, at its own small share.
Repro, using the helpers in emergingSignalsOrder.test.ts:
it('still reports a baseline message that surged next to a variant', async () => {
const other = (n: number) =>
Array.from({ length: n }, (_, i) => `cache warmed in ${i} regions ok`);
const out = await run(
[...repeat('payment failed: card declined', 10), ...other(990)],
[
...repeat('payment failed: card declined', 500),
...repeat('payment failed: gateway timeout', 2),
...other(498),
],
);
expect(out.emerging).toContainEqual(
expect.objectContaining({ status: 'shifted', pattern: 'payment failed: card declined' }),
);
});- On this branch:
emergingholds onlynew_variant(payment failed: <*> <*>) at share 0.002. The 0.01 → 0.5 jump ofcard declineddoesn't appear anywhere. - Without the 2
gateway timeoutrows: the same data reportsshifted0.01 → 0.5.
So 2 rows of a new message can hide a 50x increase in an existing one. That's probably the more important signal of the two.
Two possible fixes:
- Classify
restin both directions:This gives a cluster twoconst restVerdict = classifyShift(rest, ratio, newPatternShareFloor); if (restVerdict === 'emerging') emerging.push(rest); else if (restVerdict === 'disappeared') disappeared.push(rest);
emergingentries in that case, so "gives one cluster at most one emerging entry" would need to change. I think two entries are correct here, because they are two separate changes. - Keep one entry, but carry the remainder's shift on the variant entry, for example
baselineMessageShare: { baseline, current }. Then rank it by the larger of the two swings, so a big surge isn't sorted under a 0.002 variant.
I'd lean toward option 1. The cost is that a cluster can take two emerging slots.
There was a problem hiding this comment.
Thanks, good catch. I went with option 1 in c8582fa. The rest of the cluster is now classified in both directions, so one cluster can have a new_variant entry and a shifted entry. I added your repro as a test (the surge ranks first), and changed the old "at most one emerging entry" test to expect both entries.
I also merged main, since #3742 landed; maxBodyChars now goes through fetchWindowSample.
…-one-tree # Conflicts: # packages/api/src/mcp/tools/query/runEventPatterns.ts
A cluster with a new variant only checked the rest of the cluster for disappeared, so a surge of the baseline message was dropped: two rows of a new message could hide a 50x increase of an existing one. Classify the rest in both directions; a cluster can now take two emerging entries, one per change.
| return; | ||
| const v = variants.get(key); | ||
| if (v) v.rows++; | ||
| else variants.set(key, { rows: 1, sample: raw }); |
There was a problem hiding this comment.
🟡 P2 — Different new messages in one baseline cluster merge into a single new_variant entry that shows only the first one's sample
variants is keyed by cluster id, and only the first row's body is kept as sample. Take a baseline of GET /api/cart 200 and a current window with 6× GET /api/cart 500 and 6× GET /api/cart 404: you get one entry with pattern GET /api/cart <*> and sample ...500, so the 404s are never shown. This is the same kind of hiding the PR set out to fix. Fix: key variants by cluster plus the masked token sequence (e.g. tokens.join(' ')), or keep several distinct samples per variant.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
There was a problem hiding this comment.
This is intentional: variants are counted per baseline cluster, so one cluster gives at most one new_variant entry. Keying by the masked tokens would give one entry per distinct value of any unmasked token (IDs, hostnames), which can flood emerging. The entry's pattern (GET /api/cart <*>) shows which token varies, the share counts all the new rows, and sample is one example.
Deep Review✅ No critical issues found. A full correctness trace confirmed the core algorithm is sound: 🟡 P2 — recommended
🔵 P3 nitpicks (9)
Reviewers (12): correctness, adversarial, testing, maintainability, project-standards, agent-native, learnings-researcher, performance, kieran-typescript, reliability, api-contract, previous-comments. Testing gaps:
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 |
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_signalsmines 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:
TemplateMiner, baseline first, and compares them by cluster id. The order is fixed, so the result doesn't depend on which query finishes first.user login failed: account lockedintouser 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 inemergingwithstatus: "new_variant",baselinePattern,variantShare, and the new line as its sample. Baseline clusters with fewer than 3 sampled rows are skipped.dateRangeEndInclusive: false), so a row at the boundary is counted once.Supporting changes:
minePatternstakes an optionalminerand returnsrowClusterIds(the cluster of each input row);TemplateMiner.tokenizereturns the masked tokens Drain compares.mineWindowPatternsis split intofetchWindowSample+mineWindowSampleand kept as a wrapper, soevent_patternsis 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:packages/api/src/mcp/__tests__/emergingSignalsOrder.test.tsfrom this PR.npx jest src/mcp/__tests__/emergingSignalsOrder.test.tsinpackages/api: it fails, becausemainhas nofetchWindowSample/mineWindowSampleand reports nonew_variant.On this branch:
emergingSignalsOrder.test.tspasses (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 indisappeared.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
emerging_signalsreports dated log lines as both "new" and "gone": Drain keeps the literal date, and each window is mined separately #3544