use of io.jenkins.blueocean.analytics.Analytics.TrackRequest in project blueocean-plugin by jenkinsci.
the class PipelinePluginAnalyticsTest method testGenerateAnalyticsEvent.
@Test(timeout = 120000)
public void testGenerateAnalyticsEvent() throws Exception {
// Create single scripted pipeline
createAndRunPipeline("JobAnalyticsTest-scripted.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", 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 trackWithoutProps.
@Test
public void trackWithoutProps() {
analytics.track(new TrackRequest("test", null));
Map<String, Object> expectedProps = new HashMap();
expectedProps.put("jenkins", analytics.getServer());
expectedProps.put("jenkinsVersion", j.jenkins.getVersion().toString());
expectedProps.put("blueoceanVersion", Jenkins.get().getPlugin("blueocean-commons").getWrapper().getVersion());
Assert.assertEquals("test", analytics.lastName);
Assert.assertEquals(expectedProps, analytics.lastProps);
// Ensure identify does not contain the username
Assert.assertFalse(analytics.getIdentity().contains(User.current().getId()));
}
use of io.jenkins.blueocean.analytics.Analytics.TrackRequest in project blueocean-plugin by jenkinsci.
the class AnalyticsTest method track.
@Test
public void track() {
Map<String, Object> props = MapsHelper.of("prop1", "value1", "prop2", 2, "jenkinsVersion", j.jenkins.getVersion().toString(), "blueoceanVersion", Jenkins.get().getPlugin("blueocean-commons").getWrapper().getVersion());
analytics.track(new TrackRequest("test", props));
Map<String, Object> expectedProps = new HashMap<>(props);
expectedProps.put("jenkins", analytics.getServer());
Assert.assertEquals("test", analytics.lastName);
Assert.assertEquals(expectedProps, analytics.lastProps);
// Ensure identify does not contain the username
Assert.assertFalse(analytics.getIdentity().contains(User.current().getId()));
}
use of io.jenkins.blueocean.analytics.Analytics.TrackRequest 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