-
Notifications
You must be signed in to change notification settings - Fork 30
#213 Support spring cloud http3 #220
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
zinu-x
wants to merge
2
commits into
jd-opensource:main
Choose a base branch
from
zinu-x:213-support-spring-cloud-http3
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
2 commits
Select commit
Hold shift + click to select a range
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
54 changes: 54 additions & 0 deletions
54
...ive/agent/plugin/application/springboot/v2/definition/SpringNettyWebServerDefinition.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,54 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed 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 com.jd.live.agent.plugin.application.springboot.v2.definition; | ||
|
||
import com.jd.live.agent.core.bytekit.matcher.MatcherBuilder; | ||
import com.jd.live.agent.core.event.AgentEvent; | ||
import com.jd.live.agent.core.event.Publisher; | ||
import com.jd.live.agent.core.extension.annotation.ConditionalOnClass; | ||
import com.jd.live.agent.core.extension.annotation.Extension; | ||
import com.jd.live.agent.core.inject.annotation.Inject; | ||
import com.jd.live.agent.core.inject.annotation.Injectable; | ||
import com.jd.live.agent.core.plugin.definition.InterceptorDefinition; | ||
import com.jd.live.agent.core.plugin.definition.InterceptorDefinitionAdapter; | ||
import com.jd.live.agent.core.plugin.definition.PluginDefinition; | ||
import com.jd.live.agent.core.plugin.definition.PluginDefinitionAdapter; | ||
import com.jd.live.agent.governance.annotation.ConditionalOnGovernanceEnabled; | ||
import com.jd.live.agent.plugin.application.springboot.v2.interceptor.SpringCloudHttp3Interceptor; | ||
|
||
@Injectable | ||
@Extension(value = "SpringApplicationDefinition_v5", order = PluginDefinition.ORDER_APPLICATION) | ||
@ConditionalOnGovernanceEnabled | ||
@ConditionalOnClass(SpringNettyWebServerDefinition.TYPE_SPRING_NETTY_WEB_SERVER) | ||
@ConditionalOnClass(SpringNettyWebServerDefinition.TYPE_REACTOR_HTTP_SERVER) | ||
public class SpringNettyWebServerDefinition extends PluginDefinitionAdapter { | ||
|
||
protected static final String TYPE_SPRING_NETTY_WEB_SERVER = "org.springframework.boot.web.embedded.netty.NettyWebServer"; | ||
protected static final String TYPE_REACTOR_HTTP_SERVER = "reactor.netty.http.server.HttpServer"; | ||
|
||
private static final String METHOD_START = "start"; | ||
|
||
@Inject(Publisher.SYSTEM) | ||
private Publisher<AgentEvent> publisher; | ||
|
||
public SpringNettyWebServerDefinition() { | ||
this.matcher = () -> MatcherBuilder.named(TYPE_SPRING_NETTY_WEB_SERVER); | ||
this.interceptors = new InterceptorDefinition[]{ | ||
new InterceptorDefinitionAdapter(MatcherBuilder.named(METHOD_START), | ||
() -> new SpringCloudHttp3Interceptor(publisher)), | ||
}; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
.../live/agent/plugin/application/springboot/v2/interceptor/SpringCloudHttp3Interceptor.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,56 @@ | ||
/* | ||
* Copyright © ${year} ${owner} (${email}) | ||
* | ||
* Licensed 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 com.jd.live.agent.plugin.application.springboot.v2.interceptor; | ||
|
||
import com.jd.live.agent.bootstrap.bytekit.context.ExecutableContext; | ||
import com.jd.live.agent.core.event.AgentEvent; | ||
import com.jd.live.agent.core.event.Publisher; | ||
import com.jd.live.agent.core.plugin.definition.InterceptorAdaptor; | ||
import org.springframework.boot.web.embedded.netty.NettyWebServer; | ||
import reactor.netty.http.HttpProtocol; | ||
import reactor.netty.http.server.HttpServer; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class SpringCloudHttp3Interceptor extends InterceptorAdaptor { | ||
|
||
private static final String PROTOCOL_HTTP3 = "HTTP3"; | ||
|
||
private final Publisher<AgentEvent> publisher; | ||
|
||
public SpringCloudHttp3Interceptor(Publisher<AgentEvent> publisher) { | ||
this.publisher = publisher; | ||
} | ||
|
||
@Override | ||
public void onSuccess(ExecutableContext ctx) { | ||
NettyWebServer nettyWebServer = (NettyWebServer) ctx.getTarget(); | ||
try { | ||
Field httpServerField = nettyWebServer.getClass().getDeclaredField("httpServer"); | ||
httpServerField.setAccessible(true); | ||
HttpServer httpServer = (HttpServer) httpServerField.get(nettyWebServer); | ||
HttpProtocol[] protocols = httpServer.configuration().protocols(); | ||
for (HttpProtocol protocol : protocols) { | ||
if (PROTOCOL_HTTP3.equals(protocol.name())) { | ||
publisher.offer(AgentEvent.onApplicationStarted("Spring http3 web server started")); | ||
break; | ||
} | ||
} | ||
} catch (Exception e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 直接吞掉了所有的异常,应该细化为小的异常,从具体到公共。 |
||
//Not needing to throw exceptions | ||
} | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
...ain/resources/META-INF/services/com.jd.live.agent.core.plugin.definition.PluginDefinition
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,4 +1,5 @@ | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.SpringApplicationDefinition | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.SpringApplicationRunListenersDefinition | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.SpringApplicationContextDefinition | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.NacosRegistrationDefinition | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.NacosRegistrationDefinition | ||
com.jd.live.agent.plugin.application.springboot.v2.definition.SpringNettyWebServerDefinition |
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.
publisher 注入未做空值校验,可能导致 NPE。
只拦截了 NettyWebServer 的 start 方法,未考虑其他生命周期方法,可能遗漏部分启动场景。