use of io.jenkins.blueocean.analytics.Analytics in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalytics method onCompleted.
@Override
public void onCompleted(WorkflowRun workflowRun, @Nonnull TaskListener listener) {
Analytics analytics = Analytics.get();
if (analytics == null) {
return;
}
// Tally up all the steps used in this run
Tally tally = new Tally();
NodeGraphBuilder builder = NodeGraphBuilder.NodeGraphBuilderFactory.getInstance(workflowRun);
builder.getPipelineNodeSteps(new Link("steps/")).forEach(step -> tally.count(step.getStepType()));
boolean isDeclarative = workflowRun.getParent().getAction(DeclarativeJobAction.class) != null;
Result result = workflowRun.getResult();
String resultAsString = result != null ? result.toString() : "UNKNOWN";
// Send event for each step used in this run
tally.get().forEach((key, value) -> {
Map<String, Object> props = new HashMap<>();
props.put("type", key);
props.put("timesUsed", value);
props.put("isDeclarative", isDeclarative);
props.put("runResult", resultAsString);
analytics.track(new TrackRequest("pipeline_step_used", props));
});
}
use of io.jenkins.blueocean.analytics.Analytics in project blueocean-plugin by jenkinsci.
the class JobAnalytics method calculateAndSend.
public void calculateAndSend() {
Analytics analytics = Analytics.get();
if (analytics == null) {
return;
}
Jenkins jenkins = Jenkins.get();
ExtensionList<JobAnalyticsCheck> checks = ExtensionList.lookup(JobAnalyticsCheck.class);
ExtensionList<JobAnalyticsExclude> excludes = ExtensionList.lookup(JobAnalyticsExclude.class);
// Initialize the tally
Tally tally = new Tally();
checks.forEach(check -> tally.zero(check.getName()));
tally.zero(OTHER_CATEGORY);
jenkins.allItems().forEach(item -> {
if (excludes.stream().noneMatch(exclude -> exclude.apply(item))) {
boolean matchFound = false;
for (JobAnalyticsCheck check : checks) {
if (check.apply(item)) {
tally.count(check.getName());
matchFound = true;
break;
}
}
if (!matchFound) {
tally.count(OTHER_CATEGORY);
}
}
});
analytics.track(new TrackRequest(JOB_STATS_EVENT_NAME, tally.get()));
}
Aggregations