Explorar o código

[clsi] prepare for non-representative clsiServerIds (#34546)

* [clsi] forward instanceType to web

* [clsi] expose zone in compile response

* [clsi-perf] add new fields for instanceType and zone

* [clsi] expose isPreEmptible flag in compile response

* [clsi-perf] also add isPreEmptible field

* [clsi] rename isPreEmptible -> isSpotInstance

GitOrigin-RevId: 2bc2d772e0b14da83afb51f5f3e4fefd3f60b733
Jakob Ackermann hai 1 mes
pai
achega
58970cd6ea

+ 3 - 0
services/clsi/app/js/CompileController.js

@@ -157,6 +157,9 @@ function compile(req, res, next) {
                 timings,
                 buildId,
                 clsiCacheShard,
+                instanceType: Settings.apis.clsi.instanceType,
+                zone: Settings.apis.clsi.zone,
+                isSpotInstance: Settings.apis.clsi.isSpotInstance,
                 outputUrlPrefix: Settings.apis.clsi.outputUrlPrefix,
                 outputFiles: outputFiles.map(file => ({
                   url:

+ 5 - 2
services/clsi/config/settings.defaults.cjs

@@ -2,7 +2,7 @@ const Path = require('node:path')
 const os = require('node:os')
 const fs = require('node:fs')
 
-const isPreEmptible = process.env.PREEMPTIBLE === 'TRUE'
+const isSpotInstance = process.env.PREEMPTIBLE === 'TRUE'
 const CLSI_SERVER_ID = os.hostname().replace('-ctr', '')
 
 module.exports = {
@@ -59,6 +59,9 @@ module.exports = {
       // External url prefix for output files, e.g. for requests via load-balancers.
       outputUrlPrefix: `${process.env.ZONE ? `/zone/${process.env.ZONE}` : ''}`,
       clsiServerId: process.env.CLSI_SERVER_ID || CLSI_SERVER_ID,
+      instanceType: process.env.INSTANCE_TYPE,
+      zone: process.env.ZONE,
+      isSpotInstance,
 
       downloadHost: process.env.DOWNLOAD_HOST || 'http://localhost:8080',
     },
@@ -104,7 +107,7 @@ module.exports = {
     parseInt(process.env.PDF_CACHING_WORKER_POOL_SIZE, 10) || 4,
   pdfCachingWorkerPoolBackLogLimit:
     parseInt(process.env.PDF_CACHING_WORKER_POOL_BACK_LOG_LIMIT, 10) || 40,
-  compileConcurrencyLimit: isPreEmptible ? 32 : 64,
+  compileConcurrencyLimit: isSpotInstance ? 32 : 64,
   performanceLogSamplingPercentage:
     parseFloat(process.env.CLSI_PERFORMANCE_LOG_SAMPLING, 10) || 0,
 }

+ 27 - 0
services/clsi/test/unit/js/CompileController.test.js

@@ -25,6 +25,9 @@ describe('CompileController', () => {
           clsi: {
             url: 'http://clsi.example.com',
             outputUrlPrefix: '/zone/b',
+            instanceType: 'c4d',
+            zone: 'b',
+            isSpotInstance: true,
             downloadHost: 'http://localhost:3013',
           },
           clsiCache: {
@@ -149,6 +152,9 @@ describe('CompileController', () => {
               })),
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)
@@ -178,6 +184,9 @@ describe('CompileController', () => {
               })),
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)
@@ -227,6 +236,9 @@ describe('CompileController', () => {
             })),
             clsiCacheShard: undefined,
             baseHistoryVersion: undefined,
+            instanceType: 'c4d',
+            zone: 'b',
+            isSpotInstance: true,
           },
         })
       })
@@ -276,6 +288,9 @@ describe('CompileController', () => {
             })),
             clsiCacheShard: undefined,
             baseHistoryVersion: undefined,
+            instanceType: 'c4d',
+            zone: 'b',
+            isSpotInstance: true,
           },
         })
       })
@@ -309,6 +324,9 @@ describe('CompileController', () => {
               timings: ctx.timings,
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)
@@ -345,6 +363,9 @@ describe('CompileController', () => {
               buildId: undefined,
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)
@@ -380,6 +401,9 @@ describe('CompileController', () => {
               buildId: undefined,
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)
@@ -413,6 +437,9 @@ describe('CompileController', () => {
               buildId: undefined,
               clsiCacheShard: undefined,
               baseHistoryVersion: undefined,
+              instanceType: 'c4d',
+              zone: 'b',
+              isSpotInstance: true,
             },
           })
           .should.equal(true)

+ 2 - 0
services/web/app/src/Features/Compile/ClsiManager.mjs

@@ -334,6 +334,7 @@ async function _sendBuiltRequest(projectId, userId, req, options) {
     outputUrlPrefix: compile.outputUrlPrefix,
     clsiCacheShard: compile.clsiCacheShard,
     baseHistoryVersion: compile.baseHistoryVersion,
+    instanceType: compile.instanceType,
   }
 }
 
@@ -1287,6 +1288,7 @@ export default {
     'outputUrlPrefix',
     'buildId',
     'clsiCacheShard',
+    'instanceType',
   ]),
   sendExternalRequest: callbackifyMultiResult(sendExternalRequest, [
     'status',

+ 9 - 1
services/web/app/src/Features/Compile/CompileController.mjs

@@ -228,6 +228,7 @@ const _CompileController = {
       outputUrlPrefix,
       buildId,
       clsiCacheShard,
+      instanceType,
     } = await CompileManager.promises
       .compile(projectId, userId, options)
       .catch(error => {
@@ -261,8 +262,15 @@ const _CompileController = {
           status,
           compileTime: timings?.compileE2E,
           timeout: limits.timeout,
-          server: clsiServerId?.includes('-c4d-') ? 'faster' : 'normal',
+          server: instanceType
+            ? instanceType === 'c4d'
+              ? 'faster'
+              : 'normal'
+            : clsiServerId?.includes('-c4d-')
+              ? 'faster'
+              : 'normal',
           clsiServerId,
+          instanceType,
           isAutoCompile,
           isInitialCompile: stats?.isInitialCompile === 1,
           restoredClsiCache: stats?.restoredClsiCache === 1,

+ 3 - 0
services/web/app/src/Features/Compile/CompileManager.mjs

@@ -98,6 +98,7 @@ async function compile(projectId, userId, options = {}) {
     buildId,
     clsiCacheShard,
     baseHistoryVersion,
+    instanceType,
   } = await ClsiManager.promises.sendRequest(projectId, compileAsUser, options)
 
   return {
@@ -112,6 +113,7 @@ async function compile(projectId, userId, options = {}) {
     buildId,
     clsiCacheShard,
     baseHistoryVersion,
+    instanceType,
   }
 }
 
@@ -243,6 +245,7 @@ export default CompileManager = {
     'outputUrlPrefix',
     'buildId',
     'clsiCacheShard',
+    'instanceType',
   ]),
 
   stopCompile: callbackify(stopCompile),