-
Notifications
You must be signed in to change notification settings - Fork 92
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
fix dedup logs #977
fix dedup logs #977
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,6 @@ export class NetworkNode implements NetworkNodeInterface { | |
userDefinedTypes: any; | ||
para?: PARA; | ||
parachainId?: number; | ||
lastLogLineCheckedTimestamp?: string; | ||
lastLogLineCheckedIndex?: number; | ||
group?: string; | ||
|
||
constructor( | ||
|
@@ -415,6 +413,8 @@ export class NetworkNode implements NetworkNodeInterface { | |
timeout: number = DEFAULT_INDIVIDUAL_TEST_TIMEOUT, | ||
): Promise<boolean> { | ||
try { | ||
let lastLogLineCheckedTimestamp: string; | ||
let lastLogLineCheckedIndex: number; | ||
const re = isGlob ? makeRe(pattern) : new RegExp(pattern, "ig"); | ||
if (!re) throw new Error(`Invalid glob pattern: ${pattern} `); | ||
const client = getClient(); | ||
|
@@ -425,7 +425,10 @@ export class NetworkNode implements NetworkNodeInterface { | |
const dedupedLogs = this._dedupLogs( | ||
logs.split("\n"), | ||
client.providerName === "native", | ||
lastLogLineCheckedTimestamp, | ||
lastLogLineCheckedIndex, | ||
); | ||
|
||
const index = dedupedLogs.findIndex((line) => { | ||
if (client.providerName !== "native") { | ||
// remove the extra timestamp | ||
|
@@ -436,11 +439,9 @@ export class NetworkNode implements NetworkNodeInterface { | |
|
||
if (index >= 0) { | ||
done = true; | ||
this.lastLogLineCheckedTimestamp = dedupedLogs[index]; | ||
this.lastLogLineCheckedIndex = index; | ||
debug( | ||
this.lastLogLineCheckedTimestamp.split(" ").slice(1).join(" "), | ||
); | ||
lastLogLineCheckedTimestamp = dedupedLogs[index]; | ||
lastLogLineCheckedIndex = index; | ||
debug(lastLogLineCheckedTimestamp.split(" ").slice(1).join(" ")); | ||
} else { | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
logs = await client.getNodeLogs(this.name, 2, true); | ||
|
@@ -538,12 +539,17 @@ export class NetworkNode implements NetworkNodeInterface { | |
return spanNames; | ||
} | ||
|
||
// prevent to seach in the same log line twice. | ||
_dedupLogs(logs: string[], useIndex = false): string[] { | ||
if (!this.lastLogLineCheckedTimestamp) return logs; | ||
if (useIndex) return logs.slice(this.lastLogLineCheckedIndex); | ||
|
||
const lastLineTs = this.lastLogLineCheckedTimestamp.split(" ")[0]; | ||
// prevent to search in the same log line twice. | ||
_dedupLogs( | ||
logs: string[], | ||
useIndex = false, | ||
lastLogLineCheckedTimestamp: string, | ||
lastLogLineCheckedIndex: number, | ||
): string[] { | ||
if (!lastLogLineCheckedTimestamp) return logs; | ||
if (useIndex) return logs.slice(lastLogLineCheckedIndex); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, lastLogLineCheckedIndex is undefined when entering the above loop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, those two variables work in tandem to represent the different providers features. The invariant here is that I think there is room to improving here, but we can do it in a follow up pr. Thanks! |
||
|
||
const lastLineTs = lastLogLineCheckedTimestamp.split(" ")[0]; | ||
const index = logs.findIndex((logLine) => { | ||
const thisLineTs = logLine.split(" ")[0]; | ||
return thisLineTs > lastLineTs; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It won't cause issue if it's not initialized ?