@@ -18,7 +18,12 @@ 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 {
22+ calculateCRC64 ,
23+ getFileSize ,
24+ parseAutoConfig ,
25+ validateAndNormalizePath ,
26+ } from '../../../utils' ;
2227import OSS from '../../../resources/oss' ;
2328import { setNodeModulesBinPermissions } from '../../../resources/fc/impl/utils' ;
2429
@@ -349,22 +354,33 @@ export default class Service extends Base {
349354 if ( slsAuto ) {
350355 const sls = new Sls ( region , credential as ICredentials ) ;
351356 const { project, logstore } = await sls . deploy ( ) ;
357+ const logAutoConfig = parseAutoConfig ( this . local . logConfig as string ) ;
358+ const logParams = logAutoConfig ?. params || { } ;
359+ const existingLogConfig =
360+ typeof this . local . logConfig === 'object' && this . local . logConfig !== null
361+ ? this . local . logConfig
362+ : { } ;
363+ const customFields : Record < string , any > = { ...existingLogConfig , ...logParams } ;
352364 logger . write (
353365 yellow ( `Created log resource succeeded, please replace logConfig: auto in yaml with:
354366logConfig:
355- enableInstanceMetrics: true
356- enableRequestMetrics: true
357- logBeginRule: DefaultRegex
367+ enableInstanceMetrics: ${ customFields . enableInstanceMetrics }
368+ enableRequestMetrics: ${ customFields . enableRequestMetrics }
369+ logBeginRule: ${ customFields . logBeginRule }
358370 logstore: ${ logstore }
359371 project: ${ project } \n` ) ,
360372 ) ;
373+
361374 this . createResource . sls = { project, logstore } ;
362375 _ . set ( this . local , 'logConfig' , {
363- enableInstanceMetrics : true ,
364- enableRequestMetrics : true ,
365- logBeginRule : 'DefaultRegex' ,
376+ enableInstanceMetrics :
377+ 'enableInstanceMetrics' in customFields ? customFields . enableInstanceMetrics : true ,
378+ enableRequestMetrics :
379+ 'enableRequestMetrics' in customFields ? customFields . enableRequestMetrics : true ,
380+ logBeginRule : 'logBeginRule' in customFields ? customFields . logBeginRule : 'DefaultRegex' ,
366381 logstore,
367382 project,
383+ ...customFields ,
368384 } ) ;
369385 }
370386
@@ -443,7 +459,12 @@ vpcConfig:
443459 _ . set ( this . local , 'vpcConfig' , vpcConfig ) ;
444460 }
445461 if ( nasAuto ) {
446- let serverAddr = `${ mountTargetDomain } :/${ functionName } ` ;
462+ const { params } = parseAutoConfig ( this . local . nasConfig as string ) ;
463+ const customMountDir = params . mountDir
464+ ? validateAndNormalizePath ( params . mountDir , 'mountDir' )
465+ : `/mnt/${ functionName } ` ;
466+ const customServerAddr = params . serverAddr ? params . serverAddr : `${ functionName } ` ;
467+ let serverAddr = `${ mountTargetDomain } :/${ customServerAddr } ` ;
447468 if ( serverAddr . length > 128 ) {
448469 serverAddr = serverAddr . substring ( 0 , 128 ) ;
449470 }
@@ -454,8 +475,9 @@ nasConfig:
454475 userId: 0
455476 mountPoints:
456477 - serverAddr: ${ serverAddr }
457- mountDir: /mnt/${ functionName }
458- enableTLS: false\n` ) ,
478+ mountDir: ${ customMountDir }
479+ enableTLS: false
480+ ` ) ,
459481 ) ;
460482 this . createResource . nas = { mountTargetDomain, fileSystemId } ;
461483 _ . set ( this . local , 'nasConfig' , {
@@ -464,7 +486,7 @@ nasConfig:
464486 mountPoints : [
465487 {
466488 serverAddr,
467- mountDir : `/mnt/ ${ functionName } ` ,
489+ mountDir : customMountDir ,
468490 enableTLS : false ,
469491 } ,
470492 ] ,
0 commit comments