-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add actions job log buffer and profiler #866
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
Open
mattdholloway
wants to merge
28
commits into
main
Choose a base branch
from
actions-job-log-buffer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+427
−31
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
8a5efb9
add sliding window for actions logs
mattdholloway e6ef962
refactor: fix sliding
mattdholloway 271c7c2
remove trim content
mattdholloway e65c0f0
only use up to 1mb of memory for logs
mattdholloway ade3852
update to tail lines in second pass
mattdholloway 5a76cbd
add better memory usage calculation
mattdholloway 8e60fb2
increase window size to 5MB
mattdholloway e1c3143
update test
mattdholloway 75dc8e7
Merge branch 'main' into actions-job-log-buffer
mattdholloway b128e44
Merge branch 'actions-job-log-buffer' of https://github.com/github/gi…
mattdholloway 88d16d2
Merge branch 'main' into actions-job-log-buffer
mattdholloway 4bf84b2
Merge branch 'main' into actions-job-log-buffer
mattdholloway 6b8f2ba
update vers
mattdholloway 8002fbd
undo vers change
mattdholloway 52e531e
add incremental memory tracking
mattdholloway 8f85398
use ring buffer
mattdholloway 0d19480
remove unused ctx param
mattdholloway f104e67
remove manual GC clear
mattdholloway 9d273b9
fix cca feedback
mattdholloway 4e43327
extract ring buffer logic to new package
mattdholloway 2ff2d4f
handle log content processing errors and use correct param for maxjob…
mattdholloway c6f5f7f
fix tailing
mattdholloway 1c1061c
account for if tailLines exceeds window size
mattdholloway 75b8c94
add profiling thats reusable
mattdholloway 71bfac8
remove profiler testing
mattdholloway a43b03c
refactor profiler: introduce safeMemoryDelta for accurate memory delt…
mattdholloway d9c8825
linter fixes
mattdholloway ec070ee
Update pkg/buffer/buffer.go
mattdholloway 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package buffer | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
// ProcessResponseAsRingBufferToEnd reads the body of an HTTP response line by line, | ||
// storing only the last maxJobLogLines lines using a ring buffer (sliding window). | ||
// This efficiently retains the most recent lines, overwriting older ones as needed. | ||
// | ||
// Parameters: | ||
// httpResp: The HTTP response whose body will be read. | ||
// maxJobLogLines: The maximum number of log lines to retain. | ||
// | ||
// Returns: | ||
// string: The concatenated log lines (up to maxJobLogLines), separated by newlines. | ||
// int: The total number of lines read from the response. | ||
// *http.Response: The original HTTP response. | ||
// error: Any error encountered during reading. | ||
// | ||
// The function uses a ring buffer to efficiently store only the last maxJobLogLines lines. | ||
// If the response contains more lines than maxJobLogLines, only the most recent lines are kept. | ||
func ProcessResponseAsRingBufferToEnd(httpResp *http.Response, maxJobLogLines int) (string, int, *http.Response, error) { | ||
lines := make([]string, maxJobLogLines) | ||
validLines := make([]bool, maxJobLogLines) | ||
totalLines := 0 | ||
writeIndex := 0 | ||
|
||
scanner := bufio.NewScanner(httpResp.Body) | ||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024) | ||
|
||
for scanner.Scan() { | ||
line := scanner.Text() | ||
totalLines++ | ||
|
||
lines[writeIndex] = line | ||
validLines[writeIndex] = true | ||
writeIndex = (writeIndex + 1) % maxJobLogLines | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return "", 0, httpResp, fmt.Errorf("failed to read log content: %w", err) | ||
} | ||
|
||
var result []string | ||
linesInBuffer := totalLines | ||
if linesInBuffer > maxJobLogLines { | ||
linesInBuffer = maxJobLogLines | ||
} | ||
|
||
startIndex := 0 | ||
if totalLines > maxJobLogLines { | ||
startIndex = writeIndex | ||
} | ||
|
||
for i := 0; i < linesInBuffer; i++ { | ||
idx := (startIndex + i) % maxJobLogLines | ||
if validLines[idx] { | ||
result = append(result, lines[idx]) | ||
} | ||
} | ||
|
||
return strings.Join(result, "\n"), totalLines, httpResp, nil | ||
} |
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
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.