Search in sources :

Example 6 with TrackRequest

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"));
}
Also used : TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) PipelineBaseTest(io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest) Test(org.junit.Test)

Example 7 with TrackRequest

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()));
}
Also used : TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with TrackRequest

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()));
}
Also used : TrackRequest(io.jenkins.blueocean.analytics.Analytics.TrackRequest) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with TrackRequest

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

Aggregations

TrackRequest (io.jenkins.blueocean.analytics.Analytics.TrackRequest)9 Test (org.junit.Test)6 PipelineBaseTest (io.jenkins.blueocean.rest.impl.pipeline.PipelineBaseTest)3 HashMap (java.util.HashMap)3 Analytics (io.jenkins.blueocean.analytics.Analytics)2 Result (hudson.model.Result)1 ServiceException (io.jenkins.blueocean.commons.ServiceException)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 InputStream (java.io.InputStream)1 Jenkins (jenkins.model.Jenkins)1 DeclarativeJobAction (org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction)1 WebMethod (org.kohsuke.stapler.WebMethod)1 POST (org.kohsuke.stapler.verb.POST)1