Skip to content

[SPARK-37805][TESTS] Refactor TestUtils#configTestLog4j method to use log4j2 api #35095

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

Closed

Conversation

LuciferYang
Copy link
Contributor

@LuciferYang LuciferYang commented Jan 4, 2022

What changes were proposed in this pull request?

SPARK-37795 add a scalastyle rule to ban org.apache.log4j imports, but there is still one place to retain the imports of org.apache.log4j in o.a.spark.TestUtils.

This pr refactor configTestLog4j method in o.a.spark.TestUtils to use log4j2 api and let the log behavior using log4j2.x be the same as that using log4j1.x before. In fact, the configTestLog4j method behavior before this pr is invalid because PropertyConfigurator.configure method in org.apache.logging.log4j:log4j-1.2-api is an empty method as follows:

https://github.com/apache/logging-log4j2/blob/491a0b3787975b6fc95b6a8cb3da76dc7517c65f/log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java#L39-L47

Another change of this pr is rename the method name from configTestLog4j to configTestLog4j2.

Why are the changes needed?

Clean up the org.apache.log4j imports left in Spark internal and let configTestLog4j method behavior keep consistent between log4j1.x and log4j2.x.

Does this PR introduce any user-facing change?

The configTestLog4j method in TestUtils rename to configTestLog4j2

How was this patch tested?

  • Pass the Jenkins or GitHub Action
  • Manual test

Run the test cases using configTestLog4j method in the following 3 scenarios:

  1. without this pr to test log4j2.x
  2. with this pr to test log4j2.x
  3. run git reset --hard 19227983e91a54b5f27ade6412dad1088dfcba9e to test log4j1.x

For example WholeStageCodegenSparkSubmitSuite, run

mvn clean install -DskipTests -pl sql/core -am
mvn test -pl sql/core -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.WholeStageCodegenSparkSubmitSuite

Scenario 1 does not print any logs to the console, scenario 2 and scenario 3 will print similar logs to the console

@LuciferYang
Copy link
Contributor Author

cc @dongjoon-hyun

@dongjoon-hyun
Copy link
Member

cc @viirya

@dongjoon-hyun
Copy link
Member

FYI, @LuciferYang . It was intentionally ignored at that time after discussing with @williamhyun offline.

@LuciferYang
Copy link
Contributor Author

FYI, @LuciferYang . It was intentionally ignored at that time after discussing with @williamhyun offline.

What is the specific reason? I didn't find it in SPARK-37795

@LuciferYang
Copy link
Contributor Author

GA run failed,Let me check it first

@LuciferYang
Copy link
Contributor Author

GA Passed

builder.add(appenderBuilder)
builder.add(builder.newRootLogger(s"$level").add(builder.newAppenderRef("console")))
val configuration = builder.build()
LogManager.getContext(false).asInstanceOf[LoggerContext].reconfigure(configuration)
Copy link
Member

Choose a reason for hiding this comment

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

This rewriting looks okay. I just wonder the purpose of configTestLog4j and if it is necessary. These tests are not checking the log (as they are still passed with no-op configTestLog4j now). And seems it is not used to reduce verbose logging.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can just remove configTestLog4j?

Copy link
Contributor Author

@LuciferYang LuciferYang Jan 5, 2022

Choose a reason for hiding this comment

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

I traced back to the original pr (SPARK-3193), it seems that configTestLog4j is only added to help troubleshoot the failed UT on Jenkins about the Process exitcode != 0

I agree to remove this method directly,(EDIT) what do you think @dongjoon-hyun ?

Copy link
Contributor Author

@LuciferYang LuciferYang Jan 5, 2022

Choose a reason for hiding this comment

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

Hmm... It seems that the method of calling configTestLog4j in the current UTs is in the process of runSparkSubmit. If we directly remove this method, I can not find out where to see the relevant log of runSparkSubmit (not in target/unit-tests.log), which is really not conducive to troubleshooting.

Copy link
Member

Choose a reason for hiding this comment

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

Then it is okay to keep it, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok ~

appenderBuilder.add(builder.newLayout("PatternLayout")
.addAttribute("pattern", "%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n"))
builder.add(appenderBuilder)
builder.add(builder.newRootLogger(s"$level").add(builder.newAppenderRef("console")))
Copy link
Member

Choose a reason for hiding this comment

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

s"$level" -> level. level is already a string, no need to interpolate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc06076 fix 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.

