-
Notifications
You must be signed in to change notification settings - Fork 223
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
Start of a PSES log file analyzer #797
Conversation
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.
Some quick comments on the C# code, will look at the PowerShell this week
src/PowerShellEditorServices.Protocol/MessageProtocol/MessageReader.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices.Protocol/MessageProtocol/MessageReader.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices.Protocol/MessageProtocol/MessageReader.cs
Outdated
Show resolved
Hide resolved
bc5b6ce
to
1cc9e57
Compare
src/PowerShellEditorServices.Protocol/MessageProtocol/MessageReader.cs
Outdated
Show resolved
Hide resolved
src/PowerShellEditorServices.Protocol/MessageProtocol/MessageWriter.cs
Outdated
Show resolved
Hide resolved
Can you give an example of how to use this? I'd like a bit more context |
If you look in the Teams channel you'll see a bunch of examples of usage. |
|
||
$message = parseLogMessage $method | ||
|
||
[PsesLogEntry]::new($script:logEntryIndex, $timestamp, $timestampStr, $logLevel, $threadId, $method, |
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.
This module targets PS v5.1+ right? Might be worth setting the manifest field. Otherwise, need New-Object
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.
Better yet, you could use the coercion syntax:
[PsesLogEntry]@{
Index = $script:logEntryIndex
Timestamp = $timestampStr
TimestampStr = [datetime]$timestampStr
...
}
You should even get field completions for that.
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'll set the module manifest to require v5 or higher. This tool is primarily for project maintainers so I don't think that should be a problem.
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 set it to 5.1.
$script:logEntryIndex++ | ||
} | ||
|
||
function parseLogMessage([string]$Method) { |
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 not a param
block?
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.
Not using this like an advanced function (no need to support pipeline input, should process, etc).
# Description = '' | ||
|
||
# Minimum version of the PowerShell engine required by this module | ||
# PowerShellVersion = '' |
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.
Given class usage, this should be "5.1" I'm thinking
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.
We got class support in 5.0, right?
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 think so, but I think there a number of problems with 5.0 that have lead to its widespread removal and de facto deprecation.
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 set it to 5.1.
. $PSScriptRoot\Parse-PsesLog.ps1 | ||
. $PSScriptRoot\Analyze.ps1 | ||
|
||
Export-ModuleMember -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.
@daxian-dbw thinks that this should be unneeded with FunctionsToExport
set in the manifest.
Apparently the flow is:
defined commands --> Export-ModuleMember
--> FunctionsToExport
--> actual exported commands
Where -->
is "filter through".
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.
However, this bodes experimentation
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.
Certainly defining an explicit list of exported functions is something we want to encourage for performance and discovery/analysis reasons.
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.
Fixed.
tools/PsesLogAnalyzer/Types.ps1
Outdated
@@ -0,0 +1,152 @@ | |||
enum PsesLogLevel { | |||
Diagnostic; |
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.
Are the semicolons needed here?
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.
No. Bad habit from when I defined simple enums on a single line. I'll fix 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.
Fixed.
This is probably a legal path char on Linux but on Windows it isn't. Also, Pester uses a similar format: <path>: line <num> Update PSES log analyzer to parse template. Add some more analysis commands.
1f07039
to
e35b7d2
Compare
I think I've addressed all the PR feedback. |
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.
LGTM! I left two small comments, but they are just comments
return $result | ||
} | ||
|
||
if (($Method -eq 'ReadMessage') -and |
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.
Given a cascade of if
/elseif
/else
statements followed by a single implicit return, this might be refactorable as a series of if (...) { return }
statements for slightly lower complexity.
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.
This is a bigger change. I'll adress it later (in another PR) when I'm back from New York.
parseLogMessageBody -Discard | ||
return $result | ||
} | ||
else { |
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.
else
here is not needed, since if
always returns
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.
Fixed
I'll be travelling tomorrow. Could someone merge this before 1.9.1 if @TylerLeonhardt approves it. Thanks. |
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.
This looks great @rkeithhill! I can't wait to give it a try 👍 I +1'd the remaining feedback from @rjmholt.
Wanted to get some input on this one before I take it any further -
particularly the suggested logging change to MessageReader/Writer.