Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
jenkins
提交
e76110f4
J
jenkins
项目概览
xxadev
/
jenkins
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
J
jenkins
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e76110f4
编写于
10月 27, 2018
作者:
R
R. Tyler Croy
提交者:
GitHub
10月 27, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3698 from daniel-beck/JENKINS-54136
[JENKINS-54136] Use per-trial correlation IDs
上级
a41c4b38
b3b79764
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
44 addition
and
4 deletion
+44
-4
core/src/main/java/jenkins/telemetry/Correlator.java
core/src/main/java/jenkins/telemetry/Correlator.java
+7
-0
core/src/main/java/jenkins/telemetry/Telemetry.java
core/src/main/java/jenkins/telemetry/Telemetry.java
+3
-1
test/src/test/java/jenkins/telemetry/TelemetryTest.java
test/src/test/java/jenkins/telemetry/TelemetryTest.java
+34
-3
未找到文件。
core/src/main/java/jenkins/telemetry/Correlator.java
浏览文件 @
e76110f4
...
...
@@ -23,6 +23,7 @@
*/
package
jenkins.telemetry
;
import
com.google.common.annotations.VisibleForTesting
;
import
hudson.Extension
;
import
hudson.model.Describable
;
import
hudson.model.Descriptor
;
...
...
@@ -56,6 +57,12 @@ public class Correlator extends Descriptor<Correlator> implements Describable<Co
return
correlationId
;
}
@Restricted
(
NoExternalUse
.
class
)
@VisibleForTesting
void
setCorrelationId
(
String
correlationId
)
{
this
.
correlationId
=
correlationId
;
}
@Override
public
Descriptor
<
Correlator
>
getDescriptor
()
{
return
this
;
...
...
core/src/main/java/jenkins/telemetry/Telemetry.java
浏览文件 @
e76110f4
...
...
@@ -34,6 +34,7 @@ import hudson.model.UsageStatistics;
import
jenkins.model.Jenkins
;
import
jenkins.util.SystemProperties
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.kohsuke.accmod.Restricted
;
import
org.kohsuke.accmod.restrictions.NoExternalUse
;
...
...
@@ -178,7 +179,8 @@ public abstract class Telemetry implements ExtensionPoint {
JSONObject
wrappedData
=
new
JSONObject
();
wrappedData
.
put
(
"type"
,
telemetry
.
getId
());
wrappedData
.
put
(
"payload"
,
data
);
wrappedData
.
put
(
"correlator"
,
ExtensionList
.
lookupSingleton
(
Correlator
.
class
).
getCorrelationId
());
String
correlationId
=
ExtensionList
.
lookupSingleton
(
Correlator
.
class
).
getCorrelationId
();
wrappedData
.
put
(
"correlator"
,
DigestUtils
.
sha256Hex
(
correlationId
+
telemetry
.
getId
()));
try
{
URL
url
=
new
URL
(
ENDPOINT
);
...
...
test/src/test/java/jenkins/telemetry/TelemetryTest.java
浏览文件 @
e76110f4
...
...
@@ -7,7 +7,9 @@ import static org.junit.Assert.*;
import
hudson.security.csrf.CrumbExclusion
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.jvnet.hudson.test.JenkinsRule
;
...
...
@@ -29,7 +31,11 @@ import java.time.LocalDate;
import
java.time.temporal.ChronoUnit
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.SortedSet
;
import
java.util.TreeSet
;
import
java.util.UUID
;
import
java.util.logging.Level
;
import
java.util.regex.Pattern
;
public
class
TelemetryTest
{
@Rule
...
...
@@ -40,11 +46,19 @@ public class TelemetryTest {
private
static
int
counter
=
0
;
@Before
public
void
prepare
()
throws
Exception
{
correlators
.
clear
();
types
.
clear
();
counter
=
0
;
j
.
jenkins
.
setNoUsageStatistics
(
false
);
// tests usually don't submit this, but we need this
Telemetry
.
ENDPOINT
=
j
.
getURL
().
toString
()
+
"uplink/events"
;
}
@Test
public
void
testSubmission
()
throws
Exception
{
j
.
jenkins
.
setNoUsageStatistics
(
false
);
// tests usually don't submit this, but we need this
assertEquals
(
"no requests received"
,
0
,
counter
);
Telemetry
.
ENDPOINT
=
j
.
getURL
().
toString
()
+
"uplink/events"
;
ExtensionList
.
lookupSingleton
(
Telemetry
.
TelemetryReporter
.
class
).
doRun
();
do
{
Thread
.
sleep
(
250
);
...
...
@@ -56,11 +70,28 @@ public class TelemetryTest {
assertThat
(
types
,
hasItem
(
"test-data"
));
assertThat
(
types
,
not
(
hasItem
(
"future"
)));
assertThat
(
types
,
not
(
hasItem
(
"past"
)));
assertThat
(
correlators
.
size
(),
is
(
counter
));
assertTrue
(
Pattern
.
compile
(
"[0-9a-f]+"
).
matcher
(
correlators
.
first
()).
matches
());
assertThat
(
types
,
not
(
hasItem
(
"empty"
)));
assertThat
(
correlators
.
size
(),
is
(
1
));
assertTrue
(
"at least one request received"
,
counter
>
0
);
// TestTelemetry plus whatever real impls exist
}
@Test
public
void
testPerTrialCorrelator
()
throws
Exception
{
Correlator
correlator
=
ExtensionList
.
lookupSingleton
(
Correlator
.
class
);
String
correlationId
=
"00000000-0000-0000-0000-000000000000"
;
correlator
.
setCorrelationId
(
correlationId
);
ExtensionList
.
lookupSingleton
(
Telemetry
.
TelemetryReporter
.
class
).
doRun
();
do
{
Thread
.
sleep
(
250
);
}
while
(
counter
==
0
);
// this might end up being flaky due to 1 to many active telemetry trials
assertThat
(
types
,
hasItem
(
"test-data"
));
//90ecf3ce1cd5ba1e5ad3cde7ad08a941e884f2e4d9bd463361715abab8efedc5
assertThat
(
correlators
,
hasItem
(
DigestUtils
.
sha256Hex
(
correlationId
+
"test-data"
)));
}
@TestExtension
public
static
class
EmptyTelemetry
extends
Telemetry
{
...
...
@@ -209,7 +240,7 @@ public class TelemetryTest {
}
}
private
static
S
et
<
String
>
correlators
=
new
Hash
Set
<>();
private
static
S
ortedSet
<
String
>
correlators
=
new
Tree
Set
<>();
private
static
Set
<
String
>
types
=
new
HashSet
<>();
@TestExtension
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录