@viirya Any other need change?

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 not sure about #35095 (comment).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

@srowen srowen left a comment

Choose a reason for hiding this comment

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

Looks OK pending tests

@LuciferYang
Copy link
Contributor Author

8d0a078 merge with master

@LuciferYang
Copy link
Contributor Author

Looks OK pending tests

GA passed

@LuciferYang LuciferYang requested a review from srowen January 12, 2022 02:28
@srowen
Copy link
Member

srowen commented Jan 13, 2022

Merged to master

@srowen srowen closed this in f3eedaf Jan 13, 2022
@LuciferYang
Copy link
Contributor Author

thanks all

dchvn pushed a commit to dchvn/spark that referenced this pull request Jan 19, 2022
…se log4j2 api

### What changes were proposed in this pull request?
SPARK-37795 add a scalastyle rule to ban `org.apache.log4j` imports, but there is still one place to retain the imports of `org.apache.log4j` in `o.a.spark.TestUtils`.

This pr refactor `configTestLog4j` method in `o.a.spark.TestUtils` to use log4j2 api and let the log behavior using log4j2.x be the same as that using log4j1.x before. In fact, the `configTestLog4j` method behavior before this pr is invalid because `PropertyConfigurator.configure` method in `org.apache.logging.log4j:log4j-1.2-api` is an empty method as follows:

https://github.com/apache/logging-log4j2/blob/491a0b3787975b6fc95b6a8cb3da76dc7517c65f/log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java#L39-L47

Another change of this pr is rename the method name from `configTestLog4j`  to `configTestLog4j2`.

### Why are the changes needed?
Clean up the `org.apache.log4j` imports left in Spark internal and let `configTestLog4j` method behavior keep consistent between log4j1.x and log4j2.x.

### Does this PR introduce _any_ user-facing change?
The  `configTestLog4j` method in `TestUtils` rename to `configTestLog4j2`

### How was this patch tested?

- Pass the Jenkins or GitHub Action
- Manual test

Run the test cases using `configTestLog4j` method in the following 3 scenarios:

1. without this pr to test log4j2.x
2. with this pr to test log4j2.x
3. run `git reset --hard 1922798` to test log4j1.x

For example `WholeStageCodegenSparkSubmitSuite`, run

```
mvn clean install -DskipTests -pl sql/core -am
mvn test -pl sql/core -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.WholeStageCodegenSparkSubmitSuite
```

Scenario 1 does not print any logs to the console, scenario 2 and scenario 3 will print similar logs to the console

Closes apache#35095 from LuciferYang/refactor-configTestLog4j.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
sumwale pushed a commit to TIBCOSoftware/snappy-spark that referenced this pull request Feb 9, 2022
…se log4j2 api

SPARK-37795 add a scalastyle rule to ban `org.apache.log4j` imports, but there is still one place to retain the imports of `org.apache.log4j` in `o.a.spark.TestUtils`.

This pr refactor `configTestLog4j` method in `o.a.spark.TestUtils` to use log4j2 api and let the log behavior using log4j2.x be the same as that using log4j1.x before. In fact, the `configTestLog4j` method behavior before this pr is invalid because `PropertyConfigurator.configure` method in `org.apache.logging.log4j:log4j-1.2-api` is an empty method as follows:

https://github.com/apache/logging-log4j2/blob/491a0b3787975b6fc95b6a8cb3da76dc7517c65f/log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java#L39-L47

Another change of this pr is rename the method name from `configTestLog4j`  to `configTestLog4j2`.

Clean up the `org.apache.log4j` imports left in Spark internal and let `configTestLog4j` method behavior keep consistent between log4j1.x and log4j2.x.

The  `configTestLog4j` method in `TestUtils` rename to `configTestLog4j2`

- Pass the Jenkins or GitHub Action
- Manual test

Run the test cases using `configTestLog4j` method in the following 3 scenarios:

1. without this pr to test log4j2.x
2. with this pr to test log4j2.x
3. run `git reset --hard 1922798` to test log4j1.x

For example `WholeStageCodegenSparkSubmitSuite`, run

```
mvn clean install -DskipTests -pl sql/core -am
mvn test -pl sql/core -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.WholeStageCodegenSparkSubmitSuite
```

Scenario 1 does not print any logs to the console, scenario 2 and scenario 3 will print similar logs to the console

