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

test: reducing logspam #5022

Merged
merged 20 commits into from
Jun 4, 2022
Merged

test: reducing logspam #5022

merged 20 commits into from
Jun 4, 2022

Conversation

keturn
Copy link
Member

@keturn keturn commented May 23, 2022

I've never been happy with the setupLogging method I added to MTE. Now that it's a year later and we no longer have the engine-tests/MTE split to worry about, I might understand things well enough to do better.

Contains

  • A logback configuration file to be used by default during module tests. Run groovyw module refresh to add this logback-test.xml to your workspace.

  • A new syntax to exclude log messages using a regular expression.

[ example filter configuration, before and after ]

Before, using logback-classic matchers as documented:

    <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
      <evaluator>
        <matcher>
          <Name>reflectionsEmpty</Name>
          <regex>given scan urls are empty</regex>
        </matcher>
        <expression>reflectionsEmpty.matches(message)</expression>
      </evaluator>
      <OnMismatch>NEUTRAL</OnMismatch>
      <OnMatch>DENY</OnMatch>
    </filter>

After:

<denyRegex prefix="org.reflections" message="given scan urls are empty" />

  • Refactorings to reduce the duplication of the fiddly bits of log configuration between engine tests, module tests, and production (the PC facade).

Implementation Goals:

  • All test tasks should be able to filter logs with logback.
  • Test frameworks like JUnit should be test* dependencies.
    • except code in engine-tests/src/main that builds on JUnit APIs for use by external module tests, then:
      • api if classes/interfaces from it show up on public method signatures.
      • otherwise implementation if it's needed to compile but not publicly visible.
  • Only the edges (facade, test runners) should define a logging backend (logback).
    • except the code that uses specific logback classes. Which is multiple things in engine, and logback 1.2 isn't structured in a way that facilitates making complete logback extensions from logback-core alone; you often have to pull in logback-classic to do anything useful. This largely breaks the "let the edges pick their own logging backend" architecture I wanted, but the least we can do is not conflict with any logback.xml a downstream consumer wants to set up.

How to test

Run some engine tests, run some module tests, see if you can figure out how to include or exclude the log messages you want during your test output.

Outstanding before merging

Include with Merge

@keturn keturn added Type: Improvement Request for or addition/enhancement of a feature Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance Size: S Small effort likely only affecting a single area and requiring little to no research labels May 23, 2022
@github-actions github-actions bot added the Category: Build/CI Requests, Issues and Changes targeting gradle, groovy, Jenkins, etc. label May 23, 2022
@keturn keturn force-pushed the test/logspamReduction branch from 3d86d4c to 9bca6ef Compare May 23, 2022 20:01
@keturn
Copy link
Member Author

keturn commented May 23, 2022

In this branch's current state, things work fine for engine-tests. If you look at the console output for the integrationTest step, there's only the warnings from Java itself: https://jenkins.terasology.io/teraorg/job/Terasology/job/engine/view/change-requests/job/PR-5022/2/pipeline-console/

and when you look at the output for a specific test, you see it has some: https://jenkins.terasology.io/teraorg/job/Terasology/job/engine/view/change-requests/job/PR-5022/2/testReport/org.terasology.engine.integrationenvironment/MTEExtensionTestWithPerClassLifecycle/Integration_Tests___firstTestFindsThings__/

(The ...[truncated 19025 chars]... there is Jenkins, not the test execution. Its threshold for output on passing tests is very small. It keeps a bit more for failed tests.)

The thing I haven't checked yet, and I expect is not filtered, is the output of module tests.

@keturn
Copy link
Member Author

keturn commented May 24, 2022

Things to know about junit and logging: JUnit uses java.util.logging. We consolidate that with our own slf4j-based logging using jul-to-slf4j.

keturn added 11 commits May 26, 2022 13:06
We only use xml for configs and it's just extra noise.
Excludes
- reflections "given scan urls are empty": wontfix
- reflections errors on benchmark classes: wontfix, engine doesn't need to Reflect on them
- engine.i18n info-level messages: rarely relevant to test execution
So when Jenkins truncates the part you wanted to see, you can get download the whole thing and look at it locally.

build(jenkins): include the default logback.xml in artifacts

So the module build job can pick it up if the module didn't bring their own.
Goals:
- Only the edges (facade, test runners) should define a logging backend (logback)
  - except the code that uses specific logback classes
      (and maybe that should be only logback-core, but that's another story)
- All test tasks should be able to filter logs with logback
- Test frameworks like JUnit should be `test*` dependencies
  - except code in engine-tests/src/main that builds on JUnit APIs for use by external module tests
Easier to use and much lighter requirements than Janino or Groovy.
and add some comments for documentation
installed by `groovyw module refresh`
@keturn keturn force-pushed the test/logspamReduction branch from 5020499 to c670b39 Compare May 26, 2022 20:18
@jdrueckert jdrueckert merged commit 8a7219b into develop Jun 4, 2022
@jdrueckert jdrueckert deleted the test/logspamReduction branch June 4, 2022 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Build/CI Requests, Issues and Changes targeting gradle, groovy, Jenkins, etc. Category: Test/QA Requests, Issues and Changes targeting tests and quality assurance Size: S Small effort likely only affecting a single area and requiring little to no research Type: Improvement Request for or addition/enhancement of a feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants