Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

DEVPROD-1435: Use renderingType GQL field to determine Row rendering format #497

Merged
merged 24 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions cypress/integration/external_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ describe("External Links", () => {
cy.dataCy("raw-log-button").should(
"have.attr",
"href",
"http://localhost:9090/test_log/spruce_ubuntu1604_check_codegen_d54e2c6ede60e004c48d3c4d996c59579c7bbd1f_22_03_02_15_41_35/0?test_name=JustAFakeTestInALonelyWorld&group_id=&text=true",
"http://localhost:9090/rest/v2/tasks/spruce_ubuntu1604_check_codegen_d54e2c6ede60e004c48d3c4d996c59579c7bbd1f_22_03_02_15_41_35/build/TestLogs/JustAFakeTestInALonelyWorld?execution=0&print_time=true",
);
cy.dataCy("html-log-button").should("be.visible");
cy.dataCy("html-log-button").should("not.be.disabled");
cy.dataCy("html-log-button").should(
"have.attr",
"href",
"http://localhost:9090/test_log/spruce_ubuntu1604_check_codegen_d54e2c6ede60e004c48d3c4d996c59579c7bbd1f_22_03_02_15_41_35/0?test_name=JustAFakeTestInALonelyWorld&group_id=#L0",
"http://localhost:9090/test_log/spruce_ubuntu1604_check_codegen_d54e2c6ede60e004c48d3c4d996c59579c7bbd1f_22_03_02_15_41_35/0?test_name=JustAFakeTestInALonelyWorld#L0",
);
});
});
Expand Down
26 changes: 17 additions & 9 deletions src/components/LogRow/RowRenderer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LogTypes } from "constants/enums";
import { LogRenderingTypes, LogTypes } from "constants/enums";
import { useLogContext } from "context/LogContext";
import { useHighlightParam } from "hooks/useHighlightParam";
import { ProcessedLogLines } from "types/logs";
Expand All @@ -17,6 +17,7 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
expandLines,
getLine,
getResmokeLineColor,
logMetadata,
preferences,
range,
scrollToLine,
Expand All @@ -38,6 +39,20 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
? new RegExp(`${highlights.map((h) => `(${h})`).join("|")}`, "gi")
: undefined;

let Row: typeof ResmokeRow | typeof AnsiRow;
// At this point, logMetadata.renderingType is guaranteed to be defined from <LoadingPage />
switch (logMetadata?.renderingType) {
case LogRenderingTypes.Resmoke:
Row = ResmokeRow;
break;
case LogRenderingTypes.Default:
Row = AnsiRow;
break;
default:
Row = AnsiRow;
break;
}

const result = (index: number) => {
const processedLogLine = processedLogLines[index];
if (isCollapsedRow(processedLogLine)) {
Expand All @@ -49,7 +64,7 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
/>
);
}
const Row = rowRendererMap[logType];

return (
<Row
getLine={getLine}
Expand All @@ -72,11 +87,4 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
return result;
};

const rowRendererMap = {
[LogTypes.EVERGREEN_TASK_FILE]: AnsiRow,
[LogTypes.EVERGREEN_TASK_LOGS]: AnsiRow,
[LogTypes.EVERGREEN_TEST_LOGS]: AnsiRow,
[LogTypes.RESMOKE_LOGS]: ResmokeRow,
};

export { ParsleyRow };
8 changes: 7 additions & 1 deletion src/constants/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ enum LogTypes {
RESMOKE_LOGS = "RESMOKE_LOGS",
}

enum LogRenderingTypes {
Default = "default",
Resmoke = "resmoke",
}

