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

control-service: fix data job deployment cpu conversion #3109

Merged
merged 1 commit into from
Feb 14, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are the gradle jar and properties in source controL? I think those are dynamically downloaded on demand when needed.

distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ private void checkDeployment() throws Exception {
Assertions.assertFalse(jobDeployment.getEnabled());
Assertions.assertEquals(1000, jobDeployment.getResources().getMemoryLimit());
Assertions.assertEquals(500, jobDeployment.getResources().getMemoryRequest());
Assertions.assertEquals(2000, jobDeployment.getResources().getCpuLimit());
Assertions.assertEquals(1000, jobDeployment.getResources().getCpuRequest());
Assertions.assertEquals(2, jobDeployment.getResources().getCpuLimit());
Assertions.assertEquals(1, jobDeployment.getResources().getCpuRequest());
Assertions.assertNotNull(jobDeployment.getJobVersion());
Assertions.assertNotNull(jobDeployment.getContacts());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ private void setDefaultCpuRequestIfNeeded(DataJobDeploymentResources resources)
try {
if (resources.getCpuRequestCores() == null) {
String cpu = defaultConfigurations.dataJobRequests().getCpu();
resources.setCpuRequestCores(K8SMemoryConversionUtils.getCpuInFloat(cpu));
resources.setCpuRequestCores(K8SMemoryConversionUtils.getCpuInCores(cpu));
}
} catch (ParseException e) {
handleResourcesException(e);
Expand All @@ -468,7 +468,7 @@ private void setDefaultCpuLimitIfNeeded(DataJobDeploymentResources resources) {
try {
if (resources.getCpuLimitCores() == null) {
String cpu = defaultConfigurations.dataJobLimits().getCpu();
resources.setCpuLimitCores(K8SMemoryConversionUtils.getCpuInFloat(cpu));
resources.setCpuLimitCores(K8SMemoryConversionUtils.getCpuInCores(cpu));
}
} catch (ParseException e) {
handleResourcesException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ public static int getMemoryInMi(String memory) throws ParseException {
return getMemoryInMi(memoryAmount, memory);
}

public static float getCpuInFloat(String cpu) throws ParseException {
return NumberFormat.getInstance().parse(cpu).floatValue();
public static float getCpuInCores(String cpu) throws ParseException {
float value = NumberFormat.getInstance().parse(cpu).floatValue();

if (cpu != null && cpu.endsWith("m")) {
value = value / 1000;
}

return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.text.ParseException;

@SpringBootTest(classes = ControlplaneApplication.class)
public class DataJobDefaultConfigurationsTest {

Expand All @@ -35,16 +37,16 @@ public void testDefaultMemoryLimit() throws Exception {
@Test
public void testDefaultCpuRequest() throws Exception {
Assertions.assertEquals(
1000,
K8SMemoryConversionUtils.getCpuInFloat(
1,
K8SMemoryConversionUtils.getCpuInCores(
dataJobDefaultConfigurations.dataJobRequests().getCpu()));
}

@Test
public void testDefaultCpuLimit() throws Exception {
Assertions.assertEquals(
2000,
K8SMemoryConversionUtils.getCpuInFloat(
2,
K8SMemoryConversionUtils.getCpuInCores(
dataJobDefaultConfigurations.dataJobLimits().getCpu()));
}

Expand Down Expand Up @@ -77,4 +79,14 @@ public void testTbConversion() {
public void testTiConversion() {
Assertions.assertEquals(2097152, K8SMemoryConversionUtils.getMemoryInMi(2, "Ti"));
}

@Test
public void testCpuMilicoresConversion() throws ParseException {
Assertions.assertEquals(1, K8SMemoryConversionUtils.getCpuInCores("1000m"));
}

@Test
public void testCpuCoresConversion() throws ParseException {
Assertions.assertEquals(1, K8SMemoryConversionUtils.getCpuInCores("1"));
}
}