Skip to content

Commit

Permalink
Attempt to fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
haiqi96 committed Jan 17, 2025
1 parent ef7fd82 commit 518eec9
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -935,12 +935,16 @@ def start_log_viewer_webui(
s3_config = stream_storage.s3_config

settings_json_updates["StreamFilesS3Region"] = s3_config.region_code
settings_json_updates["StreamFilesS3PathPrefix"] = f"{s3_config.bucket}/{s3_config.key_prefix}"
settings_json_updates["StreamFilesS3PathPrefix"] = (
f"{s3_config.bucket}/{s3_config.key_prefix}"
)
access_key_id, secret_access_key = s3_config.get_credentials()
if access_key_id is not None and secret_access_key is not None:
stream_storage_env_vars = [
"-e", f"AWS_ACCESS_KEY_ID={access_key_id}",
"-e", f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
"-e",
f"AWS_ACCESS_KEY_ID={access_key_id}",
"-e",
f"AWS_SECRET_ACCESS_KEY={secret_access_key}",
]

settings_json = read_and_update_settings_json(settings_json_path, settings_json_updates)
Expand Down
67 changes: 48 additions & 19 deletions components/log-viewer-webui/server/src/routes/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,51 @@ const S3_MANAGER = (
new S3Manager(settings.StreamFilesS3Region);


/**
* Submits a stream extraction job and returns the metadata of the extracted stream
*
* @param {object} props
* @param {import("fastify").FastifyInstance | {dbManager: DbManager}} props.fastify
* @param {EXTRACT_JOB_TYPES} props.jobType
* @param {number} props.logEventIdx
* @param {string} props.streamId
* @param {import("fastify").FastifyReply} props.resp
* @return {Promise<object>} A promise that resolves to the extracted stream's metadata.
*/
const extractStreamAndGetMetadata = async ({
fastify,
jobType,
logEventIdx,
streamId,
resp,
}) => {
const extractResult = await fastify.dbManager.submitAndWaitForExtractStreamJob({
jobType: jobType,
logEventIdx: logEventIdx,
streamId: streamId,
targetUncompressedSize: settings.StreamTargetUncompressedSize,
});

if (null === extractResult) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("Unable to extract stream with " +
`streamId=${streamId} at logEventIdx=${logEventIdx}`);
}

const streamMetadata = fastify.dbManager.getExtractedStreamFileMetadata(
streamId,
logEventIdx
);

if (null === streamMetadata) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("Unable to find the metadata of extracted stream with " +
`streamId=${streamId} at logEventIdx=${logEventIdx}`);
}

return streamMetadata;
};

/**
* Creates query routes.
*
Expand Down Expand Up @@ -40,29 +85,13 @@ const routes = async (fastify, options) => {
);

if (null === streamMetadata) {
const extractResult = await fastify.dbManager.submitAndWaitForExtractStreamJob({
streamMetadata = await extractStreamAndGetMetadata({
fastify: fastify,
jobType: extractJobType,
logEventIdx: sanitizedLogEventIdx,
streamId: streamId,
targetUncompressedSize: settings.StreamTargetUncompressedSize,
resp: resp,
});

if (null === extractResult) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("Unable to extract stream with " +
`streamId=${streamId} at logEventIdx=${sanitizedLogEventIdx}`);
}

streamMetadata = await fastify.dbManager.getExtractedStreamFileMetadata(
streamId,
sanitizedLogEventIdx
);

if (null === streamMetadata) {
resp.code(StatusCodes.BAD_REQUEST);
throw new Error("Unable to find the metadata of extracted stream with " +
`streamId=${streamId} at logEventIdx=${sanitizedLogEventIdx}`);
}
}

if (null === S3_MANAGER) {
Expand Down

0 comments on commit 518eec9

Please sign in to comment.