use of io.jenkins.blueocean.analytics.Analytics.TrackRequest 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.TrackRequest in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalyticsTest method testGenerateAnalyticsEventWithDeclarative.
@Test(timeout = 120000)
public void testGenerateAnalyticsEventWithDeclarative() throws Exception {
// Create single scripted pipeline
createAndRunPipeline("JobAnalyticsTest-declarative.jenkinsfile");
AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
Assert.assertNotNull(analytics);
TrackRequest req = analytics.lastReq;
Assert.assertNotNull(req);
Assert.assertEquals("pipeline_step_used", req.name);
Map<String, Object> properties = req.properties;
Assert.assertEquals("type", "org.jenkinsci.plugins.workflow.steps.EchoStep", properties.get("type"));
Assert.assertEquals("timesUsed", 2, properties.get("timesUsed"));
Assert.assertEquals("isDeclarative", true, properties.get("isDeclarative"));
Assert.assertEquals("runResult", "SUCCESS", properties.get("runResult"));
}
use of io.jenkins.blueocean.analytics.Analytics.TrackRequest in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalyticsTest method testGeneratedAnalyticsEventWithScriptedFunction.
@Test(timeout = 120000)
public void testGeneratedAnalyticsEventWithScriptedFunction() throws Exception {
createAndRunPipeline("PipelinePluginAnalyticsTest-scripted-function.jenkinsfile");
AnalyticsImpl analytics = (AnalyticsImpl) Analytics.get();
Assert.assertNotNull(analytics);
TrackRequest req = analytics.lastReq;
Assert.assertNotNull(req);
Assert.assertEquals("pipeline_step_used", req.name);
Map<String, Object> properties = req.properties;
Assert.assertEquals("type", "org.jenkinsci.plugins.workflow.steps.EchoStep", properties.get("type"));
Assert.assertEquals("timesUsed", 1, properties.get("timesUsed"));
Assert.assertEquals("isDeclarative", false, properties.get("isDeclarative"));
Assert.assertEquals("runResult", "SUCCESS", properties.get("runResult"));
}
use of io.jenkins.blueocean.analytics.Analytics.TrackRequest in project blueocean-plugin by jenkinsci.
the class AnalyticsTest method nullNameInTrackRequest.
@Test
public void nullNameInTrackRequest() {
try {
analytics.track(new TrackRequest(null, null));
Assert.fail("did not throw exception");
} catch (ServiceException.BadRequestException e) {
Assert.assertEquals("missing name", e.getMessage());
}
}
use of io.jenkins.blueocean.analytics.Analytics.TrackRequest in project blueocean-plugin by jenkinsci.
the class AnalyticsRoute method track.
@POST
@WebMethod(name = "track")
public void track(StaplerRequest staplerRequest) throws IOException {
Analytics analytics = Analytics.get();
if (analytics == null) {
return;
}
TrackRequest req;
try (InputStream is = staplerRequest.getInputStream()) {
req = JsonConverter.toJava(is, TrackRequest.class);
}
analytics.track(req);
}
Aggregations