Skip to content

Conversation

@pulpdrew
Copy link
Contributor

@pulpdrew pulpdrew commented Nov 7, 2025

Closes HDX-2728

Summary

This PR groups AlertHistory records by createdAt time to avoid showing multiple alert histories for the same time on the alerts page. There can be multiple AlertHistory records for the same createdAt time for grouped alerts

Testing

To test this, setup a Saved Search alert with a group by configured, then navigate to the alerts page to see one history per time:

Screenshot 2025-11-07 at 4 46 40 PM Screenshot 2025-11-07 at 4 46 30 PM

@changeset-bot
Copy link

changeset-bot bot commented Nov 7, 2025

🦋 Changeset detected

Latest commit: df32655

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

This PR includes changesets to release 2 packages
Name Type
@hyperdx/api Patch
@hyperdx/app 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
Copy link

vercel bot commented Nov 7, 2025

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

Project Deployment Preview Comments Updated (UTC)
hyperdx-v2-oss-app Ready Ready Preview Comment Nov 10, 2025 7:20pm

@claude
Copy link

claude bot commented Nov 7, 2025

PR Review

Overall assessment: Well-implemented feature with excellent test coverage. One minor issue to address.

Issues

  • ⚠️ Type mismatch in controller return type (packages/api/src/controllers/alertHistory.ts:23) → The function returns Omit<IAlertHistory, "alert">[] but the actual returned objects have createdAt as Date while the API response needs string. The frontend expects AlertHistory type from common-utils which has createdAt: string. Either update the return type to match the actual shape or ensure date serialization is handled correctly.

Strengths

  • Comprehensive test coverage with 12 test cases covering edge cases
  • Clean aggregation pipeline implementation
  • Proper state logic (ALERT takes precedence over OK)
  • Follows MongoDB aggregation patterns correctly

Minor observations (non-blocking)

  • Consider adding an index comment for the { alert: 1, createdAt: -1 } index in alertHistory.ts since this query pattern is now critical
  • The aggregation could potentially be optimized with $first for lastValues sorting, but current approach is clear and maintainable

@github-actions
Copy link
Contributor

github-actions bot commented Nov 7, 2025

E2E Test Results

All tests passed • 39 passed • 3 skipped • 312s

Status Count
✅ Passed 39
❌ Failed 0
⚠️ Flaky 0
⏭️ Skipped 3

View full report →

@pulpdrew pulpdrew force-pushed the drew/group-alert-histories branch from 8b2db33 to 5756505 Compare November 7, 2025 21:55
@pulpdrew pulpdrew requested review from a team and wrn14897 and removed request for a team November 7, 2025 22:05
Comment on lines 55 to 57
$replaceRoot: {
newRoot: '$docs',
},
Copy link
Member

Choose a reason for hiding this comment

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

any reason we don't want to do the aggregation on the db level? like computing isOk and all that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My only concern with that was potentially breaking the API by changing the response format, requiring us to coordinate fronted and backend deployment. I can probably keep the format similar enough to avoid issues though, so I will give that a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated 👍

Copy link
Member

@wrn14897 wrn14897 left a comment

Choose a reason for hiding this comment

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

Great fix!

@kodiakhq kodiakhq bot merged commit 78aff33 into main Nov 10, 2025
9 checks passed
@kodiakhq kodiakhq bot deleted the drew/group-alert-histories branch November 10, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants