-
Notifications
You must be signed in to change notification settings - Fork 54
@W-10459671@ Provide progress information of SFGE on verbose mode #792
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
Conversation
| * @param eventKey EventKey to display to user | ||
| * @param args String args passed to the EventKey to make the displayed message meaningful | ||
| */ | ||
| public static void postMessage(String internalLog, EventKey eventKey, String... args) { |
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.
Creating an alternate method to post realtime messages. I've marked the other entry points as deprecated and we can eventually make them realtime as well.
|
|
||
|
|
||
|
|
||
| /** SFGE RELATED **/ |
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.
New event keys to match the new messages
| "unmatchedPathExtensionCpd": "Path extensions for the following files will not be processed by CPD: %s", | ||
| "sfgeInfoLog": "%s", | ||
| "sfgeMetaInfoCollected": "Loaded %s: [ %s ]", | ||
| "sfgeFinishedCompilingFiles": "Compiled %s files.", | ||
| "sfgeStartedBuildingGraph": "Building graph . . .", | ||
| "sfgeFinishedBuildingGraph": "Added all compilation units to graph.", | ||
| "sfgePathEntryPointsIdentified": "Identified %s path entry point(s).", | ||
| "sfgeViolationsInPathProgress": "Detected %s violation(s) from %s path(s) on %s entry point(s) so far.", | ||
| "sfgeCompletedPathAnalysis": "Overall, analyzed %s path(s) from %s entry point(s). Detected %s violation(s)." |
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.
New messages to be displayed during verbose calls.
@teresa-allen-sfdc Please do let me your thoughts on the verbose messages.
| name = "CliMessagerAppender", | ||
| category = Core.CATEGORY_NAME, | ||
| elementType = Appender.ELEMENT_TYPE) | ||
| public class CliMessagerAppender extends AbstractAppender { |
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.
New log appender that steps in to pass realtime messages when needed.
|
|
||
| /** Indicates if a Jorje parse error causes the entire process to stop. */ | ||
| boolean shouldIgnoreParseErrors(); | ||
|
|
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.
New config values to control verbose behavior.
LogWarningsOnVerbose would make the output noisier by including all the warnings from SFGE as info events.
ProgressIncrementsOnVerbose controls how often we post updates on number of paths analyzed.
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.
Do we need these config values anymore? Would removing them simplify the code?
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
||
| public interface ProgressListener { |
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.
Will add javadocs
| import java.util.TreeSet; | ||
|
|
||
| /** Publishes information to CLI on the progress of analysis. */ | ||
| public class ProgressListenerImpl implements ProgressListener { |
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.
All action happens here
| <CliMessagerAppender name="LogToCliMessager"> | ||
| <PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} %m%n"/> | ||
| </CliMessagerAppender> |
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.
Configuring the new log appender.
| // When data is passed back up to us, pop it onto the appropriate string. | ||
| cp.stdout.on('data', data => { | ||
| stdout += data; | ||
| if (!this.handleLiveOut(String(data))) { |
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.
Handle live output if relevant.
| const regex = new RegExp(`^${startTag}(.*)${endTag}`, 'g'); | ||
| const headerLength = startTag.length; | ||
| const tailLength = endTag.length; |
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.
Steps are the same as regular CliMessager updates, except we allow different tags to mean different things.
src/lib/sfge/SfgeWrapper.ts
Outdated
| if (this.outputProcessor.isRealtimeOutput(data)) { | ||
| return this.outputProcessor.processRealtimeOutput(data); | ||
| } | ||
| return false; |
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.
SFGE overrides live output handling.
| expect(isSubstr(output, substring), `Output "${output}" should not contain substring "${substring}"`).is.false; | ||
| } | ||
|
|
||
| describe('scanner:run:dfa', function () { |
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.
New end-to-end tests for dfa. Directly testing sfge's Main.java was getting problematic because of the multithreading. These new tests are more reliable.
Though I'm seeing an issue where each verbose like is printed 6 times. Still investigating to understand the cause.
jfeingold35
left a comment
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.
The SFGE portion has more than we strictly need, but the design itself is sound. I'll keep an eye out for the refactor.
| boolean shouldLogWarningsOnVerbose(); | ||
|
|
||
| /** | ||
| * Should be used to set the level of increments at which path analysis progress update is | ||
| * provided | ||
| */ | ||
| int getProgressIncrementsOnVerbose(); |
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.
Unnecessary, since we're making the progress report happen all the time instead of just on Verbose.
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.
Since the functionality has been modified, this can be renamed to not include "OnVerbose". Though I still think this is a useful variable to have so that users could increase or decrease depending on their convenience. For now, I haven't surfaced these new variables as scanner:run:dfa's flags.
| @VisibleForTesting static final boolean DEFAULT_LOG_WARNINGS_ON_VERBOSE = false; | ||
| @VisibleForTesting static final int DEFAULT_PROGRESS_INCREMENTS_ON_VERBOSE = 50; |
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.
Unnecessary, since progress logging should happen all the time instead of just on Verbose.
| public boolean shouldLogWarningsOnVerbose() { | ||
| return EnvUtil.shouldLogWarningsOnVerbose(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getProgressIncrementsOnVerbose() { | ||
| return EnvUtil.getProgressIncrementsOnVerbose(); | ||
| } | ||
|
|
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.
Unnecessary.
| } | ||
| } | ||
|
|
||
| final ProgressListener progressListener = ProgressListenerProvider.get(); |
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.
Could we have the listener be a static final property to avoid the need to keep declaring a variable for it?
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.
static final would force instantiation at the earliest and not use the lazy loading functionality as intended.
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.
| */ | ||
| public class ProgressListenerImpl implements ProgressListener { | ||
|
|
||
| @VisibleForTesting static final String NONE_FOUND = "none found"; |
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.
As mentioned in scrum, having this many individual events feels like overkill for now, but the strategy itself is sound.
| public boolean shouldLogWarningsOnVerbose() { | ||
| return !EnvUtil.DEFAULT_LOG_WARNINGS_ON_VERBOSE; | ||
| } | ||
|
|
||
| @Override | ||
| public int getProgressIncrementsOnVerbose() { | ||
| return -1 * EnvUtil.DEFAULT_PROGRESS_INCREMENTS_ON_VERBOSE; |
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.
Unnecessary
| public boolean shouldLogWarningsOnVerbose() { | ||
| return SfgeConfigImpl.getInstance().shouldLogWarningsOnVerbose(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getProgressIncrementsOnVerbose() { |
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.
Unnecessary
messages/EventKeyTemplates.js
Outdated
| "sfgeInfoLog": "%s", | ||
| "sfgeMetaInfoCollected": "Loaded %s: [ %s ]", | ||
| "sfgeFinishedCompilingFiles": "Compiled %s files.", | ||
| "sfgeStartedBuildingGraph": "Building graph . . .", |
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.
The periods don't need spaces between them.
| static boolean shouldLogWarningsOnVerbose() { | ||
| return getBoolOrDefault(ENV_LOG_WARNINGS_ON_VERBOSE, DEFAULT_LOG_WARNINGS_ON_VERBOSE); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the level of increments at which path analysis progress update is provided. Applicable | ||
| * only with --verbose. | ||
| * | ||
| * @return value of {@link #ENV_PROGRESS_INCREMENTS_ON_VERBOSE} environment variable if set, | ||
| * else {@link #DEFAULT_PROGRESS_INCREMENTS_ON_VERBOSE} | ||
| */ | ||
| static int getProgressIncrementsOnVerbose() { | ||
| return getIntOrDefault( | ||
| ENV_PROGRESS_INCREMENTS_ON_VERBOSE, DEFAULT_PROGRESS_INCREMENTS_ON_VERBOSE); | ||
| } |
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.
Why is this still here? We don't need it anymore, right?
|
|
||
| /** Indicates if a Jorje parse error causes the entire process to stop. */ | ||
| boolean shouldIgnoreParseErrors(); | ||
|
|
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.
Do we need these config values anymore? Would removing them simplify the code?
| // When data is passed back up to us, pop it onto the appropriate string. | ||
| cp.stdout.on('data', data => { | ||
| stdout += data; | ||
| if (!this.handleLiveOut(String(data))) { |
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.
I don't love this check.
If live output and at-the-end output use different start and end strings, couldn't we just pass all output through both at the appropriate times? The output processor would process real time output as it's received, and then it would process at-the-end output at the end, right?
| let intervalCount = 0; | ||
| this.intervalId = setInterval(() => { | ||
| uxEvents.emit(EVENTS.UPDATE_SPINNER, "Please wait." + ".".repeat(intervalCount)); | ||
| uxEvents.emit(EVENTS.WAIT_ON_SPINNER, 'message is unused'); |
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.
You can remove everything with the interval, here. The point of this was to add a period to the end of the please wait string every 30 seconds. Now that we're adding more informative progress reports, this is redundant.
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.
The extra dots still look like something is happening especially when waiting on the next update. Let me know how you like it during QA. Based on that, we can keep it or remove it.
|
|
||
|
|
||
| private emitUxEvent(eventType: string, messageKey: string, args: string[]): void { | ||
| if (eventType === '') { |
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.
How can this happen?
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.
Previously, we had an if/else to filter only valid eventTypes to go in. The filter has been restructured to not always check for eventTypes. This check should possibly never be invoked, but this is just being defensive to avoid unexpected issues.
4d68616 to
805ca8c
Compare
This PR helps provide more insight into how SFGE's analysis is progressing.
SFGE_PROGRESS_INCREMENTS_ON_VERBOSEenv variable can be tweaked. Default value is 50.SFGE_LOG_WARNINGS_ON_VERBOSEenv variable.There's still some verbosity coming in while generating catalogs to use for rule execution and this decreases the clarity of SFGE's actual progress. I've logged a separate work item to address this issue.