-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-54029] Add telemetry for Stapler dispatches (#3688)
* Add telemetry for Stapler dispatches * Add TODO * Released version of Stapler (cherry picked from commit d1cbb20)
- Loading branch information
1 parent
9da2717
commit b9725c1
Showing
2 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
core/src/main/java/jenkins/telemetry/impl/StaplerDispatches.java
This file contains 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,120 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2018, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package jenkins.telemetry.impl; | ||
|
||
import hudson.Extension; | ||
import hudson.PluginWrapper; | ||
import hudson.model.UsageStatistics; | ||
import hudson.util.VersionNumber; | ||
import jenkins.model.Jenkins; | ||
import jenkins.telemetry.Telemetry; | ||
import jenkins.util.SystemProperties; | ||
import net.sf.json.JSONObject; | ||
import org.kohsuke.MetaInfServices; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
import org.kohsuke.stapler.EvaluationTrace; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.time.LocalDate; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TimeZone; | ||
import java.util.TreeMap; | ||
import java.util.TreeSet; | ||
|
||
/** | ||
* Telemetry implementation gathering information about Stapler dispatch routes. | ||
*/ | ||
@Extension | ||
@Restricted(NoExternalUse.class) | ||
public class StaplerDispatches extends Telemetry { | ||
@Nonnull | ||
@Override | ||
public LocalDate getStart() { | ||
return LocalDate.of(2018, 10, 10); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public LocalDate getEnd() { | ||
return LocalDate.of(2019, 2, 1); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Stapler request handling"; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public JSONObject createContent() { | ||
Map<String, Object> info = new TreeMap<>(); | ||
info.put("components", buildComponentInformation()); | ||
info.put("dispatches", buildDispatches()); | ||
|
||
return JSONObject.fromObject(info); | ||
} | ||
|
||
private Object buildDispatches() { | ||
Set<String> currentTraces = traces; | ||
traces = new TreeSet<>(); | ||
return currentTraces; | ||
} | ||
|
||
private Object buildComponentInformation() { | ||
Map<String, String> components = new TreeMap<>(); | ||
VersionNumber core = Jenkins.getVersion(); | ||
components.put("jenkins-core", core == null ? "" : core.toString()); | ||
|
||
for (PluginWrapper plugin : Jenkins.get().pluginManager.getPlugins()) { | ||
if (plugin.isActive()) { | ||
components.put(plugin.getShortName(), plugin.getVersion()); | ||
} | ||
} | ||
return components; | ||
} | ||
|
||
@MetaInfServices | ||
public static class StaplerTrace extends EvaluationTrace.ApplicationTracer { | ||
|
||
@Override | ||
protected void record(StaplerRequest staplerRequest, String s) { | ||
if (UsageStatistics.DISABLED || !Jenkins.get().isUsageStatisticsCollected()) { | ||
// TODO use new API after jenkinsci/jenkins#3687 is merged | ||
// do not collect traces while usage statistics are disabled | ||
return; | ||
} | ||
traces.add(s); | ||
} | ||
} | ||
|
||
private static volatile Set<String> traces = new TreeSet<>(); | ||
} |
7 changes: 7 additions & 0 deletions
7
core/src/main/resources/jenkins/telemetry/impl/StaplerDispatches/description.jelly
This file contains 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,7 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core"> | ||
Stapler is the web framework used by Jenkins. | ||
To help develop an upcoming major revision of the framework, this trial collects information about how Stapler processes HTTP requests. | ||
In addition to references to classes, methods, and Stapler-related resource files involved in Stapler request processing, this trial collects the names of installed plugins, their versions, and the version of Jenkins core. | ||
It does <strong>not</strong> collect URLs or any user data. | ||
</j:jelly> |