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

properly get displayname of node #38

Merged
merged 2 commits into from
Dec 22, 2017

Conversation

mwinter69
Copy link

use the executor of the build to get the node.
builtOn is set too late for us to get the node and we end up using
master
This is a proper implementation that was tried to be fixed with PR #19

use the executor of the build to get the node.
builtOn is set too late for us to get the node and we end up using
master
@@ -138,7 +139,7 @@ public TestData(Action action) {
public BuildData(AbstractBuild<?, ?> build, Date currentTime, TaskListener listener) {
initData(build, currentTime);

Node node = build.getBuiltOn();
Node node = build.getExecutor().getOwner().getNode();

Choose a reason for hiding this comment

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

how about we try to use getBuiltOn() first and fall back to getExecutor().getOwner().getNode() if the first one is null? Just to be on the safe side

Copy link
Author

Choose a reason for hiding this comment

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

It must be null if you follow the logic.
In the method execute of class Run you will see that the BuildWrappers are initialized from method createBuildListener. But the builtOn is only set when later in the execute the RunExecution.run is called (which actually is AbstractBuild.AbstractBuildExecution.run)

Choose a reason for hiding this comment

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

I get that. However this is relying on implementation details. With the current low test coverage I'd prefer to be as conservative as possible.

Choose a reason for hiding this comment

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

Another way to look at it is this.
It seems pointless for anyone to call getBuiltOn() if getExecutor().getOwner().getNode() can give you the same result and do it earlier.

I see there is an @Exported getBuiltOnStr() method so remote API is the only sane use case.
Is getBuiltOn() purely a legacy method then?

Copy link
Author

Choose a reason for hiding this comment

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

It is not pointless.
getExecutor() will only return something when a build is running. getBuiltOn() will also return the node when the build is finished when the node with this name still exists. Internally only the name of the node is stored and when you call getBuiltOn() it searches for the node with the name.
Maybe its time to write some tests with JenkinsRule where a real job is executed on a node.

Choose a reason for hiding this comment

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

Thanks for the explanation.

Based on that I'd still prefer to keep the fallback logic in case somebody somewhere tries to pass a non-running build here.

Maybe its time to write some tests with JenkinsRule where a real job is executed on a node.

Yeah this project definitely needs a heavy makeover (including this class).

I started to port the integ test we do on travis with docker in #36 but there is always something more urgent.
I also need to get more familiar with the jenkins test harness, hopefully #40 will be an opportunity to learn by example

Choose a reason for hiding this comment

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

Another thing: how does this compare to the pipeline logic in lines 190-194? Seems to to the same thing but using displayName?

Copy link
Author

Choose a reason for hiding this comment

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

This is wrong, it will return something like Executor-#0, but definitely not the host.
For pipelines using getExecutor().getOwner().getNode() will just get the host where the logstashSend is called, but the build could have run on many different hosts before.
Anyway I'm also looking into a more pipeline like logstash that accepts a block

logstash {
  node('label') {
    do something
    do anotherthing
  }
}

but I have to find a way to inject the host after the logstashwriter is initialized.

Choose a reason for hiding this comment

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

will just get the host where the logstashSend is called, but the build could have run on many different hosts before.

I get that.
One final question: for now, do you think we should change the pipeline handling to use the getExecutor().getOwner().getNode() instead of the current executor display name?

Copy link
Author

Choose a reason for hiding this comment

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

I fixed also the pipeline handling to display the name of the node and not the executor. I also added some integration tests using JenkinsRule.

properly get the node when BuildData is initilaized from a pipeline
pump mockito to latest version
add integration test, that use Jenkins test harness
@jakub-bochenski
Copy link

Will try to merge this soon. just need to find time to read through the latest commit

@jakub-bochenski jakub-bochenski merged commit cc4225b into jenkinsci:master Dec 22, 2017
mwinter69 added a commit to mwinter69/logstash-plugin that referenced this pull request Dec 27, 2017
properly get displayname of node (jenkinsci#38)
@mwinter69 mwinter69 deleted the fixNodeName branch December 30, 2017 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants