-
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
17
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
17 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 b11b794
fix(webflux): optimize inst name matcher
mtomik 1b67ee2
fix(webflux): non-instrument solution
mtomik 83508ca
Revert "fix(webflux): non-instrument solution"
mtomik 1032fc8
Merge remote-tracking branch 'upstream/main' into fix/webflux-spring-…
mtomik 9ddab5b
fix(webflux): header copy NPE on cancelled subscription
mtomik 3448be7
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
82 changes: 82 additions & 0 deletions
82
...-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,82 @@ | ||
| /* | ||
| * 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.NamedElement; | ||
| 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.declaresMethod; | ||
| import static net.bytebuddy.matcher.ElementMatchers.hasSuperType; | ||
| import static net.bytebuddy.matcher.ElementMatchers.isInterface; | ||
| import static net.bytebuddy.matcher.ElementMatchers.nameContains; | ||
| 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 NamedElement> getTypeMatcherPreFilter() { | ||
| return nameContains("Subscriber").or(nameContains("Subscription")); | ||
| } | ||
|
|
||
| @Override | ||
| public ElementMatcher<? super TypeDescription> getTypeMatcher() { | ||
|
SylvainJuge marked this conversation as resolved.
|
||
| return not(isInterface()) | ||
| .and(declaresMethod(getMethodMatcher())) | ||
| .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 { | ||
| } | ||
| } |
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.
I think there are a bunch in reactor that don't use those in the names. Maybe add that as a special case?
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.
Asking an LLM to find known implementations of
Subscriptionyields the following list, soreactor.is a good prefix, we might also addio.reactivex.andio.smallrye.mutiny.but I'm definitely not familiar with any of those reactor frameworks. Here it would not hurt to have a few false positives rather than lots of false positives creating lots of useless overhead, so this should be fine as a first step, and we can refine further if needed.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.
one drawback of this additional name matching is increased instruction time spent. So I run the numbers again:
current filter
OR starts with "reactor."
OR all 3 starts with you mentioned
if we want to optimize the filter even further - with something like just
nameEndsWith("Subscriber")we cover most of them with just this overhead.the
nameContains("Subscription")was there just to match it even when someone did his own implementation - bigger chance that we catch itnameEndsWith("Subscriber") OR all 3 your package prefixes
the thing is that if we miss some of them, we just rely on GC to clean it up later. so it just about finding that balance I guess 😄 but at the end, every one of these will be better than it was before, where we missed all of them