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

Added minimum uphours feature #377

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

snallami
Copy link
Member

@snallami snallami commented Jul 6, 2019

Added minimum uphours feature so that agent stays up for specified minimum hours before considering for termination. Once agent stayed for minimum number of hours other rules (like idle termination time) will get evaluated.

Why this feature is important?

Main use cases.

  1. Avoid agent spin up time. Windows agents in AWS takes somewhere around 10 to 20 minutes to spin up and without minimum uptime feature we see that builds are waiting longer for agent to be available. Linus agents spin up time is faster though compared to windows.

  2. Warm up ephemeral agents with caches(maven or npm or any other) so that actual developer builds can be faster and with the help of minimum uphours we can retain agent for 8 to 10 hours which helps in faster builds during development hours or working hours.

  3. Reserve capacity upfront for pre planned work.

  4. No need to depend on static agent for cache warmup.

And this is optional feature

Copy link
Contributor

@res0nance res0nance left a comment

Choose a reason for hiding this comment

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

Could you also write a test?

@@ -32,29 +32,29 @@
private static final Logger LOGGER = Logger.getLogger(EC2OndemandSlave.class.getName());

@Deprecated
public EC2OndemandSlave(String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType)
public EC2OndemandSlave(String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType, String minUpHours)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not add the new option to deprecated constructors

Copy link
Member Author

Choose a reason for hiding this comment

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

let me see if i can bypass them


public String getMinUpHours() {
return minUpHours;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Mind the indentation

Copy link
Member Author

Choose a reason for hiding this comment

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

hmmm , not sure why my eclipse is messing up formatting only for this line. Let me use text editor in next commit

@@ -33,23 +33,23 @@
private final String spotInstanceRequestId;

@Deprecated
public EC2SpotSlave(String name, String spotInstanceRequestId, String description, String remoteFS, int numExecutors, Mode mode, String initScript, String tmpDir, String labelString, String remoteAdmin, String jvmopts, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType)
public EC2SpotSlave(String name, String spotInstanceRequestId, String description, String remoteFS, int numExecutors, Mode mode, String initScript, String tmpDir, String labelString, String remoteAdmin, String jvmopts, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType, String minUpHours)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here on deprecated constructors

@@ -175,7 +177,7 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri
String instanceCapStr, String iamInstanceProfile, boolean deleteRootOnTermination,
boolean useEphemeralDevices, boolean useDedicatedTenancy, String launchTimeoutStr, boolean associatePublicIp,
String customDeviceMapping, boolean connectBySSHProcess, boolean monitoring,
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses) {
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses, String minUpHours) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Modifying the ctor this way also breaks backwards compat with groovy scripts

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you want me to add one more overloaded constructor?

Copy link
Contributor

Choose a reason for hiding this comment

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

Add another and deprecate the older one, is how it usually is handled. The older constructors should not take in new params and should provide a safe default. i.e the old behaviour.

Copy link
Member

Choose a reason for hiding this comment

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

Same here about the constructor. Same comment about the type (use int or Integer).

@snallami
Copy link
Member Author

snallami commented Jul 7, 2019

For some odd reason, I am not able to comment on review for minuphours=0 inline. Adding comment here.

If minuphours=0 then code evaluates other rule like idle termination time. See code @
https://gist.github.com/snallami/d917ec049e5d80e4206e2ce0cd2ef895

@snallami
Copy link
Member Author

snallami commented Jul 7, 2019

Thanks for review. I updated code as per review comments. Adding notes here as well.

  1. If minuphours=0 then code evaluates other rule like idle termination time. See code @
    https://gist.github.com/snallami/d917ec049e5d80e4206e2ce0cd2ef895

Need clarification

  1. I am not clear about what are the next steps about review comment "Modifying the ctor this way also breaks backwards compat with groovy scripts".

Let me know if you want me to add an overloaded constructor or modify groovy scripts.

  1. I will look into better way to add tests since check method always return 1

@res0nance
Copy link
Contributor

A good start to tests is an old testcase that would otherwise timeout should not timeout any longer.

2. Reverted previous changes in test cases and also removed minuphours in deprecated constructors.
3. Corrected logic in retention strategy.
4. Added test case for minuphours. Not all cases are covered sine idlemilliseconds method is final in computer onject
@@ -1 +0,0 @@
buildPlugin(configurations: buildPlugin.recommendedConfigurations())
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why this got deleted in my commit. let me submit a new commit