Closes apache#35095 from LuciferYang/refactor-configTestLog4j.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
kazuyukitanimura pushed a commit to kazuyukitanimura/spark that referenced this pull request Aug 10, 2022
…se log4j2 api

### What changes were proposed in this pull request?
SPARK-37795 add a scalastyle rule to ban `org.apache.log4j` imports, but there is still one place to retain the imports of `org.apache.log4j` in `o.a.spark.TestUtils`.

This pr refactor `configTestLog4j` method in `o.a.spark.TestUtils` to use log4j2 api and let the log behavior using log4j2.x be the same as that using log4j1.x before. In fact, the `configTestLog4j` method behavior before this pr is invalid because `PropertyConfigurator.configure` method in `org.apache.logging.log4j:log4j-1.2-api` is an empty method as follows:

https://github.com/apache/logging-log4j2/blob/491a0b3787975b6fc95b6a8cb3da76dc7517c65f/log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java#L39-L47

Another change of this pr is rename the method name from `configTestLog4j`  to `configTestLog4j2`.

### Why are the changes needed?
Clean up the `org.apache.log4j` imports left in Spark internal and let `configTestLog4j` method behavior keep consistent between log4j1.x and log4j2.x.

### Does this PR introduce _any_ user-facing change?
The  `configTestLog4j` method in `TestUtils` rename to `configTestLog4j2`

### How was this patch tested?

- Pass the Jenkins or GitHub Action
- Manual test

Run the test cases using `configTestLog4j` method in the following 3 scenarios:

1. without this pr to test log4j2.x
2. with this pr to test log4j2.x
3. run `git reset --hard 1922798` to test log4j1.x

For example `WholeStageCodegenSparkSubmitSuite`, run

```
mvn clean install -DskipTests -pl sql/core -am
mvn test -pl sql/core -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.WholeStageCodegenSparkSubmitSuite
```

Scenario 1 does not print any logs to the console, scenario 2 and scenario 3 will print similar logs to the console

Closes apache#35095 from LuciferYang/refactor-configTestLog4j.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
asiunov pushed a commit to ascend-io/spark that referenced this pull request Aug 25, 2022
…se log4j2 api

### What changes were proposed in this pull request?
SPARK-37795 add a scalastyle rule to ban `org.apache.log4j` imports, but there is still one place to retain the imports of `org.apache.log4j` in `o.a.spark.TestUtils`.

This pr refactor `configTestLog4j` method in `o.a.spark.TestUtils` to use log4j2 api and let the log behavior using log4j2.x be the same as that using log4j1.x before. In fact, the `configTestLog4j` method behavior before this pr is invalid because `PropertyConfigurator.configure` method in `org.apache.logging.log4j:log4j-1.2-api` is an empty method as follows:

https://github.com/apache/logging-log4j2/blob/491a0b3787975b6fc95b6a8cb3da76dc7517c65f/log4j-1.2-api/src/main/java/org/apache/log4j/PropertyConfigurator.java#L39-L47

Another change of this pr is rename the method name from `configTestLog4j`  to `configTestLog4j2`.

### Why are the changes needed?
Clean up the `org.apache.log4j` imports left in Spark internal and let `configTestLog4j` method behavior keep consistent between log4j1.x and log4j2.x.

### Does this PR introduce _any_ user-facing change?
The  `configTestLog4j` method in `TestUtils` rename to `configTestLog4j2`

### How was this patch tested?

- Pass the Jenkins or GitHub Action
- Manual test

Run the test cases using `configTestLog4j` method in the following 3 scenarios:

1. without this pr to test log4j2.x
2. with this pr to test log4j2.x
3. run `git reset --hard 1922798` to test log4j1.x

For example `WholeStageCodegenSparkSubmitSuite`, run

```
mvn clean install -DskipTests -pl sql/core -am
mvn test -pl sql/core -Dtest=none -DwildcardSuites=org.apache.spark.sql.execution.WholeStageCodegenSparkSubmitSuite
```

Scenario 1 does not print any logs to the console, scenario 2 and scenario 3 will print similar logs to the console

Closes apache#35095 from LuciferYang/refactor-configTestLog4j.

Authored-by: yangjie01 <yangjie01@baidu.com>
Signed-off-by: Sean Owen <srowen@gmail.com>
(cherry picked from commit f3eedaf)
@LuciferYang LuciferYang deleted the refactor-configTestLog4j branch October 22, 2023 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants