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

exim: Use har-reader #5250

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

kingthorin
Copy link
Member

@kingthorin kingthorin commented Jan 26, 2024

Overview

  • CHANGELOG > Added change note.
  • build file > Updated/added dependencies.
  • HarImporter > Re-worked to use har-reader lib.
  • HarUtils > Extensively added to to facilitate use of the new lib.
  • MenuImportHar > Re-worked and simplified to take advantage of the new utils, importer, and lib.
  • HarImporterUnitTest > Tweaked to accommodate HarImporter changes.

Related Issues

NA

Checklist

  • Update help
  • Update changelog
  • Run ./gradlew spotlessApply for code formatting
  • Write tests
  • Check code coverage
  • Sign-off commits
  • Squash commits
  • Use a descriptive title

Comment on lines 223 to 226
if ((name.equalsIgnoreCase(HttpFieldsNames.CACHE_CONTROL)
|| name.equalsIgnoreCase(HttpFieldsNames.SET_COOKIE))
&& (value.contains("\n") || value.contains("\r"))) {
i.setValue(i.getValue().replaceAll("[\r\n]", ", "));
Copy link
Member Author

Choose a reason for hiding this comment

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

Should I just do this in all headers? I have no idea why the samples are like this, but these headers were where I encountered the issue 🤷‍♂️

* @see <a href="http://www.softwareishard.com/blog/har-12-spec/">HTTP Archive 1.2</a>
* @see HttpMessage
*/
public final class HarUtils {
Copy link
Member Author

Choose a reason for hiding this comment

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

This is largely an updated version of what's in core. ~85% of the code is duplicated.

Copy link
Member

Choose a reason for hiding this comment

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

Is this one going to replace the core class to export?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the long run I guess. It depends what we do with the "search" extension usage?

Copy link
Member

Choose a reason for hiding this comment

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

Once we move that out of core it can use "this" one too, I'm asking to know if more code is needed for this one. We should add a comment that custom fields are not yet migrated to this class (or add them now? I assume the new lib supports them).

Copy link
Member Author

Choose a reason for hiding this comment

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

I hadn't really handled any of the export related functionality. We might have to use jackson for that, the lib used here is very read centric.

Copy link
Member

Choose a reason for hiding this comment

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

Almost all code is for export functionality (starting in createZapHarLog() and following methods). It looks like it has setAdditionalField for custom fields. We would have to use Jackson (or rely on it anyway).

@kingthorin
Copy link
Member Author

Removed the inner classes, still need to tweak the HTTP Version handling.

@kingthorin
Copy link
Member Author

I've adjusted the version handling now. I believe this now has all the previously discussed changes.

@thc202
Copy link
Member

thc202 commented May 21, 2024

I'd do a final review later in the day.

List<HttpMessage> messages =
HarImporter.getHttpMessages(new HarFileReader().readHarFile(file));
int count = 1;
private HarLog preProcessHarLog(HarLog log) {
Copy link
Member

Choose a reason for hiding this comment

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

Would be great to have tests that cover these preprocessing checks.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I mentioned this in an email or the Friday notes at some point. I'd like to add all the HAR files we've collected along the way and use those for tests if there's no objection. None of them are terribly huge, and it's just text so it compresses well (for git operations etc).

Copy link
Member

Choose a reason for hiding this comment

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

We should still have specific tests for these, as it's easier to see what input tests what.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do both?

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with both.

Copy link
Member

Choose a reason for hiding this comment

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

Better to verify the messages are imported with the expected content (that's the most important).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair, just gotta get the tests behaving well first.

@kingthorin
Copy link
Member Author

I think I got all the comments, just need to add tests. Please lemme know if I've missed something.

@kingthorin kingthorin force-pushed the exim-har-reader branch 2 times, most recently from 092c58a to bd49ab6 Compare May 23, 2024 01:05
@kingthorin
Copy link
Member Author

I started to add tests. There were a number of challenges. I'll add some comments to cover those.

The tests will fail, they succeed individually but there seems to be some sort of concurrency or cleanup issue when run together.

@thc202
Copy link
Member

thc202 commented May 23, 2024

#5250 (comment)

The logger should be set up for each test not all of them, also better to call Configurator.reconfigure(getClass().getResource("/log4j2-test.properties").toURI()); to reset the configuration to previous state. (To be clear that does not fix the test failures, there are still some tests that need further changes, like setting up some more mocking and the messages.)

@kingthorin kingthorin force-pushed the exim-har-reader branch 2 times, most recently from 67a8efc to 98d875f Compare May 23, 2024 10:35
@thc202
Copy link
Member

thc202 commented May 23, 2024

I was not clear with #5250 (comment) I meant that the logger should be initialised in a BeforeEach rather than BeforeAll, sorry.

@kingthorin
Copy link
Member Author

Okay I've updated a bunch of stuff. Things are a bit better. The log handling was ripped off from GraphQL tests. I had to put your reconfigure suggestion in each method because AfterAll is static and didn't like me using getClass (and I couldn't figure out an alternative to getClass).

Using mockMessages didn't seem to fix the console barf, the key is there so I don't get the issue....

Can you think of another place we've done mocking to handle persisting messages? I think I recall talking about this for another PR but I can't figure out what it was.

@thc202
Copy link
Member

thc202 commented May 23, 2024

The log reset should be done after each test.

Let me look.

SpiderTaskUnitTest

@kingthorin kingthorin force-pushed the exim-har-reader branch 2 times, most recently from 1961879 to 4279b38 Compare May 23, 2024 11:08
@kingthorin
Copy link
Member Author

Getting closer... 🤷‍♂️

@thc202
Copy link
Member

thc202 commented May 23, 2024

Change to extHistory = mock(ExtensionHistory.class);.

@kingthorin
Copy link
Member Author

kingthorin commented May 23, 2024

Latest changes bring me back to getResourcePath claiming to be null when using getHtml

Edit: Doing a gradle refresh to see if it helps/matters.

@kingthorin
Copy link
Member Author

Wow it actually did help....and on a Linux VM 😕

@kingthorin
Copy link
Member Author

Hrm missing something in cleanup I guess. UrlImporter test now failing 😢

@thc202
Copy link
Member

thc202 commented May 23, 2024

It's trying to send the requests :)

@kingthorin
Copy link
Member Author

As discussed via slack, instead of dropping h3 requests they could probably be treated as http/2.

@kingthorin kingthorin force-pushed the exim-har-reader branch 4 times, most recently from 48f7c92 to 6151e4e Compare May 30, 2024 13:29
- CHANGELOG > Added change note.
- build file > Updated/added dependencies.
- HarImporter > Re-worked to use har-reader lib.
- HarUtils > Extensively added to to facilitate use of the new lib.
- MenuImportHar > Re-worked and simplified to take advantage of the new
utils, importer, and lib.
- HarImporterUnitTest > Tweaked to accommodate HarImporter changes.

Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
@kingthorin
Copy link
Member Author

I still have more testing to add but it's coming together

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