Skip to content

Commit

Permalink
Fixed issue with shared s3 buckets (#221) (#222)
Browse files Browse the repository at this point in the history
- PPaasTestStatus.getAllStatus on the root s3 folder were finding tests from the shared subfolders on shared s3 buckets. It was then erroring when trying to load the status for those files
- Added export constant for the shared folder which can be overridden by SHARED_ENVIRONMENT_PREFIX env
- Added code to the getAllStatus function to ignore s3 keys that start with SHARED_ENVIRONMENT_PREFIX when our KEYSPACE_PREFIX is an empty string
  • Loading branch information
tkmcmaster authored May 10, 2024
1 parent a2cacaf commit d09a583
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/src/ppaasteststatus.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { LogLevel, log } from "./util/log";
import { TestStatus, TestStatusMessage } from "../types";
import {
KEYSPACE_PREFIX,
SHARED_ENVIRONMENT_PREFIX,
defaultTestFileTags,
getFileContents as getFileContentsS3,
getTags,
init as initS3,
listFiles,
uploadFileContents
} from "./util/s3";
import { LogLevel, log } from "./util/log";
import { TestStatus, TestStatusMessage } from "../types";
import PpaasTestId from "./ppaastestid";
import { _Object as S3Object } from "@aws-sdk/client-s3";

Expand Down Expand Up @@ -175,9 +177,17 @@ export class PpaasTestStatus implements TestStatusMessage {
s3File: S3Object;
contents: string | undefined;
}
const isSharedS3Environment: boolean = KEYSPACE_PREFIX.startsWith(SHARED_ENVIRONMENT_PREFIX);
const ppaasTestIds: TestIdContents[] = s3Files.map((s3File: S3Object) => {
try {
if (!s3File.Key) { return undefined; }
// Check if it's an /s3-environment/* and we're prefix ""
// Fixed Bug: We were having issues with non-dev environments finding the old runs from /s3-environment/*
// This code would then try to load those tests from the root and can't find them and would error
// If we're prefix "" then filter out tests that are under /s3-environment/*
if (!isSharedS3Environment && s3File.Key.startsWith(SHARED_ENVIRONMENT_PREFIX)) {
return undefined;
}
const testId: string = s3File.Key.slice(s3File.Key.lastIndexOf("/") + 1, s3File.Key.lastIndexOf("."));
log(`Parsed testId ${testId} from ${s3File.Key}`, LogLevel.DEBUG);
if (ignoreList && ignoreList.includes(testId)) {
Expand Down
1 change: 1 addition & 0 deletions common/src/util/s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type { S3File };
const gunzip = promisify(zlibGunzip);
const writeFile = promisify(fsWriteFile);

export const SHARED_ENVIRONMENT_PREFIX: string = process.env.SHARED_ENVIRONMENT_PREFIX || "s3-environment/";
export let BUCKET_NAME: string;
export let BUCKET_URL: string;
export let KEYSPACE_PREFIX: string;
Expand Down

0 comments on commit d09a583

Please sign in to comment.