Skip to content

Commit c99a929

Browse files
authored
feat: kubernetes deploy and real-time status update (#68)
* dev: generic methods for calculating percentiles * dev: javadocs style commenting * dev: change MTTFB percentile map value with Long * dev: stop status append * dev: already running errorcode append * dev: validation update * dev: agent stop event, avg cal, preftest update * dev: agent deploy as statefulSet * dev: status logging * dev: adjust test method * dev: stomp socket handling due to k8s * dev: remove unused ingress * dev: setup stomp with SockJS * dev: kubernetes profile agent loader * dev: docker buildx multiplatform image * dev: setup EUREKA k8s config * dev: local image pusher script * chore: undo issuer * dev: agent renewal parallel execution * chore: gradle clean and build * dev: websocket service exporter * dev: imagePulling always & eureka connect * dev: SockJS script src added * dev: ddl-auto validate to update * dev: spring cloud kubernetes import * dev: RBAC role & rolebinding to serviceaccount * dev: ingress rule update * dev: limiting resource * dev: tls issuer and connect to ingress
1 parent 4be50ce commit c99a929

File tree

49 files changed

+1278
-307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1278
-307
lines changed

.github/workflows/gke-cd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ jobs:
7272
run: chmod +x ./gradlew
7373

7474
- name: Build and test project
75-
run: ./gradlew build
75+
run: ./gradlew clean build
7676

7777
- name: Build docker image and push
7878
run: bash ./script/img_push_multi_arch.sh -u ${{ secrets.DOCKERHUB_USERNAME }} -t ${{ secrets.DOCKERHUB_TOKEN }}

bm-agent/src/main/java/org/benchmarker/bmagent/consts/PreftestConsts.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,30 @@
33
import java.util.Arrays;
44
import java.util.List;
55

6+
/**
7+
* Performance Test Constants
8+
*/
69
public interface PreftestConsts {
7-
List<Double> percentiles = Arrays.asList(50D, 90D, 95D,99D,99.9D);
10+
11+
/**
12+
* Required when measuring percentile of TPS and MTTFB(Mean Time To First Byte)
13+
*/
14+
List<Double> percentiles = Arrays.asList(50D, 90D, 95D, 99D, 99.9D);
15+
16+
/**
17+
* If performance test has error rate exceed {@link PreftestConsts#errorLimitRate}, instantly
18+
* shutdown all scheduler and emit event to bm-controller
19+
*/
20+
Double errorLimitRate = 50D;
21+
22+
/**
23+
* ErrorLimit Lookup process will be started after this time
24+
*/
25+
int errorLimitCheckDelay = 10;
26+
27+
/**
28+
* ErrorLimit Lookup process period
29+
*/
30+
int errorLimitCheckPeriod = 5;
831

932
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package org.benchmarker.bmagent.consts;
22

3+
/**
4+
* SSE constants
5+
*/
36
public interface SseManageConsts {
7+
8+
/**
9+
* SSE timeout constant
10+
*/
411
Long SSE_TIMEOUT = 600000L;
512
}

bm-agent/src/main/java/org/benchmarker/bmagent/consts/SystemSchedulerConst.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
package org.benchmarker.bmagent.consts;
22

3+
/**
4+
* System Scheduler constants
5+
*/
36
public interface SystemSchedulerConst {
47

58
/**
69
* System scheduler will run in this ID
710
*/
811
Long systemSchedulerId = -100L;
12+
13+
/**
14+
* System scheduler's name
15+
*/
916
String systemUsageSchedulerName = "cpu-memory-usage-update";
17+
18+
/**
19+
* @deprecated since 2024-03-28
20+
*/
1021
Integer connectControllerTimeout = 10; // seconds
22+
23+
/**
24+
* @deprecated since 2024-03-28
25+
*/
1126
Integer connectionFailedLimit = 50;
1227

1328

bm-agent/src/main/java/org/benchmarker/bmagent/controller/AgentApiController.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.benchmarker.bmagent.controller;
22

33

4-
import jakarta.servlet.http.HttpServletRequest;
4+
import java.io.IOException;
5+
import java.net.InetAddress;
6+
import java.net.UnknownHostException;
57
import java.util.Map;
68
import java.util.Set;
79
import lombok.RequiredArgsConstructor;
@@ -21,11 +23,15 @@
2123
import org.springframework.web.bind.annotation.RequestMapping;
2224
import org.springframework.web.bind.annotation.RequestParam;
2325
import org.springframework.web.bind.annotation.RestController;
24-
import org.springframework.web.context.request.RequestContextHolder;
25-
import org.springframework.web.context.request.ServletRequestAttributes;
2626
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
2727

28-
28+
/**
29+
* Main RESTAPI endpoint
30+
*
31+
* <p>
32+
* bm-controller will send request to here for performance testing
33+
* </p>
34+
*/
2935
@RestController
3036
@RequiredArgsConstructor
3137
@RequestMapping("/api")
@@ -46,15 +52,16 @@ public class AgentApiController {
4652
@PostMapping("/groups/{group_id}/templates/{template_id}")
4753
public SseEmitter manageSSE(@PathVariable("template_id") Long templateId,
4854
@PathVariable("group_id") String groupId,
49-
@RequestParam("action") String action, @RequestBody TemplateInfo templateInfo) {
55+
@RequestParam("action") String action, @RequestBody TemplateInfo templateInfo)
56+
throws IOException {
5057
log.info(templateInfo.toString());
5158

5259
if (action.equals("start")) {
5360
agentStatusManager.getAndUpdateStatusIfReady(
5461
AgentStatus.TESTING).orElseThrow(() -> new RuntimeException("agent is not ready"));
5562
return sseManageService.start(templateId, groupId, templateInfo);
5663
} else {
57-
sseManageService.stop(templateId);
64+
sseManageService.stopSign(templateId);
5865
return null;
5966
}
6067
}
@@ -70,23 +77,26 @@ public ResponseEntity<Map<Long, SchedulerStatus>> getSchedulersStatus() {
7077
}
7178

7279
@GetMapping("/status")
73-
public AgentInfo getStatus() {
74-
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
75-
String scheme = request.getScheme(); // http or https
76-
String serverName = request.getServerName();
77-
int serverPort = request.getServerPort();
78-
Set<Long> longs = scheduledTaskService.getStatus().keySet();
80+
public AgentInfo getStatus() throws UnknownHostException {
81+
log.info("Check current status");
82+
InetAddress localHost = InetAddress.getLocalHost();
83+
String serverAddress = localHost.getHostAddress();
84+
String scheme = "http"; // Assuming it's always HTTP when accessed locally
85+
int serverPort = 8081; // Assuming default port is 8080
7986

80-
String agentServerUrl = scheme + "://" + serverName + ":" + serverPort;
87+
Set<Long> longs = scheduledTaskService.getStatus().keySet();
8188

82-
return AgentInfo.builder()
89+
String agentServerUrl = scheme + "://" + serverAddress + ":" + serverPort;
90+
AgentInfo info = AgentInfo.builder()
8391
.templateId(longs)
8492
.cpuUsage(agentStatusManager.getCpuUsage())
8593
.memoryUsage(agentStatusManager.getMemoryUsage())
8694
.startedAt(agentStatusManager.getStartedAt())
8795
.serverUrl(agentServerUrl)
8896
.status(agentStatusManager.getStatus().get())
8997
.build();
98+
log.info(info.toString());
99+
return info;
90100
}
91101
}
92102

bm-agent/src/main/java/org/benchmarker/bmagent/initializer/Initializer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
import org.springframework.context.annotation.Profile;
1414
import org.springframework.stereotype.Component;
1515

16+
/**
17+
* The Initializer class is responsible for <strong>initializing various components of the
18+
* application when it starts up</strong>.
19+
*
20+
* <p>
21+
* The Initializer will start system scheduler which recording CPU / MEMORY usage in every seconds
22+
*/
1623
@Component
1724
@Profile("!test")
1825
@Slf4j
@@ -26,7 +33,6 @@ public class Initializer implements CommandLineRunner, ApplicationContextAware {
2633

2734
@Override
2835
public void run(String... args) throws Exception {
29-
log.info("init");
3036
// cpu, memory usage checker
3137
scheduledTaskService.startChild(SystemSchedulerConst.systemSchedulerId,
3238
SystemSchedulerConst.systemUsageSchedulerName, agentStatusManager::updateStats, 0, 1,

0 commit comments

Comments
 (0)