enum CaseSensitivity {
Sensitive = "sensitive",
Insensitive = "insensitive",
Expand Down Expand Up @@ -33,8 +38,9 @@ enum WordWrapFormat {
export {
CaseSensitivity,
FilterLogic,
WordWrapFormat,
LogRenderingTypes,
LogTypes,
MatchType,
SearchBarActions,
WordWrapFormat,
};
17 changes: 9 additions & 8 deletions src/context/LogContext/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ interface SearchState {
}

interface LogMetadata {
logType?: LogTypes;
fileName?: string;
taskID?: string;
execution?: string;
testID?: string;
buildID?: string;
origin?: string;
execution?: string;
fileName?: string;
htmlLogURL?: string;
rawLogURL?: string;
isUploadedLog?: boolean;
jobLogsURL?: string;
legacyJobLogsURL?: string;
isUploadedLog?: boolean;
logType?: LogTypes;
origin?: string;
rawLogURL?: string;
renderingType?: string;
taskID?: string;
testID?: string;
}

interface Preferences {
Expand Down
8 changes: 6 additions & 2 deletions src/gql/generated/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2910,6 +2910,7 @@ export type User = {
__typename?: "User";
displayName: Scalars["String"]["output"];
emailAddress: Scalars["String"]["output"];
parsleyFilters: Array<ParsleyFilter>;
patches: Patches;
permissions: Permissions;
subscriptions?: Maybe<Array<GeneralSubscription>>;
Expand Down Expand Up @@ -2949,6 +2950,7 @@ export type UserSettings = {
region?: Maybe<Scalars["String"]["output"]>;
slackMemberId?: Maybe<Scalars["String"]["output"]>;
slackUsername?: Maybe<Scalars["String"]["output"]>;
timeFormat?: Maybe<Scalars["String"]["output"]>;
timezone?: Maybe<Scalars["String"]["output"]>;
useSpruceOptions?: Maybe<UseSpruceOptions>;
};
Expand All @@ -2964,6 +2966,7 @@ export type UserSettingsInput = {
region?: InputMaybe<Scalars["String"]["input"]>;
slackMemberId?: InputMaybe<Scalars["String"]["input"]>;
slackUsername?: InputMaybe<Scalars["String"]["input"]>;
timeFormat?: InputMaybe<Scalars["String"]["input"]>;
timezone?: InputMaybe<Scalars["String"]["input"]>;
useSpruceOptions?: InputMaybe<UseSpruceOptionsInput>;
};
Expand Down Expand Up @@ -3241,13 +3244,13 @@ export type TaskQuery = {
} | null;
};

export type TestLogUrlQueryVariables = Exact<{
export type TestLogUrlAndRenderingTypeQueryVariables = Exact<{
taskID: Scalars["String"]["input"];
testName: Scalars["String"]["input"];
execution: Scalars["Int"]["input"];
}>;

export type TestLogUrlQuery = {
export type TestLogUrlAndRenderingTypeQuery = {
__typename?: "Query";
task?: {
__typename?: "Task";
Expand All @@ -3259,6 +3262,7 @@ export type TestLogUrlQuery = {
id: string;
logs: {
__typename?: "TestLog";
renderingType?: string | null;
url?: string | null;
urlRaw?: string | null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
query TestLogURL($taskID: String!, $testName: String!, $execution: Int!) {
query TestLogURLAndRenderingType(
$taskID: String!
$testName: String!
$execution: Int!
) {
task(taskId: $taskID, execution: $execution) {
id
tests(opts: { testName: $testName, excludeDisplayNames: true }) {
testResults {
id
logs {
renderingType
url
urlRaw
}
Expand Down
4 changes: 2 additions & 2 deletions src/gql/queries/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import GET_LOGKEEPER_TASK from "./get-logkeeper-task.graphql";
import GET_TASK from "./get-task.graphql";
import GET_TEST_LOG_URL from "./get-test-log-url.graphql";
import GET_TEST_LOG_URL_AND_RENDERING_TYPE from "./get-test-log-url-and-rendering-type.graphql";
import GET_USER from "./get-user.graphql";
import PROJECT_FILTERS from "./project-filters.graphql";
import TASK_FILES from "./task-files.graphql";

export {
GET_LOGKEEPER_TASK,
GET_TASK,
GET_TEST_LOG_URL,
GET_TEST_LOG_URL_AND_RENDERING_TYPE,
GET_USER,
PROJECT_FILTERS,
TASK_FILES,
Expand Down
16 changes: 12 additions & 4 deletions src/pages/LogDrop/FileDropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from "@emotion/styled";
import { palette } from "@leafygreen-ui/palette";
import { useDropzone } from "react-dropzone";
import { useLogDropAnalytics } from "analytics";
import { LogTypes } from "constants/enums";
import { LogRenderingTypes, LogTypes } from "constants/enums";
import { LOG_LINE_TOO_LARGE_WARNING } from "constants/errors";
import { LOG_FILE_SIZE_LIMIT, LOG_LINE_SIZE_LIMIT } from "constants/logs";
import { size } from "constants/tokens";
Expand Down Expand Up @@ -40,9 +40,17 @@ const FileDropper: React.FC = () => {
);

const onParse = useCallback(
(logType: LogTypes | undefined) => {
if (logType) {
setLogMetadata({ isUploadedLog: true, logType });
(renderingType: LogRenderingTypes | undefined) => {
if (renderingType) {
const logType =
renderingType === LogRenderingTypes.Resmoke
? LogTypes.RESMOKE_LOGS
: LogTypes.EVERGREEN_TASK_LOGS;
setLogMetadata({
isUploadedLog: true,
logType,
renderingType,
});
leaveBreadcrumb("Parsing file", { logType }, SentryBreadcrumb.UI);
dispatch({ type: "PARSE_FILE" });
startTransition(() => {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/LogDrop/ParseLogSelect/ParseLogSelect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Cookie from "js-cookie";
import { LogTypes } from "constants/enums";
import { LogRenderingTypes, LogTypes } from "constants/enums";
import { renderWithRouterMatch as render, screen, userEvent } from "test_utils";
import ParseLogSelect from ".";

Expand All @@ -24,7 +24,7 @@ describe("parse log select", () => {
});

it("defaults to 'Raw' option if cookie is set to evergreen logs", () => {
mockedGet.mockImplementation(() => LogTypes.EVERGREEN_TASK_LOGS);
mockedGet.mockImplementation(() => LogRenderingTypes.Default);
render(
<ParseLogSelect
fileName="filename.txt"
Expand All @@ -37,7 +37,7 @@ describe("parse log select", () => {
});

it("defaults to 'Resmoke' option if cookie is set to resmoke logs", () => {
mockedGet.mockImplementation(() => LogTypes.RESMOKE_LOGS);
mockedGet.mockImplementation(() => LogRenderingTypes.Resmoke);
render(
<ParseLogSelect
fileName="filename.txt"
Expand Down
19 changes: 12 additions & 7 deletions src/pages/LogDrop/ParseLogSelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ import { Option, Select } from "@leafygreen-ui/select";
import { InlineCode, InlineCodeProps, Label } from "@leafygreen-ui/typography";
import Cookie from "js-cookie";
import { LAST_SELECTED_LOG_TYPE } from "constants/cookies";
import { LogTypes } from "constants/enums";
import { LogRenderingTypes } from "constants/enums";
import { size } from "constants/tokens";

interface ParseLogSelectProps {
fileName: string | undefined;
onParse: (logType: LogTypes | undefined) => void;
onParse: (logType: LogRenderingTypes | undefined) => void;
onCancel: () => void;
}

type SelectState =
| LogRenderingTypes.Resmoke
| LogRenderingTypes.Default
| undefined;

const ParseLogSelect: React.FC<ParseLogSelectProps> = ({
fileName,
onCancel,
onParse,
}) => {
const [logType, setLogType] = useState<LogTypes | undefined>(
(Cookie.get(LAST_SELECTED_LOG_TYPE) as LogTypes) ?? undefined,
const [logType, setLogType] = useState<SelectState>(
(Cookie.get(LAST_SELECTED_LOG_TYPE) as SelectState) ?? undefined,
);

return (
Expand All @@ -34,13 +39,13 @@ const ParseLogSelect: React.FC<ParseLogSelectProps> = ({
data-cy="parse-log-select"
onChange={(value) => {
Cookie.set(LAST_SELECTED_LOG_TYPE, value, { expires: 365 });
setLogType(value as LogTypes);
setLogType(value as SelectState);
}}
placeholder="Select..."
value={logType ?? ""}
>
<Option value={LogTypes.RESMOKE_LOGS}>Resmoke</Option>
<Option value={LogTypes.EVERGREEN_TASK_LOGS}>Raw</Option>
<Option value={LogRenderingTypes.Resmoke}>Resmoke</Option>
<Option value={LogRenderingTypes.Default}>Raw</Option>
</Select>
<ButtonContainer>
<Button onClick={onCancel}>Cancel</Button>
Expand Down
31 changes: 17 additions & 14 deletions src/pages/LogView/LoadingPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import NotFound from "pages/404";
import { LogkeeperMetadata } from "types/api";
import { SentryBreadcrumb, leaveBreadcrumb } from "utils/errorReporting";
import { getBytesAsString } from "utils/string";
import { useResolveLogURL } from "./useResolveLogURL";
import { useResolveLogURLAndRenderingType } from "./useResolveLogURLAndRenderingType";

interface LoadingPageProps {
logType: LogTypes;
Expand All @@ -41,7 +41,8 @@ const LoadingPage: React.FC<LoadingPageProps> = ({ logType }) => {
legacyJobLogsURL,
loading: isLoadingEvergreen,
rawLogURL,
} = useResolveLogURL({
renderingType,
} = useResolveLogURLAndRenderingType({
buildID,
execution,
fileName,
Expand Down Expand Up @@ -83,6 +84,7 @@ const LoadingPage: React.FC<LoadingPageProps> = ({ logType }) => {
logType,
origin,
rawLogURL,
renderingType,
taskID: taskID || logkeeperMetadata?.task_id,
testID,
});
Expand All @@ -92,25 +94,26 @@ const LoadingPage: React.FC<LoadingPageProps> = ({ logType }) => {
dispatchToast.error(error);
}
}, [
buildID,
data,
ingestLines,
error,
logType,
isLoadingLogkeeperMetadata,
dispatchToast,
setLogMetadata,
taskID,
error,
execution,
testID,
origin,
buildID,
rawLogURL,
fileName,
htmlLogURL,
ingestLines,
isLoadingLogkeeperMetadata,
jobLogsURL,
legacyJobLogsURL,
fileName,
logkeeperMetadata?.task_id,
logkeeperMetadata?.execution,
logkeeperMetadata?.task_id,
logType,
origin,
rawLogURL,
renderingType,
setLogMetadata,
taskID,
testID,
]);

if (isLoadingLog || isLoadingEvergreen) {
Expand Down
Loading
Loading