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 #486

Closed
wants to merge 22 commits into from

Conversation

SupaJoon
Copy link
Collaborator

DevProd-1435

Description

The resmoke route is not fully deprecated yet so we must support it until Julian lets us know. renderingType is only applicable to test logs at the moment.

@SupaJoon SupaJoon requested a review from a team February 12, 2024 21:54
Copy link

cypress bot commented Feb 12, 2024

1 failed test on run #5222 ↗︎

1 120 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

fix it up
Project: Parsley Commit: 30e548e0b8
Status: Failed Duration: 03:15 💡
Started: Feb 29, 2024 9:38 PM Ended: Feb 29, 2024 9:41 PM

Review all test suite changes for PR #486 ↗︎

@SupaJoon SupaJoon changed the title DevProd-1435: Use renderType GQL field to determine Row rendering format DevProd-1435: Use renderingType GQL field to determine Row rendering format Feb 13, 2024
Copy link
Collaborator

@khelif96 khelif96 left a comment

Choose a reason for hiding this comment

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

I think this can be done in a way that is a little more flexible for expanding to different rendering types. Right now the assumption is that there are only 2 types of logs and doesn't leave room for future log types like how the previous implementation did.

If we are going to be using renderingType to determine log render behavior we should try to be consistent across the app about how it is used instead of having it only apply to a very specific subset of test logs.

// At this point, logMetadata.renderingType is guaranteed to be defined from LogView/LoadingPage.tsx.
// logType can be removed from this calculation when the Parsley resmoke route is fully deprecated.
const Row =
logMetadata?.renderingType === "resmoke" ||
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use enums instead of strings like "resmoke" or "default"

Copy link
Collaborator

Choose a reason for hiding this comment

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

I also don't quite understand this bit of logic. Is there a way we can preserve rowRenderMap it seems far more flexible and would allow the expansion of future row types in the future.

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 15, 2024

Choose a reason for hiding this comment

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

I think this logic doesn't make sense because it doesn't do a good job at holistically bringing in renderingType to Parsley. The logic that you reviewed utilizes parsley route (logType) and renderingType when available. I just pushed some code to decouple the route from renderingType, utilizes testlog renderingType from the GQL endpoint but also extrapolates rendering type per logType.

@@ -9,18 +9,19 @@ interface SearchState {
}

