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

[SPARK-48320][CORE][DOCS] Add structured logging guide to the scala and java doc #46634

Closed
wants to merge 16 commits into from

Conversation

panbingkun
Copy link
Contributor

@panbingkun panbingkun commented May 17, 2024

What changes were proposed in this pull request?

The pr aims to add external third-party ecosystem access guide to the scala/java doc.

The external third-party ecosystem is very extensive. Currently, the document covers two scenarios:

  • Pure java (for example, an application only uses the java language - many of our internal production applications are like this)
  • java + scala

Why are the changes needed?

Provide instructions for external third-party ecosystem access to the structured log framework.

Does this PR introduce any user-facing change?

Yes, When an external third-party ecosystem wants to access the structured log framework, developers can get help through this document.

How was this patch tested?

  • Add new UT.
  • Manually test.
  • Pass GA.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the DOCS label May 17, 2024
@@ -22,7 +22,7 @@ import java.util.Locale
* All structured logging `keys` used in `MDC` must be extends `LogKey`
*/
trait LogKey {
val name: String = this.toString.toLowerCase(Locale.ROOT)
def name: String = this.getClass.getSimpleName.stripSuffix("$").toLowerCase(Locale.ROOT)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we don't make such changes, the JavaCustomLogKeys(Custom LogKey that may be extended by external third-party ecosystems) class will have to be defined like this, which is very ugly and looks weird.
image

@@ -104,8 +112,8 @@ public void testBasicMsgLogger() {
Pair.of(Level.DEBUG, debugFn),
Pair.of(Level.TRACE, traceFn)).forEach(pair -> {
try {
assert (captureLogOutput(pair.getRight()).matches(
expectedPatternForBasicMsg(pair.getLeft())));
Assertions.assertTrue(captureLogOutput(pair.getRight()).matches(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replace assert with Assertions.assertTrue

@@ -140,15 +148,13 @@ public void testLoggerWithMDC() {
Runnable errorFn = () -> logger().error(msgWithMDC, executorIDMDC);
Runnable warnFn = () -> logger().warn(msgWithMDC, executorIDMDC);
Runnable infoFn = () -> logger().info(msgWithMDC, executorIDMDC);
Runnable debugFn = () -> logger().debug(msgWithMDC, executorIDMDC);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After #46405, the following 2 lines of code are no longer needed.

@panbingkun
Copy link
Contributor Author

cc @gengliangwang

@panbingkun panbingkun marked this pull request as ready for review May 17, 2024 07:57
@@ -22,7 +22,7 @@ import java.util.Locale
* All structured logging `keys` used in `MDC` must be extends `LogKey`
*/
trait LogKey {
val name: String = this.toString.toLowerCase(Locale.ROOT)
def name: String = this.getClass.getSimpleName.stripSuffix("$").toLowerCase(Locale.ROOT)
Copy link
Member

Choose a reason for hiding this comment

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

shall we have a val or a lazy val to memorize the key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, let's use lazy val, I have tested it and it works well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

public static final CUSTOM_LOG_KEY CUSTOM_LOG_KEY = new CUSTOM_LOG_KEY();
}
```
      and use it in `java` code:
Copy link
Member

Choose a reason for hiding this comment

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

why do we have &nbsp here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If &nbsp is not added, its indent looks incorrect, as shown below:
image

Let me incorporate this sentence into the above one, and revise it as follows:
image

* If you want to output logs in `scala code` through the structured log framework, you can define `custom LogKeys` as follows:

```scala
object CustomLogKeys {
Copy link
Member

Choose a reason for hiding this comment

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

let's not mention CustomLogKeys here. It is not necessary, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay


      when your project has **depended on `scala`**,
```scala
object CustomLogKeys {
Copy link
Member

Choose a reason for hiding this comment

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

the content seems duplicated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

1.Use the custom LogKey defined in the scala code, and use it in the scala code
2.Use the custom LogKey defined in the java code, and use it in the java code
3.Use the custom LogKey defined in the scala code, and use it in the java code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to delete the description of the last case - 3?

@panbingkun
Copy link
Contributor Author

panbingkun commented May 20, 2024

Final effect:
image

@panbingkun panbingkun changed the title [SPARK-48320][CORE][DOCS] Add external third-party ecosystem access guide to the doc [SPARK-48320][CORE][DOCS] Add external third-party ecosystem access guide to the scala/java doc May 22, 2024
Copy link
Contributor

@mridulm mridulm left a comment

Choose a reason for hiding this comment

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

Please replace all references to external and external system - we dont want to set expectations that external system integrations are encouraged.
Keep it as custom integrations instead - if power users and frameworks want to leverage the integration, this would be the path for them as it is not explicitly private [spark].

I added a few cases below, but I would expect @gengliangwang to be better aware and give much better guidance than what I can of what else might need to be changed - as he is more actively reviewing the PR's :-)

panbingkun and others added 4 commits May 23, 2024 10:18
Co-authored-by: Mridul Muralidharan <1591700+mridulm@users.noreply.github.com>
@panbingkun
Copy link
Contributor Author

Please replace all references to external and external system - we dont want to set expectations that external system integrations are encouraged. Keep it as custom integrations instead - if power users and frameworks want to leverage the integration, this would be the path for them as it is not explicitly private [spark].

I added a few cases below, but I would expect @gengliangwang to be better aware and give much better guidance than what I can of what else might need to be changed - as he is more actively reviewing the PR's :-)

Thank you very much for your patient and careful review. ❤️
I have updated it again.

Copy link
Contributor

@mridulm mridulm left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @panbingkun.
Looks good to me - I will let @gengliangwang review and merge; he is much more knowledgeable about this in general !

@panbingkun
Copy link
Contributor Author

Thanks for the changes @panbingkun. Looks good to me - I will let @gengliangwang review and merge; he is much more knowledgeable about this in general !

Yeah, Thank you very much! ❤️

Copy link
Member

Choose a reason for hiding this comment

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

@mridulm @panbingkun This README is for Spark developers. As long as it doesn't mention 3rd party supports, can we just keep 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.

I'm fine to it, WDYT @mridulm ?
we can just put the new description in the scala/java doc.

Copy link
Member

Choose a reason for hiding this comment

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

I will wait for @mridulm's response until this weekend.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC @panbingkun included the contents into the existing code; which is also a nice addition to the code documentation.
IMO that is a better overall approach given this is internal to spark.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay, I have adopted the plan of deleting README.md

@gengliangwang
Copy link
Member

LGTM except for one comment.

@github-actions github-actions bot removed the DOCS label May 24, 2024
@github-actions github-actions bot added the DOCS label May 25, 2024
@gengliangwang gengliangwang changed the title [SPARK-48320][CORE][DOCS] Add external third-party ecosystem access guide to the scala/java doc [SPARK-48320][CORE][DOCS] Add structured logging guide to the scala and java doc May 25, 2024
@gengliangwang
Copy link
Member

Thanks, merging to master

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