Skip to content

Commit

Permalink
fix: log auto with free tier
Browse files Browse the repository at this point in the history
  • Loading branch information
rsonghuster committed Sep 15, 2024
1 parent 35ca0b6 commit cc3bdbd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
8 changes: 4 additions & 4 deletions __tests__/ut/resources_acr_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ describe('Sls', () => {
describe('generateProjectName', () => {
it('test generateProjectName', () => {
const region = 'cn-hangzhou';
const accessKeyId = 'accessKeyId';
const uid = 'uid';

const result = Sls.generateProjectName(region, accessKeyId);
expect(result).toEqual(`${accessKeyId}-${region}-project`);
const result = Sls.generateProjectName(region, uid);
expect(result).toEqual(`aliyun-serverless-uid-cn-hangzhou`);
});
});

describe('generateLogstoreName', () => {
it('test generateLogstoreName', () => {
const result = Sls.generateLogstoreName();

expect(result).toBe('function-logstore');
expect(result).toBe('default-logs');
});
});
});
Expand Down
47 changes: 38 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@alicloud/pop-core": "^1.7.13",
"@serverless-cd/srm-aliyun-pop-core": "^0.0.7-beta.16",
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
"@serverless-cd/srm-aliyun-sls20201230": "0.0.3-beta.2",
"@serverless-cd/srm-aliyun-sls20201230": "0.0.3-beta.7",
"@serverless-devs/diff": "^0.0.3-beta.6",
"@serverless-devs/downloads": "^0.0.6",
"@serverless-devs/load-component": "^0.0.8",
Expand Down Expand Up @@ -73,6 +73,9 @@
"resolutions": {
"@alicloud/devs20230714": {
"registry": "https://packages.aliyun.com/6455f7ff81b284e28f4774c4/npm/npm-registry/"
},
"@serverless-cd/srm-aliyun-sls20201230": {
"registry": "https://packages.aliyun.com/6455f7ff81b284e28f4774c4/npm/npm-registry/"
}
}
}
2 changes: 1 addition & 1 deletion src/default/resources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const defaultName = 'Alibaba-Fc-V3-Component-Generated';
export const VPC_AND_NAS_NAME = process.env.FC_GENERATE_VPC_AND_NAS_NAME || defaultName;

const defaultLogStoreName = 'function-logstore';
const defaultLogStoreName = 'default-logs';
export const PROJECT = process.env.FC_GENERATE_PROJECT_NAME;
export const LOG_STORE = process.env.FC_GENERATE_LOGSTORE_NAME || defaultLogStoreName;
16 changes: 6 additions & 10 deletions src/resources/sls/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@ import logger from '../../logger';

export default class Sls {
static generateProjectName = (region: IRegion, accountID: string): string =>
PROJECT || `${accountID}-${region}-project`;
PROJECT || `aliyun-serverless-${accountID}-${region}`;
static generateLogstoreName = (): string => {
// 3.0 仅创建一个 logstore
return LOG_STORE;
// // -20 是因为要抛去生成名称的前缀(fc-service-)和后缀(-logstore)
// if (name.length > 60 - 20) {
// const prefix = name.slice(0, 6).toLocaleLowerCase();
// const md5Uid = crypto.createHmac('md5', name).update(name).digest('hex');
// return `${prefix}-${md5Uid.slice(0, 7)}`;
// }

// return `fc-v3-${name}-logstore`.toLocaleLowerCase();
};

readonly client: Sls20201230;
Expand All @@ -31,6 +22,7 @@ export default class Sls {
securityToken: credentials.SecurityToken,
endpoint: `${region}.log.aliyuncs.com`,
userAgent: 'serverless-devs',
regionId: region,
});
this.client = new Sls20201230(config);
this.accountID = credentials.AccountID;
Expand All @@ -44,8 +36,12 @@ export default class Sls {
project,
logstore,
description: 'Generated by Aliyun fc3.x component',
accountID: this.accountID,
region: this.region,
});

logger.debug(`init sls: ${JSON.stringify(request)}`);

logger.spin(
'creating',
'sls',
Expand Down

0 comments on commit cc3bdbd

Please sign in to comment.