interface LogMetadata {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for sorting!

isUploadedLog: true,
logType,
renderingType:
logType === LogTypes.RESMOKE_LOGS ? "resmoke" : "default",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same comment about using an enum value.

Comment on lines 17 to 28
type SelectState =
| LogTypes.RESMOKE_LOGS
| LogTypes.EVERGREEN_TASK_LOGS
| 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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you make this change it seems to do the same thing but is arguably slightly less readable.

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 14, 2024

Choose a reason for hiding this comment

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

LogTypes includes values that are unrelated to the Select component state which makes it harder to infer usage. We should be more strict with our typings and exclude unused values when representing state.


// renderingType is only propagated for evergreen test logs as of DEVPROD-1435.
const renderingType =
(testData?.task?.tests.testResults[0]?.logs
Copy link
Collaborator

Choose a reason for hiding this comment

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

renderingType will default to default for resmoke logs which is confusing. I think we should try to be consistent about how this value is treated and used.

@SupaJoon SupaJoon requested a review from khelif96 February 15, 2024 20:03
@@ -108,6 +111,7 @@ export const useResolveLogURL = ({
let htmlLogURL = "";
let jobLogsURL = "";
let legacyJobLogsURL = "";
let renderingType = "";
Copy link
Collaborator

@khelif96 khelif96 Feb 16, 2024

Choose a reason for hiding this comment

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

Suggested change
let renderingType = "";
let renderingType: SupportedLogRenderingTypes = LogRenderingTypes.Default;

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still necessary. Otherwise the type alias on line 206 has no effect.

Comment on lines 54 to 57
reportError(new Error("Encountered unsupported renderType"), {
rawLogURL: logMetadata?.rawLogURL,
renderingType: logMetadata?.renderingType,
}).warning();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We wouldn't want to report an error here. This will result in us logging an error for every single row.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree it's better to report the error closer to ingestion. Technically this wouldn't run into an error on every line because this code is in the generator body and not the return value.

@@ -38,6 +40,24 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
? new RegExp(`${highlights.map((h) => `(${h})`).join("|")}`, "gi")
: undefined;

let Row: React.FC<ResmokeRowProps> | React.FC<AnsiRowProps>;
// At this point, logMetadata is defined from <LoadingPage />
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can remove this comment since its implied.

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 27, 2024

Choose a reason for hiding this comment

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

I will find this comment helpful in the future. If I were looking at this code after time away, this is something I would want to verify because logMetadata and renderingType are both marked as optional in their type structures.

@@ -5,6 +5,11 @@ enum LogTypes {
RESMOKE_LOGS = "RESMOKE_LOGS",
}

enum SupportedLogRenderingTypes {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we remove the word Supported since it being here implies that it is supported?

Suggested change
enum SupportedLogRenderingTypes {
enum LogRenderingTypes {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Originally, I wanted to make a distinction between unsupported and supported rendering types because unsupported types may be cached in the Apollo request layer and the code may encounter unsupported types. Either way works and I updated the code to your suggestion.

Comment on lines 54 to 57
reportError(new Error("Encountered unsupported renderingType"), {
rawLogURL: logMetadata?.rawLogURL,
renderingType: logMetadata?.renderingType,
}).warning();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't log this here since it would log for every single log row we try to render.

@@ -189,17 +200,21 @@ export const useResolveLogURL = ({
text: false,
});
downloadURL = rawLogURL;
renderingType =
renderingTypeFromQuery || SupportedLogRenderingTypes.Default;
break;
}
default:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably a good place to error. We should set also probably set a default rendering type so the page can still work.

Comment on lines 17 to 20
type SelectState =
| LogTypes.RESMOKE_LOGS
| LogTypes.EVERGREEN_TASK_LOGS
| undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think maybe the select states should correspond to rendering types instead of LogTypes since with this refactor the LogTypes only really reflect the origin of the log.

Comment on lines 48 to 51
renderingType:
logType === LogTypes.RESMOKE_LOGS
? SupportedLogRenderingTypes.Resmoke
: SupportedLogRenderingTypes.Default,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Doing the above we can also avoid this.

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 26, 2024

Choose a reason for hiding this comment

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

If I change the function parameter from LogTypes to LogRenderingType, then I will have to cast the function parameter to LogType for the logType value on line 47 which is fine for now. These tickets will look more into logType usage.
https://jira.mongodb.org/browse/DEVPROD-5130
https://jira.mongodb.org/browse/DEVPROD-5163

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm i think this may be ok, Since this could be used to distinguish between log types for log sectioning project? I do think it would be important to iron that out in your project or at some point before it.

@@ -38,6 +40,24 @@ const ParsleyRow: RowRendererFunction = ({ logType, processedLogLines }) => {
? new RegExp(`${highlights.map((h) => `(${h})`).join("|")}`, "gi")
: undefined;

let Row: React.FC<ResmokeRowProps> | React.FC<AnsiRowProps>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is more flexible and avoids exporting the the Row props.

Suggested change
let Row: React.FC<ResmokeRowProps> | React.FC<AnsiRowProps>;
let Row: typeof ResmokeRow | typeof AnsiRow;

@SupaJoon SupaJoon requested a review from khelif96 February 27, 2024 15:44
Copy link
Collaborator

@khelif96 khelif96 left a comment

Choose a reason for hiding this comment

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

nit. Can you capitalize DEVPROD in the pr title

Great job just a few more comments and follow up from my last review.

Comment on lines +186 to +190
const {
renderingType: renderingTypeFromQuery,
url,
urlRaw,
} = testData?.task?.tests.testResults[0]?.logs || {};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we leave a comment here.
Something simple such as if we fetched test results use that URL otherwise fallback to hardcoded routes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I left a comment a comment for the query at the top of the file that describes how LogRenderingType is reasoned. I'm not actually sure what to comment here that would be useful for me. Please suggest a comment and I will commit it.

@@ -108,6 +111,7 @@ export const useResolveLogURL = ({
let htmlLogURL = "";
let jobLogsURL = "";
let legacyJobLogsURL = "";
let renderingType = "";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still necessary. Otherwise the type alias on line 206 has no effect.

Comment on lines +206 to +209
} else if (!renderingTypeFromQuery) {
renderingType = LogRenderingTypes.Default;
} else {
renderingType = LogRenderingTypes.Default;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can be refactored out. The first if statement handles the case where renderingTypeFromQuery is undefined. renderingTypeFromQuery can't be in LogRenderingTypes

Copy link
Collaborator

Choose a reason for hiding this comment

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

If we assign a default value for renderingType like my suggestion on on L115 this assignment in the else statement becomes unnecessary as well

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 29, 2024

Choose a reason for hiding this comment

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

the value from the query will overwrite renderingType so I still need the condition on line 206

Copy link
Collaborator

Choose a reason for hiding this comment

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

I may be missing what you mean but Afaict renderingType doesn't get overridden anywhere else so I still think it's not necessary. Can you point me to where it does?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, you're right. I jumbled the variable assignment on line 187 when I made that comment.

Copy link
Collaborator Author

@SupaJoon SupaJoon Feb 29, 2024

Choose a reason for hiding this comment

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

Ah, so renderingTypeFromQuery may actually be an empty string. In that case, I would want to cast it to the default rendering type and not submit an error -- that's when the condition on 206 comes into play.

rawLogURL,
unsupportedRenderingType: renderingTypeFromQuery,
},
}).warning();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be logged at .severe() since this indicates we encountered some sort of unsupported rendering type.

@SupaJoon SupaJoon changed the title DevProd-1435: Use renderingType GQL field to determine Row rendering format DEVPROD-1435: Use renderingType GQL field to determine Row rendering format Feb 29, 2024
@SupaJoon SupaJoon requested a review from khelif96 February 29, 2024 15:50
Copy link
Collaborator

@khelif96 khelif96 left a comment

Choose a reason for hiding this comment

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

Great job on this! 🚀 mod my comment

Comment on lines +206 to +209
} else if (!renderingTypeFromQuery) {
renderingType = LogRenderingTypes.Default;
} else {
renderingType = LogRenderingTypes.Default;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I may be missing what you mean but Afaict renderingType doesn't get overridden anywhere else so I still think it's not necessary. Can you point me to where it does?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants