Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
月轩居士
SkyWalking
提交
26b1d415
S
SkyWalking
项目概览
月轩居士
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
SkyWalking
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
26b1d415
编写于
10月 22, 2019
作者:
X
xiaoy00
提交者:
wu-sheng
10月 22, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Supporting RequestRateLimiterGatewayFilterFactory (#3538)
上级
9996fbb5
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
223 addition
and
20 deletion
+223
-20
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/pom.xml
...lugins/optional-spring-cloud/gateway-2.1.x-plugin/pom.xml
+1
-0
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/FilteringWebHandlerInterceptor.java
...ng/cloud/gateway/v21x/FilteringWebHandlerInterceptor.java
+100
-0
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
...ing/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
+3
-18
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/define/FilteringWebHandlerInstrumentation.java
...teway/v21x/define/FilteringWebHandlerInstrumentation.java
+68
-0
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/resources/skywalking-plugin.def
...way-2.1.x-plugin/src/main/resources/skywalking-plugin.def
+2
-1
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/pom.xml
...narios/gateway-scenario/gateway-projectA-scenario/pom.xml
+5
-0
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/src/main/java/org/apache/skywalking/apm/testcase/sc/gateway/projectA/ApiKeyResolver.java
...king/apm/testcase/sc/gateway/projectA/ApiKeyResolver.java
+34
-0
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/src/main/resources/application.yml
...eway-projectA-scenario/src/main/resources/application.yml
+10
-1
未找到文件。
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/pom.xml
浏览文件 @
26b1d415
...
...
@@ -34,6 +34,7 @@
<properties>
<spring-cloud-starter-gateway.version>
2.1.1.RELEASE
</spring-cloud-starter-gateway.version>
<compiler.version>
1.8
</compiler.version>
</properties>
<dependencies>
...
...
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/FilteringWebHandlerInterceptor.java
0 → 100644
浏览文件 @
26b1d415
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.tag.Tags
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.context.trace.SpanLayer
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.network.trace.component.ComponentsDefine
;
import
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.context.SWTransmitter
;
import
org.springframework.cloud.gateway.route.Route
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
import
java.lang.reflect.Method
;
import
static
org
.
springframework
.
cloud
.
gateway
.
support
.
ServerWebExchangeUtils
.
GATEWAY_ROUTE_ATTR
;
/**
* @author songxiaoyue
*/
public
class
FilteringWebHandlerInterceptor
implements
InstanceMethodsAroundInterceptor
{
private
static
final
String
SPRING_CLOUD_GATEWAY_ROUTE_PREFIX
=
"GATEWAY/"
;
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
EnhancedInstance
instance
=
NettyRoutingFilterInterceptor
.
getInstance
(
allArguments
[
0
]);
if
(
instance
==
null
)
{
return
;
}
AbstractSpan
span
=
(
AbstractSpan
)
instance
.
getSkyWalkingDynamicField
();
if
(
span
==
null
)
{
return
;
}
ServerWebExchange
exchange
=
(
ServerWebExchange
)
allArguments
[
0
];
String
operationName
=
SPRING_CLOUD_GATEWAY_ROUTE_PREFIX
;
Route
route
=
exchange
.
getRequiredAttribute
(
GATEWAY_ROUTE_ATTR
);
operationName
=
operationName
+
route
.
getId
();
span
.
setOperationName
(
operationName
);
SWTransmitter
transmitter
=
new
SWTransmitter
(
span
.
prepareForAsync
(),
ContextManager
.
capture
(),
operationName
);
instance
.
setSkyWalkingDynamicField
(
transmitter
);
ContextManager
.
stopSpan
(
span
);
}
@Override
public
Object
afterMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Object
ret
)
throws
Throwable
{
EnhancedInstance
instance
=
NettyRoutingFilterInterceptor
.
getInstance
(
allArguments
[
0
]);
if
(
instance
==
null
)
{
return
ret
;
}
SWTransmitter
swTransmitter
=
(
SWTransmitter
)
instance
.
getSkyWalkingDynamicField
();
if
(
swTransmitter
==
null
)
{
return
ret
;
}
Mono
<
Void
>
mono
=
(
Mono
)
ret
;
return
mono
.
doFinally
(
d
->
{
ServerWebExchange
exchange
=
(
ServerWebExchange
)
allArguments
[
0
];
HttpStatus
statusCode
=
exchange
.
getResponse
().
getStatusCode
();
if
(
statusCode
==
HttpStatus
.
TOO_MANY_REQUESTS
)
{
AbstractSpan
localSpan
=
ContextManager
.
createLocalSpan
(
swTransmitter
.
getOperationName
());
Tags
.
STATUS_CODE
.
set
(
localSpan
,
statusCode
.
toString
());
SpanLayer
.
asHttp
(
localSpan
);
localSpan
.
setComponent
(
ComponentsDefine
.
SPRING_CLOUD_GATEWAY
);
ContextManager
.
continued
(
swTransmitter
.
getSnapshot
());
ContextManager
.
stopSpan
(
localSpan
);
AbstractSpan
spanWebflux
=
swTransmitter
.
getSpanWebflux
();
spanWebflux
.
asyncFinish
();
}
});
}
@Override
public
void
handleMethodException
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
Throwable
t
)
{
}
}
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/NettyRoutingFilterInterceptor.java
浏览文件 @
26b1d415
...
...
@@ -19,20 +19,15 @@
package
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x
;
import
org.apache.skywalking.apm.agent.core.context.ContextManager
;
import
org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult
;
import
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.context.Constants
;
import
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.context.SWTransmitter
;
import
org.springframework.cloud.gateway.route.Route
;
import
org.springframework.web.server.ServerWebExchange
;
import
org.springframework.web.server.ServerWebExchangeDecorator
;
import
org.springframework.web.server.adapter.DefaultServerWebExchange
;
import
java.lang.reflect.Method
;
import
static
org
.
springframework
.
cloud
.
gateway
.
support
.
ServerWebExchangeUtils
.
GATEWAY_ROUTE_ATTR
;
/**
...
...
@@ -40,24 +35,14 @@ import static org.springframework.cloud.gateway.support.ServerWebExchangeUtils.G
*/
public
class
NettyRoutingFilterInterceptor
implements
InstanceMethodsAroundInterceptor
{
private
static
final
String
SPRING_CLOUD_GATEWAY_ROUTE_PREFIX
=
"GATEWAY/"
;
@Override
public
void
beforeMethod
(
EnhancedInstance
objInst
,
Method
method
,
Object
[]
allArguments
,
Class
<?>[]
argumentsTypes
,
MethodInterceptResult
result
)
throws
Throwable
{
EnhancedInstance
instance
=
NettyRoutingFilterInterceptor
.
getInstance
(
allArguments
[
0
]);
if
(
instance
!=
null
)
{
ServerWebExchange
exchange
=
(
ServerWebExchange
)
allArguments
[
0
];
AbstractSpan
span
=
(
AbstractSpan
)
instance
.
getSkyWalkingDynamicField
();
String
operationName
=
SPRING_CLOUD_GATEWAY_ROUTE_PREFIX
;
if
(
span
!=
null
)
{
Route
route
=
exchange
.
getRequiredAttribute
(
GATEWAY_ROUTE_ATTR
);
operationName
=
operationName
+
route
.
getId
();
span
.
setOperationName
(
operationName
);
SWTransmitter
transmitter
=
new
SWTransmitter
(
span
.
prepareForAsync
(),
ContextManager
.
capture
(),
operationName
);
ContextManager
.
stopSpan
(
span
);
ContextManager
.
getRuntimeContext
().
put
(
Constants
.
SPRING_CLOUD_GATEWAY_TRANSMITTER
,
transmitter
);
}
SWTransmitter
swTransmitter
=
(
SWTransmitter
)
instance
.
getSkyWalkingDynamicField
();
ContextManager
.
getRuntimeContext
().
put
(
Constants
.
SPRING_CLOUD_GATEWAY_TRANSMITTER
,
swTransmitter
);
}
}
...
...
@@ -99,4 +84,4 @@ public class NettyRoutingFilterInterceptor implements InstanceMethodsAroundInter
throw
new
RuntimeException
(
"Unknown parameter types:"
+
o
.
getClass
());
}
}
}
}
\ No newline at end of file
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/cloud/gateway/v21x/define/FilteringWebHandlerInstrumentation.java
0 → 100644
浏览文件 @
26b1d415
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define
;
import
net.bytebuddy.description.method.MethodDescription
;
import
net.bytebuddy.matcher.ElementMatcher
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.ConstructorInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.InstanceMethodsInterceptPoint
;
import
org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.ClassInstanceMethodsEnhancePluginDefine
;
import
org.apache.skywalking.apm.agent.core.plugin.match.ClassMatch
;
import
static
net
.
bytebuddy
.
matcher
.
ElementMatchers
.
named
;
import
static
org
.
apache
.
skywalking
.
apm
.
agent
.
core
.
plugin
.
match
.
NameMatch
.
byName
;
/**
* @author songxiaoyue
*/
public
class
FilteringWebHandlerInstrumentation
extends
ClassInstanceMethodsEnhancePluginDefine
{
@Override
public
ConstructorInterceptPoint
[]
getConstructorsInterceptPoints
()
{
return
new
ConstructorInterceptPoint
[
0
];
}
@Override
public
InstanceMethodsInterceptPoint
[]
getInstanceMethodsInterceptPoints
()
{
return
new
InstanceMethodsInterceptPoint
[]{
new
InstanceMethodsInterceptPoint
()
{
@Override
public
ElementMatcher
<
MethodDescription
>
getMethodsMatcher
()
{
return
named
(
"handle"
);
}
@Override
public
String
getMethodsInterceptor
()
{
return
"org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.FilteringWebHandlerInterceptor"
;
}
@Override
public
boolean
isOverrideArgs
()
{
return
false
;
}
}
};
}
@Override
public
ClassMatch
enhanceClass
()
{
return
byName
(
"org.springframework.cloud.gateway.handler.FilteringWebHandler"
);
}
}
apm-sniffer/optional-plugins/optional-spring-plugins/optional-spring-cloud/gateway-2.1.x-plugin/src/main/resources/skywalking-plugin.def
浏览文件 @
26b1d415
...
...
@@ -16,4 +16,5 @@
spring-cloud-gateway-2.1.x=org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define.DefaultHttpHeadersInstrumentation
spring-cloud-gateway-2.1.x=org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define.HttpClientOperationsInstrumentation
spring-cloud-gateway-2.1.x=org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define.NettyRoutingFilterInstrumentation
\ No newline at end of file
spring-cloud-gateway-2.1.x=org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define.NettyRoutingFilterInstrumentation
spring-cloud-gateway-2.1.x=org.apache.skywalking.apm.plugin.spring.cloud.gateway.v21x.define.FilteringWebHandlerInstrumentation
\ No newline at end of file
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/pom.xml
浏览文件 @
26b1d415
...
...
@@ -34,6 +34,11 @@
<artifactId>
spring-cloud-starter-gateway
</artifactId>
<version>
${test.framework.version}
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-data-redis
</artifactId>
<version>
2.1.2.RELEASE
</version>
</dependency>
</dependencies>
<build>
...
...
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/src/main/java/org/apache/skywalking/apm/testcase/sc/gateway/projectA/ApiKeyResolver.java
0 → 100644
浏览文件 @
26b1d415
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
org.apache.skywalking.apm.testcase.sc.gateway.projectA
;
import
org.springframework.cloud.gateway.filter.ratelimit.KeyResolver
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.server.ServerWebExchange
;
import
reactor.core.publisher.Mono
;
/**
* @author songxiaoyue
*/
@Component
public
class
ApiKeyResolver
implements
KeyResolver
{
public
Mono
<
String
>
resolve
(
ServerWebExchange
exchange
)
{
return
Mono
.
just
(
exchange
.
getRequest
().
getPath
().
value
());
}
}
test/plugin/scenarios/gateway-scenario/gateway-projectA-scenario/src/main/resources/application.yml
浏览文件 @
26b1d415
...
...
@@ -24,4 +24,13 @@ spring:
-
id
:
provider_route
uri
:
http://localhost:18070
predicates
:
-
Path=/provider/b/*
\ No newline at end of file
-
Path=/provider/b/*
filters
:
-
name
:
RequestRateLimiter
args
:
redis-rate-limiter.replenishRate
:
1
redis-rate-limiter.burstCapacity
:
1
key-resolver
:
"
#{@apiKeyResolver}"
redis
:
host
:
127.0.0.1
port
:
6379
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录