@thoulen thoulen requested a review from jvz July 14, 2019 19:57
Copy link
Member

@jvz jvz left a comment

Choose a reason for hiding this comment

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

Coming along nicely, thanks for the contribution! I've left some feedback on areas we need to fix before merging.

@@ -73,7 +76,7 @@
String.valueOf(STARTUP_TIME_DEFAULT_VALUE)), STARTUP_TIME_DEFAULT_VALUE);

@DataBoundConstructor
public EC2RetentionStrategy(String idleTerminationMinutes) {
public EC2RetentionStrategy(String idleTerminationMinutes, String minUpHours) {
Copy link
Member

Choose a reason for hiding this comment

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

You need to keep the old constructors and mark them @Deprecated in order to preserve backward compatibility as this class is public.

Also, you should use an argument type of either int (for a required value) or Integer (for a nullable one). I'd suggest OptionalInt as an argument type for the latter, though I'm not sure if that actually works with @DataBoundConstructor.

}

@DataBoundConstructor
public EC2OndemandSlave(String name, String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, boolean useDedicatedTenancy, int launchTimeout, AMITypeData amiType, ConnectionStrategy connectionStrategy, int maxTotalUses)
public EC2OndemandSlave(String name, String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, boolean useDedicatedTenancy, int launchTimeout, AMITypeData amiType, ConnectionStrategy connectionStrategy, int maxTotalUses, String minUpHours)
Copy link
Member

Choose a reason for hiding this comment

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

Same here; you need to create a new constructor and mark the old one @Deprecated.

I'll note that this sort of redundancy could be avoided by using a value object as the constructor argument rather than all of its attributes, but this would require a larger effort to fix at this point.

}

@DataBoundConstructor
public EC2SpotSlave(String name, String spotInstanceRequestId, String description, String remoteFS, int numExecutors, Mode mode, String initScript, String tmpDir, String labelString, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType, ConnectionStrategy connectionStrategy, int maxTotalUses)
public EC2SpotSlave(String name, String spotInstanceRequestId, String description, String remoteFS, int numExecutors, Mode mode, String initScript, String tmpDir, String labelString, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType, ConnectionStrategy connectionStrategy, int maxTotalUses, String minUpHours)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, need another constructor.

@@ -175,7 +177,7 @@ public SlaveTemplate(String ami, String zone, SpotConfiguration spotConfig, Stri
String instanceCapStr, String iamInstanceProfile, boolean deleteRootOnTermination,
boolean useEphemeralDevices, boolean useDedicatedTenancy, String launchTimeoutStr, boolean associatePublicIp,
String customDeviceMapping, boolean connectBySSHProcess, boolean monitoring,
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses) {
boolean t2Unlimited, ConnectionStrategy connectionStrategy, int maxTotalUses, String minUpHours) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here about the constructor. Same comment about the type (use int or Integer).

@@ -140,6 +140,8 @@

public int nextSubnet;

private String minUpHours;
Copy link
Member

Choose a reason for hiding this comment

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

This should be Integer for a nullable value, or int for a non-null value. Type conversion is handled automatically for you at the point of @DataBoundConstructor and @DataBoundSetter, so you can maintain the real type throughout your code.

@@ -177,6 +177,10 @@ THE SOFTWARE.
<f:entry title="${%Maximum Total Uses}" field="maxTotalUses">
<f:textbox default="-1"/>
</f:entry>

<f:entry title="Minimum uptime in hours" field="minUpHours">
<f:textbox default="0" />
Copy link
Member

Choose a reason for hiding this comment

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

This should use <f:number> instead. In fact, all the other textboxes in this form that are numeric should also use that.

@@ -0,0 +1,6 @@
<div>
<p> Retains ephemeral agents for specified hours before applying "idle termination minutes" rules.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
<p> Retains ephemeral agents for specified hours before applying "idle termination minutes" rules.
<p>Retains ephemeral agents for specified hours before applying "idle termination minutes" rules.</p>

@res0nance res0nance added the enhancement Feature additions or enhancements label Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature additions or enhancements
Projects
None yet
3 participants