-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-47602][CORE] Resource managers: Migrate logError with variable…
…s to structured logging framework ### What changes were proposed in this pull request? The pr aims to: - migrate `logError` in module `Resource managers` with variables to `structured logging framework`. - add some test case to `*LoggingSuite` - add new UT `MDCSuite` - make the `type` of `value` from `String` to `Any`( so that when using `MDC`, some code can be `omitted`, eg: `String.valueOf(...)` , `x.toString`) ### Why are the changes needed? To enhance Apache Spark's logging system by implementing structured logging. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? - Pass GA. - Add & update new UT. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #45808 from panbingkun/SPARK-47602. Authored-by: panbingkun <[email protected]> Signed-off-by: Gengliang Wang <[email protected]>
- Loading branch information
1 parent
8d4e964
commit db0975c
Showing
11 changed files
with
133 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
common/utils/src/test/scala/org/apache/spark/util/MDCSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.util | ||
|
||
import scala.jdk.CollectionConverters._ | ||
|
||
import org.scalatest.funsuite.AnyFunSuite // scalastyle:ignore funsuite | ||
|
||
import org.apache.spark.internal.{Logging, MDC} | ||
import org.apache.spark.internal.LogKey.EXIT_CODE | ||
|
||
class MDCSuite | ||
extends AnyFunSuite // scalastyle:ignore funsuite | ||
with Logging { | ||
|
||
test("check MDC message") { | ||
val log = log"This is a log, exitcode ${MDC(EXIT_CODE, 10086)}" | ||
assert(log.message === "This is a log, exitcode 10086") | ||
assert(log.context === Map("exit_code" -> "10086").asJava) | ||
} | ||
|
||
test("custom object as MDC value") { | ||
val cov = CustomObjectValue("spark", 10086) | ||
val log = log"This is a log, exitcode ${MDC(EXIT_CODE, cov)}" | ||
assert(log.message === "This is a log, exitcode CustomObjectValue: spark, 10086") | ||
assert(log.context === Map("exit_code" -> "CustomObjectValue: spark, 10086").asJava) | ||
} | ||
|
||
case class CustomObjectValue(key: String, value: Int) { | ||
override def toString: String = { | ||
"CustomObjectValue: " + key + ", " + value | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters