@@ -2311,6 +2311,7 @@ describe('External API v2 Dashboards - new format', () => {
23112311
23122312 it ( 'can round-trip all raw SQL chart config types' , async ( ) => {
23132313 const connectionId = connection . _id . toString ( ) ;
2314+ const sourceId = traceSource . _id . toString ( ) ;
23142315 const sqlTemplate = 'SELECT count() FROM otel_logs WHERE {timeFilter}' ;
23152316
23162317 const lineRawSql : ExternalDashboardTile = {
@@ -2324,6 +2325,7 @@ describe('External API v2 Dashboards - new format', () => {
23242325 displayType : 'line' ,
23252326 connectionId,
23262327 sqlTemplate,
2328+ sourceId,
23272329 compareToPreviousPeriod : true ,
23282330 fillNulls : true ,
23292331 alignDateRangeToGranularity : true ,
@@ -2342,6 +2344,7 @@ describe('External API v2 Dashboards - new format', () => {
23422344 displayType : 'stacked_bar' ,
23432345 connectionId,
23442346 sqlTemplate,
2347+ sourceId,
23452348 fillNulls : false ,
23462349 alignDateRangeToGranularity : false ,
23472350 numberFormat : { output : 'byte' , decimalBytes : true } ,
@@ -2359,6 +2362,7 @@ describe('External API v2 Dashboards - new format', () => {
23592362 displayType : 'table' ,
23602363 connectionId,
23612364 sqlTemplate,
2365+ sourceId,
23622366 numberFormat : { output : 'percent' , mantissa : 1 } ,
23632367 } ,
23642368 } ;
@@ -2374,6 +2378,7 @@ describe('External API v2 Dashboards - new format', () => {
23742378 displayType : 'number' ,
23752379 connectionId,
23762380 sqlTemplate,
2381+ sourceId,
23772382 numberFormat : { output : 'currency' , currencySymbol : '$' } ,
23782383 } ,
23792384 } ;
@@ -2389,6 +2394,7 @@ describe('External API v2 Dashboards - new format', () => {
23892394 displayType : 'pie' ,
23902395 connectionId,
23912396 sqlTemplate,
2397+ sourceId,
23922398 } ,
23932399 } ;
23942400
@@ -2457,6 +2463,43 @@ describe('External API v2 Dashboards - new format', () => {
24572463 } ) ;
24582464 } ) ;
24592465
2466+ it ( 'should return 400 when source connection does not match tile connection' , async ( ) => {
2467+ const otherConnection = await Connection . create ( {
2468+ team : team . _id ,
2469+ name : 'Other Connection' ,
2470+ host : config . CLICKHOUSE_HOST ,
2471+ username : config . CLICKHOUSE_USER ,
2472+ password : config . CLICKHOUSE_PASSWORD ,
2473+ } ) ;
2474+
2475+ const response = await authRequest ( 'post' , BASE_URL )
2476+ . send ( {
2477+ name : 'Dashboard with Mismatched Source Connection' ,
2478+ tiles : [
2479+ {
2480+ name : 'Raw SQL Tile' ,
2481+ x : 0 ,
2482+ y : 0 ,
2483+ w : 6 ,
2484+ h : 3 ,
2485+ config : {
2486+ configType : 'sql' ,
2487+ displayType : 'table' ,
2488+ connectionId : otherConnection . _id . toString ( ) ,
2489+ sourceId : traceSource . _id . toString ( ) ,
2490+ sqlTemplate : 'SELECT count() FROM otel_logs' ,
2491+ } ,
2492+ } ,
2493+ ] ,
2494+ tags : [ ] ,
2495+ } )
2496+ . expect ( 400 ) ;
2497+
2498+ expect ( response . body ) . toEqual ( {
2499+ message : `The following source IDs do not match the specified connections: ${ traceSource . _id . toString ( ) } ` ,
2500+ } ) ;
2501+ } ) ;
2502+
24602503 it ( 'should create a dashboard with filters' , async ( ) => {
24612504 const dashboardPayload = {
24622505 name : 'Dashboard with Filters' ,
@@ -3100,6 +3143,7 @@ describe('External API v2 Dashboards - new format', () => {
31003143
31013144 it ( 'can round-trip all raw SQL chart config types' , async ( ) => {
31023145 const connectionId = connection . _id . toString ( ) ;
3146+ const sourceId = traceSource . _id . toString ( ) ;
31033147 const sqlTemplate = 'SELECT count() FROM otel_logs WHERE {timeFilter}' ;
31043148
31053149 const lineRawSql : ExternalDashboardTileWithId = {
@@ -3114,6 +3158,7 @@ describe('External API v2 Dashboards - new format', () => {
31143158 displayType : 'line' ,
31153159 connectionId,
31163160 sqlTemplate,
3161+ sourceId,
31173162 compareToPreviousPeriod : true ,
31183163 fillNulls : true ,
31193164 alignDateRangeToGranularity : true ,
@@ -3133,6 +3178,7 @@ describe('External API v2 Dashboards - new format', () => {
31333178 displayType : 'stacked_bar' ,
31343179 connectionId,
31353180 sqlTemplate,
3181+ sourceId,
31363182 fillNulls : false ,
31373183 alignDateRangeToGranularity : false ,
31383184 numberFormat : { output : 'byte' , decimalBytes : true } ,
@@ -3151,6 +3197,7 @@ describe('External API v2 Dashboards - new format', () => {
31513197 displayType : 'table' ,
31523198 connectionId,
31533199 sqlTemplate,
3200+ sourceId,
31543201 numberFormat : { output : 'percent' , mantissa : 1 } ,
31553202 } ,
31563203 } ;
@@ -3167,6 +3214,7 @@ describe('External API v2 Dashboards - new format', () => {
31673214 displayType : 'number' ,
31683215 connectionId,
31693216 sqlTemplate,
3217+ sourceId,
31703218 numberFormat : { output : 'currency' , currencySymbol : '$' } ,
31713219 } ,
31723220 } ;
@@ -3183,6 +3231,7 @@ describe('External API v2 Dashboards - new format', () => {
31833231 displayType : 'pie' ,
31843232 connectionId,
31853233 sqlTemplate,
3234+ sourceId,
31863235 } ,
31873236 } ;
31883237
@@ -3271,6 +3320,45 @@ describe('External API v2 Dashboards - new format', () => {
32713320 } ) ;
32723321 } ) ;
32733322
3323+ it ( 'should return 400 when source connection does not match tile connection' , async ( ) => {
3324+ const dashboard = await createTestDashboard ( ) ;
3325+ const otherConnection = await Connection . create ( {
3326+ team : team . _id ,
3327+ name : 'Other Connection' ,
3328+ host : config . CLICKHOUSE_HOST ,
3329+ username : config . CLICKHOUSE_USER ,
3330+ password : config . CLICKHOUSE_PASSWORD ,
3331+ } ) ;
3332+
3333+ const response = await authRequest ( 'put' , `${ BASE_URL } /${ dashboard . _id } ` )
3334+ . send ( {
3335+ name : 'Updated Dashboard with Mismatched Source Connection' ,
3336+ tiles : [
3337+ {
3338+ id : new ObjectId ( ) . toString ( ) ,
3339+ name : 'Raw SQL Tile' ,
3340+ x : 0 ,
3341+ y : 0 ,
3342+ w : 6 ,
3343+ h : 3 ,
3344+ config : {
3345+ configType : 'sql' ,
3346+ displayType : 'table' ,
3347+ connectionId : otherConnection . _id . toString ( ) ,
3348+ sourceId : traceSource . _id . toString ( ) ,
3349+ sqlTemplate : 'SELECT count() FROM otel_logs' ,
3350+ } ,
3351+ } ,
3352+ ] ,
3353+ tags : [ ] ,
3354+ } )
3355+ . expect ( 400 ) ;
3356+
3357+ expect ( response . body ) . toEqual ( {
3358+ message : `The following source IDs do not match the specified connections: ${ traceSource . _id . toString ( ) } ` ,
3359+ } ) ;
3360+ } ) ;
3361+
32743362 it ( 'should delete alert when tile is updated from builder to raw SQL config' , async ( ) => {
32753363 const tileId = new ObjectId ( ) . toString ( ) ;
32763364 const dashboard = await createTestDashboard ( {
0 commit comments