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

Fix hostname resolution in recent Jenkins versions #326

Merged
merged 4 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -70,7 +70,7 @@ protected Set<String> getNodeLabels(Run<?,?> run, final String nodeName) {

// If there is no labels and the node name is master,
// we force the label "master".
if("master".equalsIgnoreCase(nodeName)){
if("master".equalsIgnoreCase(nodeName) || "built-in".equalsIgnoreCase(nodeName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be worth it to have this method in a utility method. It seems we're repeating the same checks multiple times

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

final Set<String> masterLabels = new HashSet<>();
masterLabels.add("master");
return masterLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ protected Set<String> getNodeLabels(Run run, BuildPipelineNode current, String n

// If there is no labels and the node name is master,
// we force the label "master".
if ("master".equalsIgnoreCase(nodeName)) {
if ("master".equalsIgnoreCase(nodeName) || "built-in".equalsIgnoreCase(nodeName)) {
final Set<String> masterLabels = new HashSet<>();
masterLabels.add("master");
return masterLabels;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public void finishBuildTrace(final BuildData buildData, final Run<?,?> run) {
}

// If the NodeName == "master", we don't set _dd.hostname. It will be overridden by the Datadog Agent. (Traces are only available using Datadog Agent)
if(!"master".equalsIgnoreCase(nodeName)){
if(!"master".equalsIgnoreCase(nodeName) && !"built-in".equalsIgnoreCase(nodeName)) {
final String workerHostname = getNodeHostname(run, updatedBuildData);
// If the worker hostname is equals to controller hostname but the node name is not "master"
// then we could not detect the worker hostname properly. We set _dd.hostname to 'none' explicitly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private Map<String, Object> buildTraceTags(final Run run, final BuildPipelineNod
}

// If the NodeName == "master", we don't set _dd.hostname. It will be overridden by the Datadog Agent. (Traces are only available using Datadog Agent)
if(!"master".equalsIgnoreCase(nodeName)){
if(!"master".equalsIgnoreCase(nodeName) && !"built-in".equalsIgnoreCase(nodeName)) {
final String workerHostname = getNodeHostname(run, current);
// If the worker hostname is equals to controller hostname but the node name is not "master"
// then we could not detect the worker hostname properly. We set _dd.hostname to 'none' explicitly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ public void finishBuildTrace(final BuildData buildData, final Run<?,?> run) {

final String nodeName = getNodeName(run, buildData, updatedBuildData);
nodePayload.put("name", nodeName);
if(!"master".equalsIgnoreCase(nodeName) && !"built-in".equalsIgnoreCase(nodeName)) {

if(!"master".equalsIgnoreCase(nodeName)){
final String workerHostname = getNodeHostname(run, updatedBuildData);
// If the worker hostname is equals to controller hostname but the node name is not "master"
// then we could not detect the worker hostname properly. We set _dd.hostname to 'none' explicitly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void collectTraces(final Run run, final BuildData buildData, final Build
final String nodeName = getNodeName(run, current, buildData);
nodePayload.put("name", nodeName);

if(!"master".equalsIgnoreCase(nodeName)){
if(!"master".equalsIgnoreCase(nodeName) && !"built-in".equalsIgnoreCase(nodeName)) {
final String workerHostname = getNodeHostname(run, current);
// If the worker hostname is equals to controller hostname but the node name is not "master"
// then we could not detect the worker hostname properly. We set _dd.hostname to 'none' explicitly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static FilePath buildFilePath(final String nodeName, final String workspa
}

try {
return "master".equals(nodeName) ? new FilePath(FilePath.localChannel, workspace): FilePathUtils.find(nodeName, workspace);
return ("master".equals(nodeName) || "built-in".equals(nodeName)) ? new FilePath(FilePath.localChannel, workspace): FilePathUtils.find(nodeName, workspace);
} catch (Exception e) {
LOGGER.fine("Unable to build FilePath. Error: " + e);
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div>
Enter the name you'd like to identify your Jenkins host as. Must comply with the hostname format set in <a target="_blank" href="https://tools.ietf.org/html/rfc1123#section-2">RFC 1123</a>.
Enter the name you'd like to identify your Jenkins host as. Must comply with the hostname format set in <a target="_blank" href="https://tools.ietf.org/html/rfc1123#section-2">RFC 1123</a>. Leave empty to use the detected hostname.
</div>