-
Notifications
You must be signed in to change notification settings - Fork 336
Fix: Spring 7 Webflux NoSuchElementError on HttpHeaders#entrySet() #4556
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
Open
mtomik
wants to merge
11
commits into
elastic:main
Choose a base branch
from
mtomik:fix/webflux-spring-7-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
71d6975
fix(webflux): fix NoSuchMethodError when using spring framework 7 wit…
jihad-bouhaiji 705cac4
fix(webflux): fix compilation
jihad-bouhaiji 9678d44
fix(webflux): fix compilation errors + provide spring 7 testing module
jihad-bouhaiji f3ba94a
fix(webflux): fix comment
jihad-bouhaiji 64762d2
fix(webflux): Specify allow method TRACE in the config
jihad-bouhaiji ecde26e
fix(webflux): fix comments + fix discard subscription on close
mtomik a56fc87
fix(webflux): fix comments
mtomik 0f0435f
fix(webflux): add sub cancel instrumentation
mtomik 47fbdec
fix(webflux): fix sub cancel test
mtomik 1a4387b
fix(webflux): rem debug test logs
mtomik f487029
Merge branch 'main' into fix/webflux-spring-7-support
jackshirazi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
...-plugin/src/main/java/co/elastic/apm/agent/reactor/SubscriptionCancelInstrumentation.java
This file contains hidden or 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,72 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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 co.elastic.apm.agent.reactor; | ||
|
|
||
| import co.elastic.apm.agent.sdk.ElasticApmInstrumentation; | ||
| import net.bytebuddy.asm.Advice; | ||
| import net.bytebuddy.description.method.MethodDescription; | ||
| import net.bytebuddy.description.type.TypeDescription; | ||
| import net.bytebuddy.matcher.ElementMatcher; | ||
| import org.reactivestreams.Subscription; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| import static co.elastic.apm.agent.sdk.bytebuddy.CustomElementMatchers.classLoaderCanLoadClass; | ||
| import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isInterface; | ||
| import static net.bytebuddy.matcher.ElementMatchers.named; | ||
| import static net.bytebuddy.matcher.ElementMatchers.not; | ||
| import static net.bytebuddy.matcher.ElementMatchers.takesArguments; | ||
|
|
||
| public class SubscriptionCancelInstrumentation extends ElasticApmInstrumentation { | ||
|
|
||
| @Override | ||
| public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() { | ||
| return classLoaderCanLoadClass("reactor.core.CoreSubscriber"); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
| return not(isInterface()).and(hasSuperType(named("org.reactivestreams.Subscription"))); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super MethodDescription> getMethodMatcher() { | ||
| return named("cancel").and(takesArguments(0)); | ||
| } | ||
|
|
||
| @Override | ||
| public Collection<String> getInstrumentationGroupNames() { | ||
| return Collections.singleton("reactor"); | ||
| } | ||
|
|
||
| @Override | ||
| public String getAdviceClassName() { | ||
| return "co.elastic.apm.agent.reactor.SubscriptionCancelInstrumentation$CancelAdvice"; | ||
| } | ||
|
|
||
| public static class CancelAdvice { | ||
|
|
||
| @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false) | ||
| public static void afterCancel(@Advice.This Subscription subscription) { | ||
| TracedSubscriber.onCancel(subscription); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
...n/src/main/resources/META-INF/services/co.elastic.apm.agent.sdk.ElasticApmInstrumentation
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| co.elastic.apm.agent.reactor.ReactorInstrumentation | ||
| co.elastic.apm.agent.reactor.SubscriptionCancelInstrumentation |
This file contains hidden or 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
112 changes: 112 additions & 0 deletions
112
apm-agent-plugins/apm-spring-webflux/apm-spring-webflux-plugin-spring7/pom.xml
This file contains hidden or 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,112 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <artifactId>apm-spring-webflux</artifactId> | ||
| <version>1.56.1-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>apm-spring-webflux-plugin-spring7</artifactId> | ||
| <name>${project.groupId}:${project.artifactId}</name> | ||
|
|
||
| <properties> | ||
| <!-- for licence header plugin --> | ||
| <apm-agent-parent.base.dir>${project.basedir}/../../..</apm-agent-parent.base.dir> | ||
|
|
||
| <animal.sniffer.skip>true</animal.sniffer.skip> | ||
| </properties> | ||
|
|
||
| <dependencyManagement> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-dependencies</artifactId> | ||
| <version>${version.spring-boot-4}</version> | ||
| <type>pom</type> | ||
| <scope>import</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </dependencyManagement> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>apm-spring-webflux-spring5</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <!-- through the spring-boot dependency management, the test app will be "updated" to spring boot 4 --> | ||
| <groupId>${project.groupId}</groupId> | ||
| <artifactId>apm-spring-webflux-testapp-spring7</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.springframework</groupId> | ||
| <artifactId>spring-web</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.projectreactor</groupId> | ||
| <artifactId>reactor-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <artifactId>apm-spring-webflux-spring5</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| <type>test-jar</type> | ||
| </dependency> | ||
|
|
||
| <!-- required for context-propagation during tests, but only at runtime --> | ||
| <dependency> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <artifactId>apm-reactor-plugin</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>co.elastic.apm</groupId> | ||
| <artifactId>apm-reactor-plugin</artifactId> | ||
| <version>${project.version}</version> | ||
| <scope>test</scope> | ||
| <type>test-jar</type> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.ivy</groupId> | ||
| <artifactId>ivy</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
|
|
||
|
jackshirazi marked this conversation as resolved.
|
||
| <profiles> | ||
| <profile> | ||
| <!-- Spring Boot 4 / Spring Framework 7 requires junit 6 which requires java 17 --> | ||
| <id>testing-jdk-11</id> | ||
| <activation> | ||
| <property> | ||
| <name>test_java_version</name> | ||
| <value>11</value> | ||
| </property> | ||
| </activation> | ||
| <properties> | ||
| <skipTests>true</skipTests> | ||
| </properties> | ||
| </profile> | ||
| </profiles> | ||
|
|
||
| </project> | ||
32 changes: 32 additions & 0 deletions
32
...gin-spring7/src/test/java/co/elastic/apm/agent/springwebflux/Spring7HeaderGetterTest.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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 co.elastic.apm.agent.springwebflux; | ||
|
|
||
| import co.elastic.apm.agent.testutils.Java17OnlyTest; | ||
|
|
||
| public class Spring7HeaderGetterTest extends Java17OnlyTest { | ||
|
|
||
| public Spring7HeaderGetterTest() { | ||
| super(Impl.class); | ||
| } | ||
|
|
||
| public static class Impl extends HeaderGetterTest { | ||
|
|
||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
...st/java/co/elastic/apm/agent/springwebflux/Spring7ServerAnnotatedInstrumentationTest.java
This file contains hidden or 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,32 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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 co.elastic.apm.agent.springwebflux; | ||
|
|
||
|
|
||
| import co.elastic.apm.agent.testutils.Java17OnlyTest; | ||
|
|
||
| public class Spring7ServerAnnotatedInstrumentationTest extends Java17OnlyTest { | ||
|
|
||
| public Spring7ServerAnnotatedInstrumentationTest() { | ||
| super(Impl.class); | ||
| } | ||
|
|
||
| public static class Impl extends ServerAnnotatedInstrumentationTest { | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...t/java/co/elastic/apm/agent/springwebflux/Spring7ServerFunctionalInstrumentationTest.java
This file contains hidden or 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,31 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. 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 co.elastic.apm.agent.springwebflux; | ||
|
|
||
| import co.elastic.apm.agent.testutils.Java17OnlyTest; | ||
|
|
||
| public class Spring7ServerFunctionalInstrumentationTest extends Java17OnlyTest { | ||
|
|
||
| public Spring7ServerFunctionalInstrumentationTest() { | ||
| super(Impl.class); | ||
| } | ||
|
|
||
| public static class Impl extends ServerFunctionalInstrumentationTest { | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a common name to all the implementations we need to instrument here ? the
hasSuperTypeis very expensive withoutgetTypeMatcherPreFilter, so if possible addinggetTypeMatcherPreFilterwould be relevant here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only I can think of is something like this, but that probably will not narrow it much, right?
or maybe have multiple these instrumentations by package/library that implements the CoreSubscriber ? or have just one for the implementations from
reactor.coreand the rest will be cleaned potentially by the GC later?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be fine as a first step, do you have a list of all the classes that are being currently instrumented here to verify all of them match ? If those are spring classes I would expect them to stay consistently named. If those are user-provided then it might be too narrow and we need another approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the problem is, that there can come any implementation of
CoreSubscriber. if we miss some thanks to this filter, theTracedSubscriberwill not remove it immediately from itscontextMap/subscriptionMap.if I understand it correctly, the memory leak caused by this was always handled by GC. in this newer spring 7 came newer reactor or other library that allowed us to spot it more easily? that was at least my thought...
I had here another solution to solve it - the wrapper around that subscription (ecde26e) , but I had there compile issue with the older java versions. so maybe just try to solve that to avoid using this instrumentation?