Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TES-417] The session log could not be pushed to TestOps #163

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/config/transports.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
const _ = require('lodash');
const path = require('path');
const moment = require('moment');
const TransportStream = require('winston-transport');

const { generateUuid } = require('../helper/agent');
const api = require('../core/api');

class S3FileTransport extends TransportStream {
constructor(options = {}, afterLog) {
super(options);
this.jobInfo = options.jobInfo;
this.apiKey = options.apiKey;
this.filePath = options.filePath;
this.signedUrl = options.signedUrl;
this.parentLogger = options.logger;
Expand All @@ -18,6 +23,33 @@ class S3FileTransport extends TransportStream {
}

uploadToS3() {
const parsedUrl = new URL(this.signedUrl);
const params = new URLSearchParams(parsedUrl.search);

const amzDate = params.get('X-Amz-Date');
const amzExpires = params.get('X-Amz-Expires');

const dateFormart = 'YYYYMMDDTHHmmss[Z]';
const dateExpires = moment.utc(amzDate, dateFormart).toDate();
dateExpires.setSeconds(dateExpires.getSeconds(), amzExpires * 1000);

const now = new Date();
if (dateExpires < now) {
const requestGetUploadInfo = async () => {
const response = await api.getUploadInfo(this.jobInfo.projectId, this.apiKey);
if (!response || !response.body) {
return null;
}
const { body } = response;
const { uploadUrl } = body;
this.signedUrl = uploadUrl;
const batch = generateUuid();
const fileName = path.basename(this.filePath);
return api.saveJobLog(this.jobInfo, batch, fileName, this.apiKey);
};
requestGetUploadInfo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need 'await' here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added await for requestGetUploadInfo(); Thank you.

}

return api
.uploadFile(this.signedUrl, this.filePath)
.then(() => this.afterLog && this.afterLog())
Expand Down
2 changes: 2 additions & 0 deletions src/service/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
const uploadPath = body.path;

if (jobInfo.uploadPath) {
jobInfo.oldUploadPath = jobInfo.uploadPath;

Check warning on line 50 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'

Check warning on line 50 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'
}

jobInfo.uploadUrl = uploadUrl;

Check warning on line 53 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'

Check warning on line 53 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'
jobInfo.uploadPath = uploadPath;

Check warning on line 54 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'

Check warning on line 54 in src/service/agent.js

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'jobInfo'

await api.uploadFile(uploadUrl, filePath);

Expand Down Expand Up @@ -156,6 +156,8 @@
jLogger.add(
new S3FileTransport(
{
jobInfo,
apiKey,
filePath: logFilePath,
signedUrl: jobInfo.uploadUrl,
logger,
Expand Down
Loading