Skip to content
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

ext/har: add HAR logger extension #610

Merged
merged 24 commits into from
Jan 10, 2025

Conversation

CameronBadman
Copy link
Contributor

ext/har: add HAR logger extension

Port HAR (HTTP Archive) logging functionality from abourget/goproxy
to the ext/ package. Features include:

  • Request and response capture
  • Content body logging with toggle
  • HAR 1.2 spec compliance
  • Thread-safe operation
  • Comprehensive test coverage

This is a self-contained extension that doesn't modify core functionality.
Credit to abourget/goproxy for the original implementation.

Closes #609

Port HAR logging from abourget/goproxy to ext package.
Closes elazarl#609
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
ext/har/types.go Outdated Show resolved Hide resolved
@CameronBadman
Copy link
Contributor Author

@ErikPelli Fixed up those errors I believe

@ErikPelli
Copy link
Collaborator

@CameronBadman the comment that I left for the tests has been resolved but I don't see the requested changes in the branch

ext/har/logger.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
Comment on lines 153 to 156
assert.Equal(t, 3, len(exports), "should have 3 export batches")
assert.Equal(t, threshold, len(exports[0]), "first batch should have threshold size")
assert.Equal(t, threshold, len(exports[1]), "second batch should have threshold size")
assert.Equal(t, 1, len(exports[2]), "last batch should have remainder")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are handling the batch in goroutines, we don't have anymore an enforced order. You have to adapt the assertion to expect two full batches and one with only one entry in any possible order.

Comment on lines 124 to 126
entriesCopy := make([]Entry, len(entries))
copy(entriesCopy, entries)
exports = append(exports, entriesCopy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here there is a race condition, you are appending to a shared slice but there is no mutex to prevent concurrent accesses.
Add it to prevent this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not entirely sure if I have solved this one

ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
ext/har/logger_test.go Outdated Show resolved Hide resolved
…ogger test to measure based on freq not a sorterd set
@ErikPelli
Copy link
Collaborator

Thanks! LGTM. Tomorrow I'll do one final check and, if it will be ok, I will merge this pull request

@ErikPelli ErikPelli merged commit afeff06 into elazarl:master Jan 10, 2025
1 check passed
@ErikPelli
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HAR dumper
2 participants