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

Send Node-Name HTTP header in JnlpAgentEndpointResolver #685

Merged
merged 2 commits into from
Oct 20, 2023

Conversation

jglick
Copy link
Member

@jglick jglick commented Oct 16, 2023

public static final String CLIENT_NAME_KEY = "Node-Name";
is passed as an HTTP header in WebSocket mode
addedHeaders.put(JnlpConnectionState.CLIENT_NAME_KEY, List.of(agentName));
and as a protocol header in TCP mode
headers.put(JnlpConnectionState.CLIENT_NAME_KEY, agentName);
This patch just passes it also as an HTTP header in the handshake phase of TCP mode, when the agent checks https://jenkins/tcpSlaveAgentListener/ to determine a host and port to connect to. Jenkins core will ignore the header; CloudBees CI can use it to adjust the TCP connection information according to the identity of the agent.

@jglick jglick added the enhancement For changelog: An enhancement providing new capability. label Oct 16, 2023
Comment on lines -110 to -118
public JnlpAgentEndpointResolver(String... jenkinsUrls) {
this.jenkinsUrls = new ArrayList<>(Arrays.asList(jenkinsUrls));
}

public JnlpAgentEndpointResolver(@NonNull List<String> jenkinsUrls) {
this(jenkinsUrls, null, null, null, null, false);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

These overloads appear unused, so I did not bother retaining compatibility for them.

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

Making it clear that I am blocking this PR until it does not increase the divergence between multiple copies of this code.

@jglick
Copy link
Member Author

jglick commented Oct 18, 2023

This PR does not actually increase the divergence between copies, since it adds an independent line of code after the common portions; if #687 is merged then I would resolve the merge conflict which would make that more apparent.

@basil
Copy link
Member

basil commented Oct 18, 2023

This PR does not actually increase the divergence between copies, since it adds an independent line of code after the common portions

I'm having a hard time following this point, so maybe you could clarify. Are you saying that even in the context of the more comprehensive refactoring done in #677 (which condenses all openURLConnection methods into one), you'd still want to send this header only in the request to /tcpSlaveAgentListener/ and not the request to /computer/${NODE_NAME}/jenkins-agent.jnlp because in the former case the server has no way of getting the agent name without the header but in the latter case the server can get the agent name from the URL?

@jglick
Copy link
Member Author

jglick commented Oct 19, 2023

Are you saying that…

Yes, exactly. EncryptedSlaveAgentJnlpFile.slaveName is already determined by Stapler ancestry. I guess it does no harm to pass a redundant header if the new caller of JnlpAgentEndpointResolver.openURLConnection in Launcher has access to name (or it is an optional parameter).

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

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

OK, I could also see an argument for always passing the header for greater consistency among the client's requests. But I don't feel strongly either way. Approving this PR.

@jglick
Copy link
Member Author

jglick commented Oct 19, 2023

I do not feel strongly either way either. Will wait for #677 to be merged and resolve conflicts with that.

@jglick jglick requested review from basil and Vlatombe October 20, 2023 17:49
@jglick jglick merged commit 77c0028 into jenkinsci:master Oct 20, 2023
12 checks passed
@jglick jglick deleted the CLIENT_NAME_KEY branch October 20, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement For changelog: An enhancement providing new capability.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants