Skip to content

Conversation

@frankvicky
Copy link
Contributor

JIRA: KAFKA-18466

This PR is a patch for #17373 (comment)

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@github-actions github-actions bot added triage PRs from the community build Gradle build or GitHub Actions small Small PRs labels Jan 10, 2025
@chia7712
Copy link
Member

@frankvicky please build the distribution and Pom file and then check the content, thanks!

@frankvicky
Copy link
Contributor Author

POM file from local maven:
image

Content of libs after releaseTarGz:
image

@ppkarwasz
Copy link
Contributor

Similarly to apache/eventmesh#4700, I think that:

  • Not only log4j-1.2-api, but also log4j-slf4j-impl should be removed from the runtime dependencies of all artifacts.
  • log4j-core should be an optional runtime dependency in kafka_2_13 and connect-runtime.
  • I am not sure if log4j-api should be a direct dependency at all: you only use it in kafka_2_13 and connect-runtime, because you call log4j-core methods that have log4j-api types in the signature. IMHO it is OK to remove log4j-api and rely on the fact the log4j-core depends on log4j-api.

@chia7712
Copy link
Member

I totally agree @ppkarwasz's suggestion. Additionally, jackson-dataformat-yaml can be removed from runtime dependency too. Maybe log4j-core and log4j-api can be moved to compileOnly and then include them into distribution?

@ppkarwasz
Copy link
Contributor

Additionally, jackson-dataformat-yaml can be removed from runtime dependency too.

+1

Maybe log4j-core and log4j-api can be moved to compileOnly and then include them into distribution?

Gradle apparently has a feature for that, see Optional dependencies are not optional. With a snippet like:

java {
    registerFeature('loggingConfig') {
        usingSourceSet(sourceSets.main)
    }
}

it should be possible to:

  • declare log4j-core as a optional Maven dependency with a scope of runtime.
  • Gradle users will still be able to make import the transitive dependency using:
    implementation("org.apache.kafka:kafka_2_13") {
      capabilities {
        requireCapability("org.apache.kafka:kafka_2_13-logging-config")
      }
    }

@github-actions github-actions bot removed the small Small PRs label Jan 11, 2025
@frankvicky
Copy link
Contributor Author

I have adopted the feature variant at the latest commit.

generated pom:
Screenshot from 2025-01-11 15-06-52

Content of libs after releaseTarGz:
Screenshot from 2025-01-11 15-08-20

@frankvicky
Copy link
Contributor Author

Hi @ppkarwasz,

Should we make log4j-slf4j-impl an optional dependency?

I'm running the kafka e2e on my local machine, it would fail with following log:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

It seems we still need log4j-slf4j-impl at runtime. WDYT ?

Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

It seems we still need log4j-slf4j-impl at runtime. WDYT ?

please add the log4jRuntimeLibs to copyDependantLibs too. Our docker e2e depends on systemTestLibs task by default, and the task copies the dependencies to dependant-testlibs folder

build.gradle Outdated
}

dependencies {
loggingImplementation log4j2Libs
Copy link
Member

Choose a reason for hiding this comment

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

I think only core and connect-runtime needs to add log4j2Libs to compileOnly scope.

@frankvicky
Copy link
Contributor Author

I have run a few local tests to see if log4j works.
Quickstart:
Screenshot from 2025-01-12 01-16-15

connect-standalone:
Screenshot from 2025-01-12 01-18-56

e2e (connect_test.py):
Screenshot from 2025-01-12 01-19-41

@github-actions github-actions bot removed the triage PRs from the community label Jan 12, 2025
Copy link
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

LGTM

test the latest commit on my local.

chia7712@chia7712-ubuntu:~$ cat ~/.m2/repository/org/apache/kafka/kafka_2.13/4.1.0-SNAPSHOT/kafka_2.13-4.1.0-SNAPSHOT.pom | grep log4j
chia7712@chia7712-ubuntu:~$ 
chia7712@chia7712-ubuntu:~$ cat ~/.m2/repository/org/apache/kafka/kafka-clients/4.1.0-SNAPSHOT/kafka-clients-4.1.0-SNAPSHOT.pom | grep log4j
chia7712@chia7712-ubuntu:~$ cat ~/.m2/repository/org/apache/kafka/kafka-clients/4.1.0-SNAPSHOT/kafka-clients-4.1.0-SNAPSHOT.pom | grep slf4j
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
chia7712@chia7712-ubuntu:~$ cat ~/.m2/repository/org/apache/kafka/kafka-streams/4.1.0-SNAPSHOT/kafka-streams-4.1.0-SNAPSHOT.pom | grep log4j
chia7712@chia7712-ubuntu:~$ cat ~/.m2/repository/org/apache/kafka/kafka-streams/4.1.0-SNAPSHOT/kafka-streams-4.1.0-SNAPSHOT.pom | grep slf4j
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>

@chia7712
Copy link
Member

@ppkarwasz we don't use the Gradle’s feature variants in this PR due to following reasons.

  1. We do not expect users to include the optional dependencies. Instead, users should explicitly add their preferred SLF4j provider (including the specific version) to their project dependencies. If they also include a Log4j provider, they will need to resolve any potential conflicts.
  2. Utilizing configurations.releaseOnly can effectively add the necessary Log4j 2 dependencies to the classpath for end-to-end tests and scripts.

I will merge this PR to fix the issue reported by @trnguyencflt, but please feel free to leave suggestions as follow-up, thanks!

@chia7712 chia7712 merged commit b0b54f6 into apache:trunk Jan 12, 2025
9 checks passed
chia7712 pushed a commit that referenced this pull request Jan 12, 2025
@ppkarwasz
Copy link
Contributor

@ppkarwasz we don't use the Gradle’s feature variants in this PR due to following reasons.

1. We do not expect users to include the optional dependencies. Instead, users should explicitly add their preferred SLF4j provider (including the specific version) to their project dependencies. If they also include a Log4j provider, they will need to resolve any potential conflicts.

2. Utilizing `configurations.releaseOnly` can effectively add the necessary Log4j 2 dependencies to the classpath for end-to-end tests and scripts.

The PR looks good to me now. For a POM file having log4j-core as an optional runtime dependency or not having it at all is pretty much a matter of taste.

@ppkarwasz
Copy link
Contributor

@chia7712,

I have created #18496 to protect the two classes that use Log4j Core (k.util.Log4jController and o.a.k.connect.runtime.Loggers) from throwing a linkage error if Log4j Core is not present on the runtime classpath.

@trnguyencflt
Copy link

thanks all for the quick fix 👍

pranavt84 pushed a commit to pranavt84/kafka that referenced this pull request Jan 27, 2025
airlock-confluentinc bot pushed a commit to confluentinc/kafka that referenced this pull request Jan 27, 2025
manoj-mathivanan pushed a commit to manoj-mathivanan/kafka that referenced this pull request Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Gradle build or GitHub Actions ci-approved

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants