@@ -74,7 +74,18 @@ export class ErrorAlertEvaluator {
7474 }
7575
7676 const allEnvTypes = this . collectEnvironmentTypes ( channels ) ;
77- const environments = await this . resolveEnvironments ( projectId , allEnvTypes ) ;
77+ const [ project , environments ] = await Promise . all ( [
78+ this . _replica . project . findFirst ( {
79+ where : { id : projectId } ,
80+ select : { organizationId : true } ,
81+ } ) ,
82+ this . resolveEnvironments ( projectId , allEnvTypes ) ,
83+ ] ) ;
84+
85+ if ( ! project ) {
86+ logger . error ( "[ErrorAlertEvaluator] Project not found" , { projectId } ) ;
87+ return ;
88+ }
7889
7990 if ( environments . length === 0 ) {
8091 logger . info ( "[ErrorAlertEvaluator] No matching environments found" , { projectId } ) ;
@@ -86,7 +97,12 @@ export class ErrorAlertEvaluator {
8697 const envMap = new Map ( environments . map ( ( e ) => [ e . id , e ] ) ) ;
8798 const channelsByEnvId = this . buildChannelsByEnvId ( channels , environments ) ;
8899
89- const activeErrors = await this . getActiveErrors ( projectId , envIds , scheduledAt ) ;
100+ const activeErrors = await this . getActiveErrors (
101+ project . organizationId ,
102+ projectId ,
103+ envIds ,
104+ scheduledAt
105+ ) ;
90106
91107 if ( activeErrors . length === 0 ) {
92108 await this . selfChain ( projectId , nextScheduledAt , minIntervalMs ) ;
@@ -96,7 +112,12 @@ export class ErrorAlertEvaluator {
96112 const states = await this . getErrorGroupStates ( activeErrors ) ;
97113 const stateMap = this . buildStateMap ( states ) ;
98114
99- const occurrenceCounts = await this . getOccurrenceCountsSince ( projectId , envIds , scheduledAt ) ;
115+ const occurrenceCounts = await this . getOccurrenceCountsSince (
116+ project . organizationId ,
117+ projectId ,
118+ envIds ,
119+ scheduledAt
120+ ) ;
100121 const occurrenceMap = this . buildOccurrenceMap ( occurrenceCounts ) ;
101122
102123 const alertableErrors : AlertableError [ ] = [ ] ;
@@ -301,11 +322,13 @@ export class ErrorAlertEvaluator {
301322 }
302323
303324 private async getActiveErrors (
325+ organizationId : string ,
304326 projectId : string ,
305327 envIds : string [ ] ,
306328 scheduledAt : number
307329 ) : Promise < ActiveErrorsSinceQueryResult [ ] > {
308330 const qb = this . _clickhouse . errors . activeErrorsSinceQueryBuilder ( ) ;
331+ qb . where ( "organization_id = {organizationId: String}" , { organizationId } ) ;
309332 qb . where ( "project_id = {projectId: String}" , { projectId } ) ;
310333 qb . where ( "environment_id IN {envIds: Array(String)}" , { envIds } ) ;
311334 qb . groupBy ( "environment_id, task_identifier, error_fingerprint" ) ;
@@ -346,6 +369,7 @@ export class ErrorAlertEvaluator {
346369 }
347370
348371 private async getOccurrenceCountsSince (
372+ organizationId : string ,
349373 projectId : string ,
350374 envIds : string [ ] ,
351375 scheduledAt : number
@@ -358,6 +382,7 @@ export class ErrorAlertEvaluator {
358382 } >
359383 > {
360384 const qb = this . _clickhouse . errors . occurrenceCountsSinceQueryBuilder ( ) ;
385+ qb . where ( "organization_id = {organizationId: String}" , { organizationId } ) ;
361386 qb . where ( "project_id = {projectId: String}" , { projectId } ) ;
362387 qb . where ( "environment_id IN {envIds: Array(String)}" , { envIds } ) ;
363388 qb . where ( "minute >= toStartOfMinute(fromUnixTimestamp64Milli({scheduledAt: Int64}))" , {
0 commit comments