-
-
Notifications
You must be signed in to change notification settings - Fork 94
Add Diagnostic Dumping Functionality #1443
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
Merged
Merged
Changes from 23 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7ffe56c
Add Enhanced Diagnostic Dump Feature with Configurable Output Format…
mdaneri 8cc7d02
add pipe example
mdaneri 6121cb5
various improvements
mdaneri d362833
Merge branch 'develop' into invoke-podedump
mdaneri dbf54d9
Fixes and improvements
mdaneri 14afc55
Update Helpers.ps1
mdaneri 34d7b6b
added variables from runspace
mdaneri f05adda
Update Dump.ps1
mdaneri b64da21
Added suspend and resume server
mdaneri 7db258a
internazioanalization+ example
mdaneri 88642e8
Update PetData.json
mdaneri 65836b5
Documentation
mdaneri 52574f9
upgrade powershell to '7.2.24'
mdaneri 0bd3f8a
Update Server.Tests.ps1
mdaneri 7dd5f96
Merge branch 'develop' into invoke-podedump
mdaneri 6135e17
fixes
mdaneri 82a6020
Fix CTRL B issue
mdaneri 49f962b
fixes
mdaneri 70a8696
Merge branch 'develop' into invoke-podedump
Badgerati 82c2a28
add net9
mdaneri 6ec63d9
Merge remote-tracking branch 'upstream/develop' into invoke-podedump
mdaneri e41c207
Merge remote-tracking branch 'upstream/develop' into invoke-podedump
mdaneri f0c8b45
doc fixes
mdaneri dc76df3
first review
mdaneri c8ab57c
second update
mdaneri 79fdf46
suspend http and tcp
mdaneri 900001a
fix tests
mdaneri 526325c
WSS suspension
mdaneri ce5cc01
Fix suspend
mdaneri 9cdaf4e
Update DebuggerHandler.cs
mdaneri 414d785
minor changes
mdaneri 68f14b0
tentative to use a new terminate token
mdaneri edc604e
looking good
mdaneri 0081477
Fix the suspend and dump
mdaneri 1791f76
Add progress bar
mdaneri 525638f
debugging
mdaneri 5493c91
suspend resume fixed
mdaneri 3ea0267
fixes
mdaneri a9dfecf
Changed the runspace enumeration logic
mdaneri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Overview | ||
|
||
In addition to restarting, Pode provides a way to temporarily **suspend** and **resume** the server, allowing you to pause all activities and connections without completely stopping the server. This can be especially useful for debugging, troubleshooting, or performing maintenance tasks where you don’t want to fully restart the server. | ||
|
||
## Suspending | ||
|
||
To suspend a running Pode server, use the `Suspend-PodeServer` function. This function will pause all active server runspaces, effectively putting the server into a suspended state. Here’s how to do it: | ||
|
||
1. **Run the Suspension Command**: | ||
- Simply call `Suspend-PodeServer` from within your Pode environment or script. | ||
|
||
```powershell | ||
Suspend-PodeServer -Timeout 60 | ||
``` | ||
|
||
The `-Timeout` parameter specifies how long the function should wait (in seconds) for each runspace to be fully suspended. This is optional, with a default timeout of 30 seconds. | ||
|
||
2. **Suspension Process**: | ||
- When you run `Suspend-PodeServer`, Pode will: | ||
- Pause all runspaces associated with the server, putting them into a debug state. | ||
- Trigger a "Suspend" event to signify that the server is paused. | ||
- Update the server’s status to reflect that it is now suspended. | ||
|
||
3. **Outcome**: | ||
- After suspension, all server operations are halted, and the server will not respond to incoming requests until it is resumed. | ||
|
||
## Resuming | ||
|
||
Once you’ve completed any tasks or troubleshooting, you can resume the server using `Resume-PodeServer`. This will restore the Pode server to its normal operational state: | ||
|
||
1. **Run the Resume Command**: | ||
- Call `Resume-PodeServer` to bring the server back online. | ||
|
||
```powershell | ||
Resume-PodeServer | ||
``` | ||
|
||
2. **Resumption Process**: | ||
- When `Resume-PodeServer` is executed, Pode will: | ||
- Restore all paused runspaces back to their active states. | ||
- Trigger a "Resume" event, marking the server as active again. | ||
- Clear the console, providing a refreshed view of the server status. | ||
|
||
3. **Outcome**: | ||
- The server resumes normal operations and can now handle incoming requests again. | ||
|
||
## When to Use Suspend and Resume | ||
|
||
These functions are particularly useful when: | ||
|
||
- **Debugging**: If you encounter an issue, you can pause the server to inspect state or troubleshoot without a full restart. | ||
- **Maintenance**: Suspend the server briefly during configuration changes, and then resume when ready. | ||
- **Performance Management**: Temporarily pause during high load or for throttling purposes if required by your application logic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -360,4 +360,4 @@ | |
"Users" | ||
] | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<# | ||
.SYNOPSIS | ||
Initializes and starts a Pode server with OpenAPI support and error logging. | ||
|
||
.DESCRIPTION | ||
This script sets up a Pode server with HTTP endpoints, error logging, and OpenAPI documentation. | ||
It also includes a sample route to simulate a critical error and dump the server's memory state. | ||
|
||
.EXAMPLE | ||
To run the sample: ./Web-Dump.ps1 | ||
|
||
OpenAPI Info: | ||
Specification: | ||
http://localhost:8081/openapi | ||
Documentation: | ||
http://localhost:8081/docs | ||
|
||
.LINK | ||
https://github.com/Badgerati/Pode/blob/develop/examples/Web-Dump.ps1 | ||
|
||
.NOTES | ||
Author: Pode Team | ||
License: MIT License | ||
#> | ||
|
||
try { | ||
# Determine the script path and Pode module path | ||
$ScriptPath = (Split-Path -Parent -Path $MyInvocation.MyCommand.Path) | ||
$podePath = Split-Path -Parent -Path $ScriptPath | ||
|
||
# Import the Pode module from the source path if it exists, otherwise from installed modules | ||
if (Test-Path -Path "$($podePath)/src/Pode.psm1" -PathType Leaf) { | ||
Import-Module "$($podePath)/src/Pode.psm1" -Force -ErrorAction Stop | ||
} | ||
else { | ||
Import-Module -Name 'Pode' -MaximumVersion 2.99 -ErrorAction Stop | ||
} | ||
} | ||
catch { throw } | ||
|
||
# Start Pode server with specified script block | ||
Start-PodeServer -Threads 4 -ScriptBlock { | ||
|
||
# listen on localhost:8081 | ||
Add-PodeEndpoint -Address localhost -Port 8081 -Protocol Http | ||
Add-PodeEndpoint -Address localhost -Port 8082 -Protocol Http | ||
Add-PodeEndpoint -Address localhost -Port 8083 -Protocol Http | ||
Add-PodeEndpoint -Address localhost -Port 8025 -Protocol Smtp | ||
Add-PodeEndpoint -Address localhost -Port 8091 -Protocol Ws -Name 'WS1' | ||
Add-PodeEndpoint -Address localhost -Port 8091 -Protocol Http -Name 'WS' | ||
Add-PodeEndpoint -Address localhost -Port 8100 -Protocol Tcp | ||
|
||
|
||
# set view engine to pode renderer | ||
Set-PodeViewEngine -Type Html | ||
|
||
# Enable error logging | ||
New-PodeLoggingMethod -Terminal | Enable-PodeErrorLogging | ||
|
||
|
||
# Enable OpenAPI documentation | ||
|
||
Enable-PodeOpenApi -Path '/docs/openapi' -OpenApiVersion '3.0.3' -DisableMinimalDefinitions -NoDefaultResponses | ||
|
||
Add-PodeOAInfo -Title 'Dump - OpenAPI 3.0.3' -Version 1.0.1 | ||
Add-PodeOAServerEndpoint -url '/api/v3' -Description 'default endpoint' | ||
|
||
# Enable OpenAPI viewers | ||
Enable-PodeOAViewer -Type Swagger -Path '/docs/swagger' | ||
Enable-PodeOAViewer -Type ReDoc -Path '/docs/redoc' -DarkMode | ||
Enable-PodeOAViewer -Type RapiDoc -Path '/docs/rapidoc' -DarkMode | ||
Enable-PodeOAViewer -Type StopLight -Path '/docs/stoplight' -DarkMode | ||
Enable-PodeOAViewer -Type Explorer -Path '/docs/explorer' -DarkMode | ||
Enable-PodeOAViewer -Type RapiPdf -Path '/docs/rapipdf' -DarkMode | ||
|
||
# Enable OpenAPI editor and bookmarks | ||
Enable-PodeOAViewer -Editor -Path '/docs/swagger-editor' | ||
Enable-PodeOAViewer -Bookmarks -Path '/docs' | ||
|
||
# Setup session details | ||
Enable-PodeSessionMiddleware -Duration 120 -Extend | ||
|
||
# Define API routes | ||
Add-PodeRouteGroup -Path '/api/v3' -Routes { | ||
|
||
Add-PodeRoute -PassThru -Method Get -Path '/dump' -ScriptBlock { | ||
$format = $WebEvent.Query['format'] | ||
try { | ||
# Simulate a critical error | ||
throw [System.DivideByZeroException] 'Simulated divide by zero error' | ||
} | ||
catch { | ||
$_ | Invoke-PodeDump -Format $format | ||
} | ||
} | Set-PodeOARouteInfo -Summary 'Dump state' -Description 'Dump the memory state of the server.' -Tags 'dump' -OperationId 'dump'-PassThru | | ||
Set-PodeOARequest -Parameters (New-PodeOAStringProperty -Name 'format' -Description 'Dump export format.' -Enum 'json', 'clixml', 'txt', 'bin', 'yaml' -Default 'json' | ConvertTo-PodeOAParameter -In Query ) | ||
} | ||
|
||
Add-PodeVerb -Verb 'HELLO' -ScriptBlock { | ||
Write-PodeTcpClient -Message 'HI' | ||
'here' | Out-Default | ||
} | ||
|
||
# setup an smtp handler | ||
Add-PodeHandler -Type Smtp -Name 'Main' -ScriptBlock { | ||
Write-PodeHost '- - - - - - - - - - - - - - - - - -' | ||
Write-PodeHost $SmtpEvent.Email.From | ||
Write-PodeHost $SmtpEvent.Email.To | ||
Write-PodeHost '|' | ||
Write-PodeHost $SmtpEvent.Email.Body | ||
Write-PodeHost '|' | ||
# Write-PodeHost $SmtpEvent.Email.Data | ||
# Write-PodeHost '|' | ||
$SmtpEvent.Email.Attachments | Out-Default | ||
if ($SmtpEvent.Email.Attachments.Length -gt 0) { | ||
#$SmtpEvent.Email.Attachments[0].Save('C:\temp') | ||
} | ||
Write-PodeHost '|' | ||
$SmtpEvent.Email | Out-Default | ||
$SmtpEvent.Request | out-default | ||
$SmtpEvent.Email.Headers | out-default | ||
Write-PodeHost '- - - - - - - - - - - - - - - - - -' | ||
} | ||
|
||
# GET request for web page | ||
Add-PodeRoute -Method Get -Path '/' -EndpointName 'WS' -ScriptBlock { | ||
Write-PodeViewResponse -Path 'websockets' | ||
} | ||
|
||
# SIGNAL route, to return current date | ||
Add-PodeSignalRoute -Path '/' -ScriptBlock { | ||
$msg = $SignalEvent.Data.Message | ||
|
||
if ($msg -ieq '[date]') { | ||
$msg = [datetime]::Now.ToString() | ||
} | ||
|
||
Send-PodeSignal -Value @{ message = $msg } | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.