Search in sources :

Example 1 with Analytics

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));
    });
}
Also used : Tally(io.jenkins.blueocean.service.embedded.analytics.Tally) HashMap(java.util.HashMap) TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) DeclarativeJobAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction) Analytics(io.jenkins.blueocean.analytics.Analytics) Link(io.jenkins.blueocean.rest.hal.Link) NodeGraphBuilder(io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder) Result(hudson.model.Result)

Example 2 with Analytics

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()));
}
Also used : Jenkins(jenkins.model.Jenkins) TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) Analytics(io.jenkins.blueocean.analytics.Analytics)

Aggregations

Analytics (io.jenkins.blueocean.analytics.Analytics)2 TrackRequest (io.jenkins.blueocean.analytics.Analytics.TrackRequest)2 Result (hudson.model.Result)1 Link (io.jenkins.blueocean.rest.hal.Link)1 NodeGraphBuilder (io.jenkins.blueocean.rest.impl.pipeline.NodeGraphBuilder)1 Tally (io.jenkins.blueocean.service.embedded.analytics.Tally)1 HashMap (java.util.HashMap)1 Jenkins (jenkins.model.Jenkins)1 DeclarativeJobAction (org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction)1