feat: 유량제어 그룹 버킷 분리 및 현황 화면 개선

- CustomGroupBucket 클래스 신규 생성: 초당/추가 임계치를 별도 LocalBucket으로 분리하여 개별 토큰 조회 가능
  - InflowControlManager 수정: groupBucketList 타입을 CustomGroupBucket으로 변경, makeGroupBucket() 메서드 추가
  - InflowGroupBucketService 단순화: 복잡한 리플렉션 로직 제거, CustomGroupBucket 직접 메서드 사용
  - 현황 탭에 전체 인스턴스 합산 요약 추가 (활성 인스턴스 수, 초당/추가 임계치 합산)
  - 추가 임계치 시간단위에서 '초(SEC)' 옵션 제거
  - 저장 완료 후 리스트 화면 이동 제거
This commit is contained in:
yunjy-hp
2025-12-11 11:03:59 +09:00
parent d6c2ef4cd6
commit 74aeddf838
5 changed files with 315 additions and 0 deletions
@@ -0,0 +1,105 @@
package com.eactive.eai.manage.inflow;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Service;
import com.eactive.eai.common.inflow.CustomGroupBucket;
import com.eactive.eai.common.inflow.InflowControlManager;
import com.eactive.eai.common.inflow.InflowGroupVO;
@Service
public class InflowGroupBucketService {
public GroupBucketStatusDTO getGroupBucketStatus(String groupId) {
InflowControlManager manager = InflowControlManager.getInstance();
InflowGroupVO groupVo = manager.getGroupInflowThreshold(groupId);
if (groupVo == null) {
return null;
}
GroupBucketStatusDTO dto = new GroupBucketStatusDTO();
dto.setGroupId(groupId);
dto.setGroupName(groupVo.getGroupName());
dto.setActivate(groupVo.isActivate());
List<GroupBucketStatusDTO.BucketInfo> buckets = new ArrayList<>();
// CustomGroupBucket에서 직접 토큰 조회
CustomGroupBucket customGroupBucket = getCustomGroupBucket(groupId);
// perSecond bucket
if (groupVo.getThresholdPerSecond() > 0) {
long capacity = groupVo.getThresholdPerSecond();
long available = capacity;
if (customGroupBucket != null) {
long tokens = customGroupBucket.getPerSecondAvailableTokens();
if (tokens >= 0) {
available = Math.min(tokens, capacity);
}
}
buckets.add(new GroupBucketStatusDTO.BucketInfo(
"perSecond",
capacity,
available,
"SEC"
));
}
// threshold bucket
if (groupVo.getThreshold() > 0) {
long capacity = groupVo.getThreshold();
long available = capacity;
if (customGroupBucket != null) {
long tokens = customGroupBucket.getThresholdAvailableTokens();
if (tokens >= 0) {
available = Math.min(tokens, capacity);
}
}
buckets.add(new GroupBucketStatusDTO.BucketInfo(
"threshold",
capacity,
available,
groupVo.getThresholdTimeUnit()
));
}
dto.setBuckets(buckets);
return dto;
}
/**
* 그룹 버킷 조회 (리플렉션 사용)
*/
public CustomGroupBucket getCustomGroupBucket(String groupId) {
try {
InflowControlManager manager = InflowControlManager.getInstance();
Field field = InflowControlManager.class.getDeclaredField("groupBucketList");
field.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, CustomGroupBucket> groupBucketList =
(Map<String, CustomGroupBucket>) field.get(manager);
return groupBucketList.get(groupId);
} catch (Exception e) {
return null;
}
}
public List<GroupBucketStatusDTO> getAllGroupBucketStatus() {
InflowControlManager manager = InflowControlManager.getInstance();
String[] groupIds = manager.getGroupAllKeys();
List<GroupBucketStatusDTO> result = new ArrayList<>();
for (String groupId : groupIds) {
GroupBucketStatusDTO dto = getGroupBucketStatus(groupId);
if (dto != null) {
result.add(dto);
}
}
return result;
}
}