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

[Logging] Refactor ESLoggerUsageChecker #58962

Closed
wants to merge 3 commits into from

Conversation

tumile
Copy link
Contributor

@tumile tumile commented Jul 2, 2020

Refers to #49087

This is a draft PR to refactor ESLoggerUsageChecker, a static analysis tool to verify correct usages of logger. Here are the steps taken to improve the structure of the code

  • move WrongLoggerUsage class into its own file

  • move ClassChecker into its own file

  • move MethodChecker into its own file, along with all static Type since this is the only place they are referenced

  • move all BasicValue and BasicInterpreter subclasses into MethodChecker.java as well since they are not used anywhere else

  • Inside MethodChecker.java

  • refactor findBadLoggerUsages, which is where the bulk of checks are

    • make lineNumber, methodNode, instructions, logMessageFrames, arraySizeFrames instance variables since they are accessed in multiple methods and avoid passing around too much
    • findBadLoggerUsages is broken down to 2 methods
      • analyzeMethod to populate instructions, logMessageFrames, arraySizeFrames
      • walkInstructions to check each instructions
    • walkInstructions checks for Opcode and call verifyMethodUsage or verifyConstructorUsage with necessary arguments
    • verifyMethodUsage is renamed from old verifyLoggerUsage
    • verifyConstructorUsage is extracted from old findBadLoggerUsages
    • the above two will in turn call checkFixedArityArgs or checkArrayArgs
    • the rest is kept semantically the same
  • fix SonarLint warnings

@tumile
Copy link
Contributor Author

tumile commented Jul 2, 2020

Pinging @pgomulka

@pgomulka pgomulka self-requested a review July 2, 2020 19:54
@pgomulka
Copy link
Contributor

pgomulka commented Jul 2, 2020

ok to test

@tumile

This comment has been minimized.

@tumile tumile marked this pull request as ready for review July 3, 2020 02:09
Copy link
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

hey @tumile
thank you for your interest in Elasticsearch, but I will have to close this PR for the time being. As I mentioned in #49087 (comment) the expectation was to discuss possible solutions first, before making refactoring.
I was hoping that there is a 3rd party lib that would achieve what we do there. The refactoring itself would require a fairly complex DSL, possibly migrating to a different byte manipulation library.

@pgomulka pgomulka closed this Jul 6, 2020
@tumile
Copy link
Contributor Author

tumile commented Jul 8, 2020

Thanks for letting me know. I misunderstood the requirement there. Will be more careful next time!

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.

2 participants