Skip to content

Commit a572d9c

Browse files
committed
Add telemetry for Jenkins uptime
1 parent 7d1217b commit a572d9c

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2023, CloudBees, Inc.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package jenkins.telemetry.impl;
26+
27+
import edu.umd.cs.findbugs.annotations.NonNull;
28+
import hudson.Extension;
29+
import java.time.LocalDate;
30+
import jenkins.telemetry.Telemetry;
31+
import net.sf.json.JSONObject;
32+
import org.kohsuke.accmod.Restricted;
33+
import org.kohsuke.accmod.restrictions.NoExternalUse;
34+
35+
/**
36+
* Records approximations of when Jenkins was started and the current time, to allow for computation of uptime.
37+
*/
38+
@Extension
39+
@Restricted(NoExternalUse.class)
40+
public class Uptime extends Telemetry {
41+
private static final long START = System.nanoTime();
42+
43+
@NonNull
44+
@Override
45+
public String getDisplayName() {
46+
return "Uptime";
47+
}
48+
49+
@NonNull
50+
@Override
51+
public LocalDate getStart() {
52+
return LocalDate.of(2023, 10, 20);
53+
}
54+
55+
@NonNull
56+
@Override
57+
public LocalDate getEnd() {
58+
return LocalDate.of(2024, 1, 20);
59+
}
60+
61+
@Override
62+
public JSONObject createContent() {
63+
return new JSONObject().element("start", START).element("now", System.nanoTime()).element("components", buildComponentInformation());
64+
}
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?jelly escape-by-default='true'?>
2+
<j:jelly xmlns:j="jelly:core">
3+
This trial collects two timestamps:
4+
<ul>
5+
<li><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#nanoTime()"><code>System#nanoTime</code></a> when the trial was initialized (corresponds roughly to when Jenkins was started)</li>
6+
<li><a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/System.html#nanoTime()"><code>System#nanoTime</code></a> when the trial data was collected (i.e., when it was prepared just before submission)</li>
7+
</ul>
8+
9+
Additionally this trial collects the list of installed plugins, their version, and the version of Jenkins.
10+
This data help understand unexpected submission frequency of other trials' data.
11+
</j:jelly>

0 commit comments

Comments
 (0)