Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag pipeline spans with plugin version #398

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ of this software and associated documentation files (the "Software"), to deal

import hudson.EnvVars;
import hudson.ExtensionList;
import hudson.PluginManager;
import hudson.PluginWrapper;
import hudson.model.Actionable;
import hudson.model.Computer;
import hudson.model.Item;
Expand Down Expand Up @@ -1112,5 +1114,20 @@ public static long getTimeMillis(FlowNode flowNode) {
}
return -1L;
}

@Nullable
public static String getDatadogPluginVersion() {
Jenkins jenkins = Jenkins.getInstanceOrNull();
if (jenkins == null) {
return null;
}
PluginManager pluginManager = jenkins.getPluginManager();
PluginWrapper datadogPlugin = pluginManager.getPlugin("datadog");
if (datadogPlugin == null) {
return null;
}
return datadogPlugin.getVersion();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class CITags {
public static final String JENKINS_TAG = "jenkins.tag";
public static final String JENKINS_EXECUTOR_NUMBER = "jenkins.executor.number";
public static final String JENKINS_RESULT = "jenkins.result";
public static final String JENKINS_PLUGIN_VERSION = "jenkins.plugin.version";

public static final String STATUS_SUCCESS = "success";
public static final String STATUS_ERROR = "error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public TraceSpan toSpan(final BuildData buildData, final Run<?,?> run) {
buildSpan.putMeta(CITags._DD_CI_LEVEL, buildLevel);
buildSpan.putMeta(CITags.IS_MANUAL, isTriggeredManually(run));
buildSpan.putMeta(CITags._DD_ORIGIN, ORIGIN_CIAPP_PIPELINE);
buildSpan.putMeta(CITags.JENKINS_PLUGIN_VERSION, DatadogUtilities.getDatadogPluginVersion());
buildSpan.putMeta(CITags.USER_NAME, buildData.getUserId());
if(StringUtils.isNotEmpty(buildData.getUserEmail(""))){
buildSpan.putMeta(CITags.USER_EMAIL, buildData.getUserEmail(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public JSONObject toJson(final BuildData buildData, final Run<?,?> run) {

// Jenkins specific
tagsPayload.add(CITags._DD_CI_INTERNAL + ":" + "false");
tagsPayload.add(CITags.JENKINS_PLUGIN_VERSION + ":" + DatadogUtilities.getDatadogPluginVersion());
tagsPayload.add(CITags.JENKINS_TAG + ":" + buildData.getBuildTag(""));
tagsPayload.add(CITags.JENKINS_EXECUTOR_NUMBER + ":" + buildData.getExecutorNumber(""));
if (StringUtils.isNotEmpty(jenkinsResult)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public void testTraces() throws Exception {
assertEquals("success", meta.get(CITags.JENKINS_RESULT));
assertEquals("jenkins-buildIntegrationSuccess-1", meta.get(CITags.JENKINS_TAG));
assertNull(meta.get(CITags._DD_CI_STAGES)); // this is a freestyle project which has no stages
assertNotNull(meta.get(CITags.JENKINS_PLUGIN_VERSION));

assertCleanupActions(run);
}
Expand Down Expand Up @@ -513,6 +514,8 @@ public void testCITagsOnWebhooks() throws Exception {
final JSONArray tags = webhook.getJSONArray("tags");
assertTrue(tags.contains("global_job_tag:value"));
assertTrue(tags.contains("global_tag:value"));

assertTrue(tags.stream().anyMatch(tag -> tag.toString().startsWith(CITags.JENKINS_PLUGIN_VERSION)));
}

@Test
Expand Down
Loading