Skip to content

Commit c216053

Browse files
authored
feat: group tasks by connection (#1071)
Group the alert tasks fetched from mongo into groups based on what needs to run from the same connection. This sets up for further optimizations and connection reuse.
1 parent adb05ac commit c216053

File tree

11 files changed

+1177
-191
lines changed

11 files changed

+1177
-191
lines changed

.changeset/ninety-books-hear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/api": patch
3+
---
4+
5+
Changes the order of alert evaluation to group queries by the connection on the alert.

packages/api/src/controllers/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ export function getConnectionById(
1818

1919
export function createConnection(
2020
team: string,
21-
connection: Omit<IConnection, '_id'>,
21+
connection: Omit<IConnection, 'id' | '_id'>,
2222
) {
2323
return Connection.create({ ...connection, team });
2424
}
2525

2626
export function updateConnection(
2727
team: string,
2828
connectionId: string,
29-
connection: Omit<IConnection, '_id'>,
29+
connection: Omit<IConnection, 'id' | '_id'>,
3030
) {
3131
return Connection.findOneAndUpdate({ _id: connectionId, team }, connection, {
3232
new: true,

packages/api/src/controllers/savedSearch.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ export async function getSavedSearches(teamId: string) {
2121
return savedSearches.map(savedSearch => ({
2222
...savedSearch.toJSON(),
2323
alerts: alertsBySavedSearchId[savedSearch._id.toString()]?.map(alert => {
24-
const { _id, ...restAlert } = alert.toJSON();
25-
return { id: _id, ...restAlert };
24+
return alert.toJSON();
2625
}),
2726
}));
2827
}

packages/api/src/models/alert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export enum AlertSource {
4141
}
4242

4343
export interface IAlert {
44-
_id: ObjectId;
44+
id: string;
4545
channel: AlertChannel;
4646
interval: AlertInterval;
4747
source?: AlertSource;
@@ -162,6 +162,7 @@ const AlertSchema = new Schema<IAlert>(
162162
},
163163
{
164164
timestamps: true,
165+
toJSON: { virtuals: true },
165166
},
166167
);
167168

packages/api/src/models/connection.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type ObjectId = mongoose.Types.ObjectId;
55

66
export interface IConnection {
77
_id: ObjectId;
8+
id: string;
89
host: string;
910
name: string;
1011
password: string;

0 commit comments

Comments
 (0)