-
Notifications
You must be signed in to change notification settings - Fork 77
feat: add new report cmd #812
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 7 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
d1906af
add cmd report; pernding performance improvements
tclemos f9b09bf
report: add some parallelism and concurrency to report generation
tclemos 53becda
report: load receipts by block instead of one by one
tclemos 8dd9f33
report: add support to pdf format
tclemos dc4ab98
Merge branch 'main' into thiago/cmd-report
tclemos 6c65ff5
fix merge conflict
tclemos da2f3f9
Merge branch 'main' into thiago/cmd-report
tclemos 7ab4029
make gen; linter fixes
tclemos 5c1eac5
report: copilot fixes
tclemos d686bc3
report: review start-block and end-block flags behavior and defaults
tclemos ac9e5cc
report: remove leftover errorChan
tclemos 22fbd7b
report: fix average base-fee computation
tclemos 56885c3
report: add rpc requirements to docs
tclemos f7bfc0f
report: review dependency versions
tclemos 927deeb
report: add unit tests
tclemos 93f2f68
report: improve flag validation
tclemos ee06b65
report: improved chrome dependency validation to generate pdf reports
tclemos 097e7df
report: fix timer goroutine leak in pdf generation
tclemos 8edcaf0
report: fix error message formatting in pdf generation
tclemos b5856d8
fix: restore viper to main require block in go.mod
tclemos b99f267
report: add defensive validation to prevent infinite loop
tclemos 4f2f8d9
report: fix context shadowing in pdf generation
tclemos d8922c7
report: reduce channel buffer to avoid excessive memory allocation
tclemos 8ddce4f
report: propagate context to pdf generation for immediate cancellation
tclemos 9a476a4
report: add html escaping to stat card titles and values
tclemos 4e6e7e4
report: fix goroutine leak in block channel producer
tclemos c26d5f7
report: add retry mechanism to ensure deterministic reports
tclemos eb69a61
docs: add code quality checklist to prevent common mistakes
tclemos 69cab77
docs: update retry behavior to match implementation
tclemos 18e7103
report: fix race condition by draining failedChan after main loop
tclemos de06605
report: improve progress logging to show successful and failed blocks
tclemos eeaac15
report: use effectiveGasPrice from receipt for EIP-1559 compatibility
tclemos fc4bbee
docs: update code quality checklist with critical thinking and new le…
tclemos 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,79 @@ | ||
| package report | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/chromedp/cdproto/page" | ||
| "github.com/chromedp/chromedp" | ||
| "github.com/rs/zerolog/log" | ||
| ) | ||
|
|
||
| // outputPDF generates a PDF report from the BlockReport data | ||
| func outputPDF(report *BlockReport, outputFile string) error { | ||
| log.Info().Msg("Generating PDF report from HTML") | ||
|
|
||
| // Generate HTML from the existing template | ||
| html := generateHTML(report) | ||
|
|
||
| // Create chromedp context with timeout | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
|
|
||
| // Allocate a new browser context | ||
| ctx, cancel = chromedp.NewContext(ctx) | ||
| defer cancel() | ||
|
|
||
| var buf []byte | ||
| err := chromedp.Run(ctx, | ||
| chromedp.Navigate("about:blank"), | ||
| chromedp.ActionFunc(func(ctx context.Context) error { | ||
| // Get the frame tree to set document content | ||
| frameTree, err := page.GetFrameTree().Do(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get frame tree: %w", err) | ||
| } | ||
|
|
||
| // Set the HTML content | ||
| return page.SetDocumentContent(frameTree.Frame.ID, html).Do(ctx) | ||
| }), | ||
| chromedp.ActionFunc(func(ctx context.Context) error { | ||
| // Wait a bit for any dynamic content to settle | ||
| time.Sleep(500 * time.Millisecond) | ||
| return nil | ||
tclemos marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }), | ||
| chromedp.ActionFunc(func(ctx context.Context) error { | ||
| // Print to PDF with appropriate settings | ||
| var err error | ||
| buf, _, err = page.PrintToPDF(). | ||
| WithPrintBackground(true). | ||
| WithScale(0.8). | ||
| WithPreferCSSPageSize(false). | ||
| WithPaperWidth(8.5). | ||
| WithPaperHeight(11). | ||
| WithMarginTop(0.4). | ||
| WithMarginBottom(0.4). | ||
| WithMarginLeft(0.4). | ||
| WithMarginRight(0.4). | ||
| Do(ctx) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to print to PDF: %w", err) | ||
| } | ||
| return nil | ||
| }), | ||
| ) | ||
|
|
||
| if err != nil { | ||
| return fmt.Errorf("failed to generate PDF: %w", err) | ||
| } | ||
|
|
||
| // Write PDF to file | ||
| if err := os.WriteFile(outputFile, buf, 0644); err != nil { | ||
| return fmt.Errorf("failed to write PDF file: %w", err) | ||
| } | ||
|
|
||
| log.Info().Str("file", outputFile).Msg("PDF report written") | ||
| return nil | ||
| } | ||
Oops, something went wrong.
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.