Skip to content

Commit 4f27ba8

Browse files
authored
Merge pull request #255 from ish-hcc/main
fix: java: Prevent multiple request conflicts, Fix log API, Remove NVIDIA measurement
2 parents 30cb20a + d19ef5a commit 4f27ba8

File tree

9 files changed

+149
-105
lines changed

9 files changed

+149
-105
lines changed

java/mc-o11y-manager/src/main/java/com/mcmp/o11ymanager/manager/controller/LogController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ public class LogController {
1818
@GetMapping("/query_range")
1919
public ResBody<LogSummaryDto.ResultDto> queryRangeLogs(
2020
@RequestParam String query,
21-
@RequestParam String start,
22-
@RequestParam String end,
21+
@RequestParam(required = false) String start,
22+
@RequestParam(required = false) String end,
2323
@RequestParam int limit,
2424
@RequestParam(required = false) String direction,
2525
@RequestParam(required = false) String interval,

java/mc-o11y-manager/src/main/java/com/mcmp/o11ymanager/manager/facade/AgentFacadeService.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.mcmp.o11ymanager.manager.service.interfaces.VMService;
1919
import java.util.ArrayList;
2020
import java.util.List;
21-
import java.util.concurrent.ConcurrentHashMap;
2221
import java.util.concurrent.locks.Lock;
2322
import java.util.concurrent.locks.ReentrantLock;
2423
import lombok.RequiredArgsConstructor;
@@ -40,17 +39,11 @@ public class AgentFacadeService {
4039

4140
private final FluentBitFacadeService fluentBitFacadeService;
4241
private final TelegrafFacadeService telegrafFacadeService;
43-
private final ConcurrentHashMap<String, ReentrantLock> repositoryLocks =
44-
new ConcurrentHashMap<>();
4542
private final TumblebugService tumblebugService;
4643
private final VMService vmService;
4744

48-
private ReentrantLock getAgentLock(String nsId, String mciId, String vmId) {
49-
String lockKey = nsId + "-" + mciId + "-" + vmId;
50-
return repositoryLocks.computeIfAbsent(lockKey, k -> new ReentrantLock());
51-
}
52-
5345
private AccessInfoDTO getAccessInfo(String nsId, String mciId, String vmId) {
46+
5447
TumblebugMCI.Vm vm = tumblebugPort.getVM(nsId, mciId, vmId);
5548
TumblebugSshKey sshKey = tumblebugPort.getSshKey(nsId, vm.getSshKeyId());
5649

@@ -82,7 +75,6 @@ public List<ResultDTO> install(String nsId, String mciId, String vmId) {
8275
vmId);
8376

8477
List<ResultDTO> results = new ArrayList<>();
85-
ReentrantLock agentLock = getAgentLock(nsId, mciId, vmId);
8678

8779
try {
8880
AccessInfoDTO accessInfo = getAccessInfo(nsId, mciId, vmId);
@@ -98,7 +90,6 @@ public List<ResultDTO> install(String nsId, String mciId, String vmId) {
9890

9991
// 2) Install agent
10092
// 2-1) Install Telegraf
101-
agentLock.lock();
10293
telegrafFacadeService.install(nsId, mciId, vmId, accessInfo, templateCount);
10394

10495
// 2-2) Install FluentBit
@@ -121,10 +112,6 @@ public List<ResultDTO> install(String nsId, String mciId, String vmId) {
121112
.status(ResponseStatus.ERROR)
122113
.errorMessage(e.getMessage())
123114
.build());
124-
} finally {
125-
if (agentLock.isLocked()) {
126-
agentLock.unlock();
127-
}
128115
}
129116

130117
return results;
@@ -133,7 +120,6 @@ public List<ResultDTO> install(String nsId, String mciId, String vmId) {
133120
@Transactional
134121
public List<ResultDTO> update(String nsId, String mciId, String vmId) {
135122
List<ResultDTO> results = new ArrayList<>();
136-
ReentrantLock agentLock = getAgentLock(nsId, mciId, vmId);
137123

138124
try {
139125
AccessInfoDTO accessInfo = getAccessInfo(nsId, mciId, vmId);
@@ -149,7 +135,6 @@ public List<ResultDTO> update(String nsId, String mciId, String vmId) {
149135

150136
// 2 ) 에이전트 업데이트
151137
// 2-1 ) Telegraf 업데이트
152-
agentLock.lock();
153138
telegrafFacadeService.update(nsId, mciId, vmId, accessInfo, templateCount);
154139

155140
// 2-1 ) FluentBit 업데이트
@@ -171,10 +156,6 @@ public List<ResultDTO> update(String nsId, String mciId, String vmId) {
171156
.status(ResponseStatus.ERROR)
172157
.errorMessage(e.getMessage())
173158
.build());
174-
} finally {
175-
if (agentLock.isLocked()) {
176-
agentLock.unlock();
177-
}
178159
}
179160

180161
return results;
@@ -231,7 +212,6 @@ public List<ResultDTO> uninstall(String nsId, String mciId, String vmId) {
231212

232213
List<ResultDTO> results = new ArrayList<>();
233214

234-
ReentrantLock agentLock = getAgentLock(nsId, mciId, vmId);
235215
AccessInfoDTO accessInfo = getAccessInfo(nsId, mciId, vmId);
236216

237217
try {
@@ -245,7 +225,6 @@ public List<ResultDTO> uninstall(String nsId, String mciId, String vmId) {
245225

246226
// 4 ) 에이전트 제거
247227
// 4-1 ) Telegraf 제거
248-
agentLock.lock();
249228
telegrafFacadeService.uninstall(nsId, mciId, vmId, accessInfo, templateCount);
250229

251230
// 4-1 ) FluentBit 제거
@@ -267,11 +246,6 @@ public List<ResultDTO> uninstall(String nsId, String mciId, String vmId) {
267246
.status(ResponseStatus.ERROR)
268247
.errorMessage(e.getMessage())
269248
.build());
270-
271-
} finally {
272-
if (agentLock.isLocked()) {
273-
agentLock.unlock();
274-
}
275249
}
276250

277251
return results;

java/mc-o11y-manager/src/main/java/com/mcmp/o11ymanager/manager/facade/ItemFacadeService.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Base64;
1616
import java.util.List;
1717
import java.util.Map;
18+
import java.util.concurrent.locks.ReentrantLock;
1819
import java.util.regex.Matcher;
1920
import java.util.regex.Pattern;
2021
import java.util.stream.Collectors;
@@ -48,7 +49,12 @@ private String getTelegrafConfigPath() {
4849

4950
public void addTelegrafPlugin(
5051
String nsId, String mciId, String vmId, MonitoringItemRequestDTO dto) {
52+
53+
ReentrantLock hostLock = vmService.getHostLock(nsId, mciId, vmId);
54+
5155
try {
56+
hostLock.lock();
57+
5258
TumblebugMCI.Vm vm = tumblebugService.getVm(nsId, mciId, vmId);
5359
if (vm == null) {
5460
String errorMsg = String.format("VM not found for vm: %s/%s/%s", nsId, mciId, vmId);
@@ -112,12 +118,19 @@ public void addTelegrafPlugin(
112118
log.error(errorMsg, e);
113119
throw new TelegrafConfigException(
114120
ResponseCode.INTERNAL_SERVER_ERROR, errorMsg + ": " + e.getMessage());
121+
} finally {
122+
hostLock.unlock();
115123
}
116124
}
117125

118126
public void updateTelegrafPlugin(
119127
String nsId, String mciId, String vmId, MonitoringItemUpdateDTO dto) {
128+
129+
ReentrantLock hostLock = vmService.getHostLock(nsId, mciId, vmId);
130+
120131
try {
132+
hostLock.lock();
133+
121134
TumblebugMCI.Vm vm = tumblebugService.getVm(nsId, mciId, vmId);
122135
if (vm == null) {
123136
String errorMsg = String.format("VM not found for vm: %s/%s/%s", nsId, mciId, vmId);
@@ -178,11 +191,18 @@ public void updateTelegrafPlugin(
178191
log.error(errorMsg, e);
179192
throw new TelegrafConfigException(
180193
ResponseCode.INTERNAL_SERVER_ERROR, errorMsg + ": " + e.getMessage());
194+
} finally {
195+
hostLock.unlock();
181196
}
182197
}
183198

184199
public void deleteTelegrafPlugin(String nsId, String mciId, String vmId, Long itemSeq) {
200+
201+
ReentrantLock hostLock = vmService.getHostLock(nsId, mciId, vmId);
202+
185203
try {
204+
hostLock.lock();
205+
186206
TumblebugMCI.Vm vm = tumblebugService.getVm(nsId, mciId, vmId);
187207
if (vm == null) {
188208
String errorMsg = String.format("VM not found for vm: %s/%s/%s", nsId, mciId, vmId);
@@ -229,7 +249,6 @@ public void deleteTelegrafPlugin(String nsId, String mciId, String vmId, Long it
229249
tumblebugService.executeCommand(nsId, mciId, vmId, updateCommand);
230250

231251
telegrafFacadeService.restart(nsId, mciId, vmId);
232-
233252
} catch (TelegrafConfigException e) {
234253
throw e;
235254
} catch (Exception e) {
@@ -239,6 +258,8 @@ public void deleteTelegrafPlugin(String nsId, String mciId, String vmId, Long it
239258
log.error(errorMsg, e);
240259
throw new TelegrafConfigException(
241260
ResponseCode.INTERNAL_SERVER_ERROR, errorMsg + ": " + e.getMessage());
261+
} finally {
262+
hostLock.unlock();
242263
}
243264
}
244265

@@ -247,7 +268,11 @@ private String toPluginId(String name, String type) {
247268
}
248269

249270
public List<MonitoringItemDTO> getTelegrafItems(String nsId, String mciId, String vmId) {
271+
272+
ReentrantLock hostLock = vmService.getHostLock(nsId, mciId, vmId);
273+
250274
try {
275+
hostLock.lock();
251276

252277
if (!tumblebugService.isConnectedVM(nsId, mciId, vmId)) {
253278
String errorMsg =
@@ -315,6 +340,8 @@ public List<MonitoringItemDTO> getTelegrafItems(String nsId, String mciId, Strin
315340
log.error(errorMsg, e);
316341
throw new TelegrafConfigException(
317342
ResponseCode.INTERNAL_SERVER_ERROR, errorMsg + ": " + e.getMessage());
343+
} finally {
344+
hostLock.unlock();
318345
}
319346
}
320347

java/mc-o11y-manager/src/main/java/com/mcmp/o11ymanager/manager/facade/LogFacadeService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,20 @@ public LogSummaryDto.ResultDto getRangeLogs(
4848
String interval,
4949
String step,
5050
String since) {
51-
LogCriteria criteria =
52-
LogCriteria.ofRange(query, start, end, limit, direction, interval, step, since);
51+
LogCriteria criteria;
52+
53+
if ((start == null || start.isEmpty())
54+
&& (end == null || end.isEmpty())
55+
&& (direction == null || direction.isEmpty())
56+
&& (interval == null || interval.isEmpty())
57+
&& (step == null || step.isEmpty())
58+
&& (since == null || since.isEmpty())) {
59+
criteria = LogCriteria.of(query, limit);
60+
} else {
61+
criteria =
62+
LogCriteria.ofRange(query, start, end, limit, direction, interval, step, since);
63+
}
64+
5365
Log log = lokiService.getRangeLogs(criteria);
5466
LogResponseDto responseDto = LogResponseMapper.toDto(log);
5567
return LogSummaryMapper.toResultDto(responseDto, direction);

java/mc-o11y-manager/src/main/java/com/mcmp/o11ymanager/manager/facade/TelegrafConfigFacadeService.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public class TelegrafConfigFacadeService {
4242
new ClassPathResource("telegraf_inputs_swap");
4343
private final ClassPathResource telegrafConfigInputsSystem =
4444
new ClassPathResource("telegraf_inputs_system");
45-
private final ClassPathResource telegrafConfigInputsNVIDIASMI =
46-
new ClassPathResource("telegraf_inputs_nvidia_smi");
4745
private final ClassPathResource telegrafConfigOutputsInfluxDB =
4846
new ClassPathResource("telegraf_outputs_influxdb");
4947

@@ -56,7 +54,6 @@ public class TelegrafConfigFacadeService {
5654
public static final String CONFIG_METRIC_PROCSTAT = "procstat";
5755
public static final String CONFIG_METRIC_SWAP = "swap";
5856
public static final String CONFIG_METRIC_SYSTEM = "system";
59-
public static final String CONFIG_METRIC_GPU = "gpu";
6057

6158
public static final String CONFIG_DEFAULT_METRICS =
6259
CONFIG_METRIC_CPU
@@ -156,12 +153,6 @@ public String generateTelegrafConfig(String nsId, String mciId, String vmId, Str
156153
throw new RuntimeException(errMsg);
157154
}
158155

159-
if (!telegrafConfigInputsNVIDIASMI.exists()) {
160-
errMsg = "Invalid filePath : telegrafConfigInputsNVIDIASMI";
161-
log.error(errMsg);
162-
throw new RuntimeException(errMsg);
163-
}
164-
165156
if (!telegrafConfigOutputsInfluxDB.exists()) {
166157
errMsg = "Invalid filePath : telegrafConfigOutputsInfluxDB";
167158
log.error(errMsg);
@@ -209,9 +200,6 @@ public String generateTelegrafConfig(String nsId, String mciId, String vmId, Str
209200
case CONFIG_METRIC_SYSTEM:
210201
fileService.appendConfig(telegrafConfigInputsSystem, sb);
211202
break;
212-
case CONFIG_METRIC_GPU:
213-
fileService.appendConfig(telegrafConfigInputsNVIDIASMI, sb);
214-
break;
215203
default:
216204
throw new RuntimeException("Invalid metric: " + metric);
217205
}

0 commit comments

Comments
 (0)