Skip to content

Commit

Permalink
Update rate sheduler name (#8)
Browse files Browse the repository at this point in the history
* update name generation

* update readme

* update yml file

* stage commit

* add region, geolocation, update CF template to add policy to retrive data from s3 bucket, fix type

* updates based on comments

* update error message
  • Loading branch information
resdenia authored Feb 13, 2023
1 parent 49684ec commit 5f746dc
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 11 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ and then open [Logz.io](https://app.logz.io/#/dashboard/metrics).

## Changelong

1.1.5:

- Update sheduler name from static to dynamic

1.1.4:

- Update the playwright from 1.24.0 to 1.30.0

- Add dropdown UI for regions select

1.1.3:

- Update UI
Expand Down
1 change: 1 addition & 0 deletions client/src/page/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const Home: FunctionComponent = () => {
],
configs.bucketName.value,
configs.token.value,
region,
configs.listener.value,
(step: boolean) => {
onDownload(step);
Expand Down
3 changes: 2 additions & 1 deletion client/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Api {
return cloudBridgeEventResp;
}
};
downloadCFTemplate = async (codeSnippet: string, envList: object, name: string, rangeTime: number, bucket: string, token: string, listener: string, onDownload: (step: boolean) => void, description?: string) => {
downloadCFTemplate = async (codeSnippet: string, envList: object, name: string, rangeTime: number, bucket: string, token: string, region: string, listener: string, onDownload: (step: boolean) => void, description?: string) => {
onDownload(true)

const responseModify = await this.customFetch(
Expand All @@ -244,6 +244,7 @@ class Api {
token,
bucket,
listener,
region,
rangeTime
},
settings.endPointUrls.createCfZip,
Expand Down
13 changes: 11 additions & 2 deletions controllers/creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,16 @@ exports.modifyFileLocally = async (req, res) => {
};

exports.createZipCF = async (req, res) => {
const { envList, name, description, token, bucket, listener, rangeTime } =
req.body;
const {
envList,
name,
description,
token,
bucket,
listener,
region,
rangeTime,
} = req.body;

try {
await setupCFTemplate(
Expand All @@ -180,6 +188,7 @@ exports.createZipCF = async (req, res) => {
token,
bucket,
listener,
region,
rangeTime,
);
await fileToZipCF(name);
Expand Down
27 changes: 26 additions & 1 deletion service/cloudFormation/sam-template-empty.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Resources:
#add zipNameRoute
Key: string
Handler: index.handler
Role: 'dump'
Description: Lambda Function to run playwright test
#add name of the text
FunctionName: string
Expand All @@ -31,4 +32,28 @@ Resources:
Variables:
LISTENER_URL: string
TOKEN: string
NAME_FUNCTION: string
NAME_FUNCTION: string
syntheticQueryS3Bucket:
Type: 'AWS::IAM::Role'
Properties:
RoleName: 'dump'
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: 'dump'
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 's3:GetObject'
- 'lambda:GetFunction'
Resource: '*'
33 changes: 31 additions & 2 deletions service/cloudFormation/sam-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Parameters:
Type: "String"
Description: "AWS bucket where was uploaded lambdaFunction"

AWSRegion:
Type: "String"
Description: "AWS Region where was uploaded lambdaFunction"

ZipNameRoute:
Type: "String"
Description: "Zip route in AWS Bucket what was uploaded before"
Expand All @@ -39,17 +43,42 @@ Resources:
Handler: index.handler
Description: Lambda Function to run playwright test
FunctionName: !Ref LambdaTestName
Role: !GetAtt syntheticQueryS3Bucket.Arn
MemorySize: 512
Timeout: 60
Events:
CronEvent:
Type: Schedule
Properties:
Schedule: !Ref Timeout
Name: RateSchedule
Name: !Join [ '_', [ !Ref AWS::StackName, 'rateschudule' ] ]
Description: Trigger Lambda once in a minute
Environment:
Variables:
LISTENER_URL: !Ref LogzioListenerUrl
TOKEN: !Ref LogzioToken
NAME_FUNCTION: !Ref LambdaTestName
NAME_FUNCTION: !Ref LambdaTestName
REGION: !Ref AWSRegion
syntheticQueryS3Bucket:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Join [ '-', [ 'LogzioSyntheticMonitoringLambdaRole', !Select [ 4, !Split [ '-', !Select [ 2, !Split [ '/', !Ref AWS::StackId ] ] ] ] ] ]
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- s3.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
Policies:
- PolicyName: !Join [ '-', [ 'LogzioSyntheticMonitoringLambdaPolicy', !Select [ 4, !Split [ '-', !Select [ 2, !Split [ '/', !Ref AWS::StackId ] ] ] ] ] ]
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 's3:GetObject'
Resource: '*'
89 changes: 89 additions & 0 deletions service/lambdaFunction/geolocation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {
regionData: {
'us-east-1': {
geoip: {
location: [-78.024902, 37.926868],
},
},
'us-east-2': {
geoip: {
location: [-82.996216, 40.367474],
},
},
'us-west-1': {
geoip: {
location: [-119.417931, 36.778259],
},
},
'us-west-2': {
geoip: {
location: [-120.5, 44.0],
},
},
'ap-south-1': {
geoip: {
location: [72.877426, 19.07609],
},
},
'ap-northeast-3': {
geoip: {
location: [135.484802, 34.672314],
},
},
'ap-northeast-2': {
geoip: {
location: [127.024612, 37.5326],
},
},
'ap-southeast-1': {
geoip: {
location: [103.851959, 1.29027],
},
},
'ap-southeast-2': {
geoip: {
location: [151.2099, -33.865143],
},
},
'ap-northeast-1': {
geoip: {
location: [139.839478, 35.652832],
},
},
'ca-central-1': {
geoip: {
location: [-73.561668, 45.508888],
},
},
'eu-central-1': {
geoip: {
location: [8.682127, 50.110924],
},
},
'eu-west-1': {
geoip: {
location: [-6.266155, 53.35014],
},
},
'eu-west-2': {
geoip: {
location: [-0.118092, 51.509865],
},
},
'eu-west-3': {
geoip: {
location: [2.349014, 48.864716],
},
},
'eu-north-1': {
geoip: {
location: [18.06324, 59.334591],
},
},
'sa-east-1': {
geoip: {
location: [-46.62529, -23.533773],
},
},
},
};
8 changes: 6 additions & 2 deletions service/lambdaFunction/logger.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const loggerGenerator = () => {
const loggerGenerator = (regionData) => {
return require('logzio-nodejs').createLogger({
token: process.env.TOKEN,
protocol: 'https',
host: process.env.LISTENER_URL,
port: '8071',
type: 'syntetic-scripting', // OPTIONAL (If none is set, it will be 'nodejs')
type: 'synthetic-scripting', // OPTIONAL (If none is set, it will be 'nodejs')
sendIntervalMs: 1000,
extraFields: {
aws_region: process.env.REGION,
...regionData,
},
});
};
module.exports = loggerGenerator;
12 changes: 11 additions & 1 deletion service/lambdaFunction/rsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const convertHarToJSON = require('./convertHarToJSON');
const convertToNumber = require('./convertToNumber');
const readSendTraceData = require('./rsTraceData');
const loggerGenerator = require('./logger');
const { regionData } = require('./geolocation');
const errorStatusHandler = require('./statusError');
const createSessionId = require('./sessionId');
const createResponseStatusClass = require('./responseStatusClass');
Expand All @@ -12,7 +13,7 @@ function sleep(ms) {
}

const readSendData = async (error = '') => {
const logger = loggerGenerator();
const logger = loggerGenerator(regionData[process.env.REGION]);
const sessionId = createSessionId();
const status = errorStatusHandler(error);
const harsInDir = fs.readdirSync('/tmp');
Expand All @@ -22,6 +23,15 @@ const readSendData = async (error = '') => {
if (file.split('.').length > 1 && file.split('.')[1] === 'har') {
const fileData = fs.readFileSync(`/tmp/${file}`);
const json = JSON.parse(fileData.toString());
/*
* Log entries collect data for each test url,
* To prevent error for submitting test without url(first entry)
*/
if (!json.log.entries[0].request) {
throw new Error(
"The initial entry is missing. Please verify your test code and ensure that the first entry point (URL) is correctly specified. This is where you should start your end-to-end testing. For example: await page.goto('https://example.com')",
);
}
const firstEnterence = json.log.entries[0].request.url;

const parsedData = convertHarToJSON(json);
Expand Down
1 change: 1 addition & 0 deletions utils/lambda-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ exports.createLambda = async (
...variables,
TOKEN: token,
LISTENER_URL: listenerUrl,
REGION: region,
NAME_FUNCTION: functionName,
},
},
Expand Down
Loading

0 comments on commit 5f746dc

Please sign in to comment.