Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gdyjdao
SkyWalking
提交
171620bf
S
SkyWalking
项目概览
gdyjdao
/
SkyWalking
与 Fork 源项目一致
Fork自
apache / SkyWalking
通知
1
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,发现更多精彩内容 >>
未验证
提交
171620bf
编写于
4月 14, 2020
作者:
静夜思朝颜
提交者:
GitHub
4月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Nginx correlation e2e test (#4646)
上级
b3b8aaea
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
87 addition
and
17 deletion
+87
-17
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CorrelationContext.java
...skywalking/apm/agent/core/context/CorrelationContext.java
+4
-3
apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/CorrelationContextTest.java
...alking/apm/agent/core/context/CorrelationContextTest.java
+1
-1
test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java
...org/apache/skywalking/apm/toolkit/trace/TraceContext.java
+57
-0
test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/lua/LuaController.java
...ain/java/org/apache/skywalking/e2e/lua/LuaController.java
+8
-0
test/e2e/e2e-test/docker/lua/Dockerfile.nginx
test/e2e/e2e-test/docker/lua/Dockerfile.nginx
+1
-1
test/e2e/e2e-test/docker/lua/nginx.conf
test/e2e/e2e-test/docker/lua/nginx.conf
+2
-2
test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/LuaE2E.java
...-test/src/test/java/org/apache/skywalking/e2e/LuaE2E.java
+12
-6
test/e2e/e2e-test/src/test/resources/expected/lua/endpoints-end.yml
...2e-test/src/test/resources/expected/lua/endpoints-end.yml
+1
-3
test/e2e/e2e-test/src/test/resources/expected/lua/traces.yml
test/e2e/e2e-test/src/test/resources/expected/lua/traces.yml
+1
-1
未找到文件。
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/CorrelationContext.java
浏览文件 @
171620bf
...
@@ -108,9 +108,10 @@ public class CorrelationContext {
...
@@ -108,9 +108,10 @@ public class CorrelationContext {
break
;
break
;
}
}
final
String
[]
parts
=
perData
.
split
(
":"
);
final
String
[]
parts
=
perData
.
split
(
":"
);
String
perDataKey
=
parts
[
0
];
if
(
parts
.
length
!=
2
)
{
String
perDataValue
=
parts
.
length
>
1
?
parts
[
1
]
:
""
;
continue
;
data
.
put
(
Base64
.
decode2UTFString
(
perDataKey
),
Base64
.
decode2UTFString
(
perDataValue
));
}
data
.
put
(
Base64
.
decode2UTFString
(
parts
[
0
]),
Base64
.
decode2UTFString
(
parts
[
1
]));
}
}
}
}
...
...
apm-sniffer/apm-agent-core/src/test/java/org/apache/skywalking/apm/agent/core/context/CorrelationContextTest.java
浏览文件 @
171620bf
...
@@ -111,7 +111,7 @@ public class CorrelationContextTest {
...
@@ -111,7 +111,7 @@ public class CorrelationContextTest {
// empty value
// empty value
context
=
new
CorrelationContext
();
context
=
new
CorrelationContext
();
context
.
deserialize
(
"dGVzdDE=:"
);
context
.
deserialize
(
"dGVzdDE=:"
);
Assert
.
assert
Equals
(
""
,
context
.
get
(
"test1"
).
ge
t
());
Assert
.
assert
False
(
context
.
get
(
"test1"
).
isPresen
t
());
// empty string
// empty string
context
=
new
CorrelationContext
();
context
=
new
CorrelationContext
();
...
...
test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/apm/toolkit/trace/TraceContext.java
0 → 100644
浏览文件 @
171620bf
/*
* 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.toolkit.trace
;
import
java.util.Optional
;
/**
* Try to access the sky-walking tracer context. The context is not existed, always. only the middleware, component, or
* rpc-framework are supported in the current invoke stack, in the same thread, the context will be available.
* <p>
*/
public
class
TraceContext
{
/**
* Try to get the traceId of current trace context.
*
* @return traceId, if it exists, or empty {@link String}.
*/
public
static
String
traceId
()
{
return
""
;
}
/**
* Try to get the custom value from trace context.
*
* @return custom data value.
*/
public
static
Optional
<
String
>
getCorrelation
(
String
key
)
{
return
Optional
.
empty
();
}
/**
* Put the custom key/value into trace context.
*
* @return previous value if it exists.
*/
public
static
Optional
<
String
>
putCorrelation
(
String
key
,
String
value
)
{
return
Optional
.
empty
();
}
}
test/e2e/e2e-service-provider/src/main/java/org/apache/skywalking/e2e/lua/LuaController.java
浏览文件 @
171620bf
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
package
org.apache.skywalking.e2e.lua
;
package
org.apache.skywalking.e2e.lua
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.skywalking.apm.toolkit.trace.TraceContext
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -36,8 +37,15 @@ public class LuaController {
...
@@ -36,8 +37,15 @@ public class LuaController {
@PostMapping
(
"/nginx/entry/info"
)
@PostMapping
(
"/nginx/entry/info"
)
private
String
nginxEntry
(
String
backend
)
throws
MalformedURLException
,
URISyntaxException
{
private
String
nginxEntry
(
String
backend
)
throws
MalformedURLException
,
URISyntaxException
{
final
URL
url
=
new
URL
(
"http://nginx:8080/nginx/info"
);
final
URL
url
=
new
URL
(
"http://nginx:8080/nginx/info"
);
TraceContext
.
putCorrelation
(
"entry"
,
"entry_value"
);
final
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
url
.
toURI
(),
null
,
String
.
class
);
final
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
url
.
toURI
(),
null
,
String
.
class
);
return
response
.
getBody
();
return
response
.
getBody
();
}
}
@PostMapping
(
"/nginx/end/info"
)
private
String
nginxEnd
()
throws
MalformedURLException
,
URISyntaxException
{
return
TraceContext
.
getCorrelation
(
"entry"
).
orElse
(
""
)
+
"_"
+
TraceContext
.
getCorrelation
(
"nginx"
).
orElse
(
""
);
}
}
}
test/e2e/e2e-test/docker/lua/Dockerfile.nginx
浏览文件 @
171620bf
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
FROM openresty/openresty
FROM openresty/openresty
ENV COMMIT_HASH=
45cf64640047a4a54619fa1d3451b4d0a65a62d6
ENV COMMIT_HASH=
7b23a978bb27787c69a57f734e4fa5865494ef79
WORKDIR /usr/share/skywalking-nginx-lua
WORKDIR /usr/share/skywalking-nginx-lua
...
...
test/e2e/e2e-test/docker/lua/nginx.conf
浏览文件 @
171620bf
...
@@ -47,10 +47,10 @@ http {
...
@@ -47,10 +47,10 @@ http {
location
/nginx/info
{
location
/nginx/info
{
rewrite_by_lua_block
{
rewrite_by_lua_block
{
require
("tracer"):start("User_Service_Name")
require
("tracer"):start("User_Service_Name"
,
{
nginx
=
"nginx_value"
}
)
}
}
proxy_pass
http://provider-end:9090/info
;
proxy_pass
http://provider-end:9090/
nginx/end/
info
;
body_filter_by_lua_block
{
body_filter_by_lua_block
{
require
("tracer"):finish()
require
("tracer"):finish()
...
...
test/e2e/e2e-test/src/test/java/org/apache/skywalking/e2e/LuaE2E.java
浏览文件 @
171620bf
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
package
org.apache.skywalking.e2e
;
package
org.apache.skywalking.e2e
;
import
java.net.URL
;
import
java.util.List
;
import
java.util.List
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.skywalking.e2e.annotation.ContainerHostAndPort
;
import
org.apache.skywalking.e2e.annotation.ContainerHostAndPort
;
...
@@ -51,8 +52,10 @@ import org.apache.skywalking.e2e.topo.TopoQuery;
...
@@ -51,8 +52,10 @@ import org.apache.skywalking.e2e.topo.TopoQuery;
import
org.apache.skywalking.e2e.trace.Trace
;
import
org.apache.skywalking.e2e.trace.Trace
;
import
org.apache.skywalking.e2e.trace.TracesMatcher
;
import
org.apache.skywalking.e2e.trace.TracesMatcher
;
import
org.apache.skywalking.e2e.trace.TracesQuery
;
import
org.apache.skywalking.e2e.trace.TracesQuery
;
import
org.junit.Assert
;
import
org.junit.jupiter.api.AfterAll
;
import
org.junit.jupiter.api.AfterAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.junit.jupiter.api.BeforeAll
;
import
org.springframework.http.ResponseEntity
;
import
org.testcontainers.containers.DockerComposeContainer
;
import
org.testcontainers.containers.DockerComposeContainer
;
import
static
org
.
apache
.
skywalking
.
e2e
.
metrics
.
MetricsMatcher
.
verifyMetrics
;
import
static
org
.
apache
.
skywalking
.
e2e
.
metrics
.
MetricsMatcher
.
verifyMetrics
;
...
@@ -81,10 +84,6 @@ public class LuaE2E extends SkyWalkingTestAdapter {
...
@@ -81,10 +84,6 @@ public class LuaE2E extends SkyWalkingTestAdapter {
@ContainerHostAndPort
(
name
=
"provider-entry"
,
port
=
9090
)
@ContainerHostAndPort
(
name
=
"provider-entry"
,
port
=
9090
)
private
HostAndPort
entryProvider
;
private
HostAndPort
entryProvider
;
@SuppressWarnings
(
"unused"
)
@ContainerHostAndPort
(
name
=
"nginx"
,
port
=
8080
)
private
HostAndPort
nginxHostPort
;
private
final
String
nginxServiceName
=
"User_Service_Name"
;
private
final
String
nginxServiceName
=
"User_Service_Name"
;
private
final
String
entryServiceName
=
"e2e-service-entry-provider"
;
private
final
String
entryServiceName
=
"e2e-service-entry-provider"
;
...
@@ -92,7 +91,7 @@ public class LuaE2E extends SkyWalkingTestAdapter {
...
@@ -92,7 +91,7 @@ public class LuaE2E extends SkyWalkingTestAdapter {
public
void
setUp
()
throws
Exception
{
public
void
setUp
()
throws
Exception
{
queryClient
(
swWebappHostPort
);
queryClient
(
swWebappHostPort
);
trafficController
(
entryProvider
,
"/nginx/entry/info
?backend="
+
nginxHostPort
.
host
()
+
":"
+
nginxHostPort
.
port
()
);
trafficController
(
entryProvider
,
"/nginx/entry/info
"
);
}
}
@AfterAll
@AfterAll
...
@@ -100,6 +99,13 @@ public class LuaE2E extends SkyWalkingTestAdapter {
...
@@ -100,6 +99,13 @@ public class LuaE2E extends SkyWalkingTestAdapter {
trafficController
.
stop
();
trafficController
.
stop
();
}
}
@RetryableTest
void
correlation
()
throws
Exception
{
final
URL
url
=
new
URL
(
"http"
,
entryProvider
.
host
(),
entryProvider
.
port
(),
"/nginx/entry/info"
);
final
ResponseEntity
<
String
>
response
=
restTemplate
.
postForEntity
(
url
.
toURI
(),
trafficData
,
String
.
class
);
Assert
.
assertEquals
(
response
.
getBody
(),
"entry_value_nginx_value"
);
}
@RetryableTest
@RetryableTest
void
services
()
throws
Exception
{
void
services
()
throws
Exception
{
final
List
<
Service
>
services
=
graphql
.
services
(
new
ServicesQuery
().
start
(
startTime
).
end
(
now
()));
final
List
<
Service
>
services
=
graphql
.
services
(
new
ServicesQuery
().
start
(
startTime
).
end
(
now
()));
...
@@ -213,7 +219,7 @@ public class LuaE2E extends SkyWalkingTestAdapter {
...
@@ -213,7 +219,7 @@ public class LuaE2E extends SkyWalkingTestAdapter {
private
void
verifyEndpointsMetrics
(
Endpoints
endpoints
)
throws
Exception
{
private
void
verifyEndpointsMetrics
(
Endpoints
endpoints
)
throws
Exception
{
for
(
Endpoint
endpoint
:
endpoints
.
getEndpoints
())
{
for
(
Endpoint
endpoint
:
endpoints
.
getEndpoints
())
{
if
(!
endpoint
.
getLabel
().
equals
(
"/info"
)
&&
!
endpoint
.
getLabel
().
equals
(
"/nginx/info"
))
{
if
(!
endpoint
.
getLabel
().
equals
(
"/
nginx/end/
info"
)
&&
!
endpoint
.
getLabel
().
equals
(
"/nginx/info"
))
{
continue
;
continue
;
}
}
for
(
final
String
metricName
:
ALL_ENDPOINT_METRICS
)
{
for
(
final
String
metricName
:
ALL_ENDPOINT_METRICS
)
{
...
...
test/e2e/e2e-test/src/test/resources/expected/lua/endpoints-end.yml
浏览文件 @
171620bf
...
@@ -15,7 +15,5 @@
...
@@ -15,7 +15,5 @@
endpoints
:
endpoints
:
-
key
:
not
null
-
key
:
not
null
label
:
/info
label
:
/nginx/end/info
test/e2e/e2e-test/src/test/resources/expected/lua/traces.yml
浏览文件 @
171620bf
...
@@ -34,7 +34,7 @@ traces:
...
@@ -34,7 +34,7 @@ traces:
-
key
:
not
null
-
key
:
not
null
endpointNames
:
endpointNames
:
-
/info
-
/
nginx/end/
info
duration
:
ge
0
duration
:
ge
0
start
:
gt
0
start
:
gt
0
isError
:
false
isError
:
false
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录