@@ -18,7 +18,7 @@ import FC, { GetApiType } from '../../../resources/fc';
1818import VPC_NAS from '../../../resources/vpc-nas' ;
1919import Base from './base' ;
2020import { ICredentials } from '@serverless-devs/component-interface' ;
21- import { calculateCRC64 , getFileSize } from '../../../utils' ;
21+ import { calculateCRC64 , getFileSize , parseAutoConfig , checkFcDir } from '../../../utils' ;
2222import OSS from '../../../resources/oss' ;
2323import { setNodeModulesBinPermissions } from '../../../resources/fc/impl/utils' ;
2424
@@ -349,22 +349,30 @@ export default class Service extends Base {
349349 if ( slsAuto ) {
350350 const sls = new Sls ( region , credential as ICredentials ) ;
351351 const { project, logstore } = await sls . deploy ( ) ;
352+ const logAutoConfig = parseAutoConfig ( this . local . logConfig as string ) ;
353+ const logParams = logAutoConfig ?. params || { } ;
354+ const customFields : Record < string , any > = { ...logParams } ;
355+ const getConfigValue = ( field : string , defaultValue : any ) => {
356+ return field in customFields ? customFields [ field ] : defaultValue ;
357+ } ;
352358 logger . write (
353359 yellow ( `Created log resource succeeded, please replace logConfig: auto in yaml with:
354360logConfig:
355- enableInstanceMetrics: true
356- enableRequestMetrics: true
357- logBeginRule: DefaultRegex
361+ enableInstanceMetrics: ${ getConfigValue ( 'enableInstanceMetrics' , true ) }
362+ enableRequestMetrics: ${ getConfigValue ( 'enableRequestMetrics' , true ) }
363+ logBeginRule: ${ getConfigValue ( 'logBeginRule' , ' DefaultRegex' ) }
358364 logstore: ${ logstore }
359365 project: ${ project } \n` ) ,
360366 ) ;
367+
361368 this . createResource . sls = { project, logstore } ;
362369 _ . set ( this . local , 'logConfig' , {
363- enableInstanceMetrics : true ,
364- enableRequestMetrics : true ,
365- logBeginRule : ' DefaultRegex',
370+ enableInstanceMetrics : getConfigValue ( 'enableInstanceMetrics' , true ) ,
371+ enableRequestMetrics : getConfigValue ( 'enableRequestMetrics' , true ) ,
372+ logBeginRule : getConfigValue ( 'logBeginRule' , ' DefaultRegex') ,
366373 logstore,
367374 project,
375+ ...customFields ,
368376 } ) ;
369377 }
370378
@@ -443,7 +451,15 @@ vpcConfig:
443451 _ . set ( this . local , 'vpcConfig' , vpcConfig ) ;
444452 }
445453 if ( nasAuto ) {
446- let serverAddr = `${ mountTargetDomain } :/${ functionName } ` ;
454+ const { params } = parseAutoConfig ( this . local . nasConfig as string ) ;
455+ const fcDir = params . mountDir
456+ ? checkFcDir ( params . mountDir , 'mountDir' )
457+ : `/mnt/${ functionName } ` ;
458+ if ( params . nasDir && ! params . nasDir . startsWith ( '/' ) ) {
459+ throw new Error ( 'nasDir must start with /' ) ;
460+ }
461+ const nasDir = params . nasDir ? params . nasDir : `/${ functionName } ` ;
462+ let serverAddr = `${ mountTargetDomain } :${ nasDir } ` ;
447463 if ( serverAddr . length > 128 ) {
448464 serverAddr = serverAddr . substring ( 0 , 128 ) ;
449465 }
@@ -454,8 +470,9 @@ nasConfig:
454470 userId: 0
455471 mountPoints:
456472 - serverAddr: ${ serverAddr }
457- mountDir: /mnt/${ functionName }
458- enableTLS: false\n` ) ,
473+ mountDir: ${ fcDir }
474+ enableTLS: false
475+ ` ) ,
459476 ) ;
460477 this . createResource . nas = { mountTargetDomain, fileSystemId } ;
461478 _ . set ( this . local , 'nasConfig' , {
@@ -464,7 +481,7 @@ nasConfig:
464481 mountPoints : [
465482 {
466483 serverAddr,
467- mountDir : `/mnt/ ${ functionName } ` ,
484+ mountDir : fcDir ,
468485 enableTLS : false ,
469486 } ,
470487 ] ,
0 commit comments