Skip to content

Commit e319e43

Browse files
vudayaniV Udayani
and
V Udayani
authored
Log Levels View
* fetch and display loglevels * change log levels for packages * clean up logs * address review comments * switch the CONNECT_TO_LS key * Avoid caching loggers data * add copyright headers --------- Co-authored-by: V Udayani <vudayani@vudayaniSMD6M.vmware.com>
1 parent f27c423 commit e319e43

File tree

23 files changed

+894
-6
lines changed

23 files changed

+894
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.commons.protocol;
12+
13+
public record LiveProcessLoggersSummary(String processType, String processKey, String processName, String processID,
14+
String packageName, String effectiveLevel, String configuredLevel) {
15+
16+
}

headless-services/commons/commons-lsp-extensions/src/main/java/org/springframework/ide/vscode/commons/protocol/STS4LanguageClient.java

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public interface STS4LanguageClient extends LanguageClient, SpringIndexLanguageC
5151

5252
@JsonNotification("sts/liveprocess/gcpauses/metrics/updated")
5353
void liveProcessGcPausesMetricsDataUpdated(LiveProcessSummary processKey);
54+
55+
@JsonNotification("sts/liveprocess/loglevel/updated")
56+
void liveProcessLogLevelUpdated(LiveProcessLoggersSummary liveProcessLoggersSummary);
5457

5558
@JsonNotification("sts/highlight")
5659
void highlight(HighlightParams highlights);

headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/LanguageServerHarness.java

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
115115
import org.springframework.ide.vscode.commons.protocol.CursorMovement;
116116
import org.springframework.ide.vscode.commons.protocol.HighlightParams;
117+
import org.springframework.ide.vscode.commons.protocol.LiveProcessLoggersSummary;
117118
import org.springframework.ide.vscode.commons.protocol.LiveProcessSummary;
118119
import org.springframework.ide.vscode.commons.protocol.STS4LanguageClient;
119120
import org.springframework.ide.vscode.commons.protocol.java.ClasspathListenerParams;
@@ -437,6 +438,10 @@ public void indexUpdated() {
437438
receiveIndexUpdated();
438439
}
439440

441+
@Override
442+
public void liveProcessLogLevelUpdated(LiveProcessLoggersSummary processKey) {
443+
}
444+
440445
});
441446

442447
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/ActuatorConnection.java

+4
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,8 @@ public interface ActuatorConnection {
3333
Map<?, ?> getStartup() throws IOException;
3434

3535
String getLiveMetrics(String metricName, String tags) throws IOException;
36+
37+
String getLoggers() throws IOException;
38+
39+
String configureLogLevel(Map<String, String> args) throws IOException;
3640
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/HttpActuatorConnection.java

+15
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ public String getBeans() throws IOException {
8080
return restTemplate.getForObject("/beans", String.class);
8181
}
8282

83+
@Override
84+
public String getLoggers() throws IOException {
85+
return restTemplate.getForObject("/loggers", String.class);
86+
}
87+
88+
@Override
89+
public String configureLogLevel(Map<String, String> args) throws IOException {
90+
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath("/loggers/"+args.get("packageName"));
91+
if (args != null) {
92+
uriBuilder.queryParam("configuredLevel", args.get("configuredLevel"));
93+
}
94+
String url = actuatorUrl + uriBuilder.toUriString();
95+
return restTemplate.postForObject(URI.create(url), null, String.class);
96+
}
97+
8398
@Override
8499
public String getLiveMetrics(String metricName, String tags) throws IOException {
85100
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath("/metrics/"+metricName);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.boot.java.livehover.v2;
12+
13+
/**
14+
* @author Udayani V
15+
*/
16+
public class LoggerInfo {
17+
18+
private String configuredLevel;
19+
20+
private String effectiveLevel;
21+
22+
public String getConfiguredLevel() {
23+
return configuredLevel;
24+
}
25+
public String getEffectiveLevel() {
26+
return effectiveLevel;
27+
}
28+
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2023 Broadcom, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* https://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Broadcom, Inc. - initial API and implementation
10+
*******************************************************************************/
11+
package org.springframework.ide.vscode.boot.java.livehover.v2;
12+
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
17+
18+
/**
19+
* @author Udayani V
20+
*/
21+
@JsonIgnoreProperties(ignoreUnknown = true)
22+
public class Loggers {
23+
24+
private List<String> levels;
25+
private Map<String, LoggerInfo> loggers;
26+
27+
public List<String> getLevels() {
28+
return levels;
29+
}
30+
31+
public Map<String, LoggerInfo> getLoggers() {
32+
return loggers;
33+
}
34+
35+
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessCommandHandler.java

+43
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.ArrayList;
1414
import java.util.Collection;
15+
import java.util.HashMap;
1516
import java.util.HashSet;
1617
import java.util.List;
1718
import java.util.Map;
@@ -43,6 +44,8 @@ public class SpringProcessCommandHandler {
4344
private static final String COMMAND_LIST_CONNECTED = "sts/livedata/listConnected";
4445
private static final String COMMAND_GET_METRICS = "sts/livedata/get/metrics";
4546
private static final String COMMAND_GET_REFRESH_METRICS = "sts/livedata/refresh/metrics";
47+
private static final String COMMAND_GET_LOGGERS = "sts/livedata/getLoggers";
48+
private static final String COMMAND_CONFIGURE_LOGLEVEL = "sts/livedata/configure/logLevel";
4649

4750
private final SpringProcessConnectorService connectorService;
4851
private final SpringProcessConnectorLocal localProcessConnector;
@@ -88,6 +91,16 @@ public SpringProcessCommandHandler(SimpleLanguageServer server, SpringProcessCon
8891
return refreshMetrics(params);
8992
});
9093
log.info("Registered command handler: {}",COMMAND_GET_METRICS);
94+
95+
server.onCommand(COMMAND_GET_LOGGERS, (params) -> {
96+
return getLoggers(params);
97+
});
98+
log.info("Registered command handler: {}",COMMAND_GET_LOGGERS);
99+
100+
server.onCommand(COMMAND_CONFIGURE_LOGLEVEL, (params) -> {
101+
return configureLogLevel(params);
102+
});
103+
log.info("Registered command handler: {}",COMMAND_CONFIGURE_LOGLEVEL);
91104

92105
server.onCommand(COMMAND_LIST_CONNECTED, (params) -> {
93106
List<LiveProcessSummary> result = new ArrayList<>();
@@ -320,4 +333,34 @@ private CompletableFuture<Object> handleLiveMetricsProcessRequest(ExecuteCommand
320333
return CompletableFuture.completedFuture(null);
321334
}
322335

336+
337+
private CompletableFuture<Object> getLoggers(ExecuteCommandParams params) {
338+
SpringProcessLoggersData loggersData = null;
339+
SpringProcessParams springProcessParams = new SpringProcessParams();
340+
springProcessParams.setProcessKey(getProcessKey(params));
341+
springProcessParams.setEndpoint(getArgumentByKey(params, "endpoint"));
342+
if (springProcessParams.getProcessKey() != null) {
343+
loggersData = connectorService.getLoggers(springProcessParams);
344+
return CompletableFuture.completedFuture(loggersData);
345+
}
346+
347+
return CompletableFuture.completedFuture(loggersData);
348+
}
349+
350+
private CompletableFuture<Object> configureLogLevel(ExecuteCommandParams params) {
351+
Map<String, String> args = new HashMap<>();
352+
args.put("packageName", getArgumentByKey(params, "packageName"));
353+
args.put("configuredLevel", getArgumentByKey(params, "configuredLevel"));
354+
args.put("effectiveLevel", getArgumentByKey(params, "effectiveLevel"));
355+
SpringProcessParams springProcessParams = new SpringProcessParams();
356+
springProcessParams.setProcessKey(getProcessKey(params));
357+
springProcessParams.setArgs(args);
358+
359+
if (springProcessParams.getProcessKey() != null) {
360+
connectorService.configureLogLevel(springProcessParams);
361+
}
362+
363+
return CompletableFuture.completedFuture(null);
364+
}
365+
323366
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnector.java

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.boot.java.livehover.v2;
1212

13+
import java.util.Map;
14+
1315
/**
1416
* @author Martin Lippert
1517
*/
@@ -29,4 +31,6 @@ public interface SpringProcessConnector {
2931
String getProcessName();
3032
SpringProcessGcPausesMetricsLiveData refreshGcPausesMetrics(SpringProcessLiveData current, String metricName, String tags) throws Exception;
3133
SpringProcessMemoryMetricsLiveData refreshMemoryMetrics(SpringProcessLiveData current, String metricName, String tags) throws Exception;
34+
SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData) throws Exception;
35+
SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception;
3236
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverHttp.java

+45
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
*******************************************************************************/
1111
package org.springframework.ide.vscode.boot.java.livehover.v2;
1212

13+
import java.util.Map;
14+
1315
public class SpringProcessConnectorOverHttp implements SpringProcessConnector {
1416

1517
private final ProcessType processType;
@@ -157,6 +159,49 @@ public SpringProcessMemoryMetricsLiveData refreshMemoryMetrics(SpringProcessLive
157159

158160
throw new Exception("no live memory metrics data received, lets try again");
159161
}
162+
163+
164+
@Override
165+
public SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData)
166+
throws Exception {
167+
if (actuatorConnection != null) {
168+
SpringProcessLoggersData loggersData = new SpringProcessLiveDataExtractorOverHttp().retrieveLoggersData(getProcessType(), actuatorConnection, processID, processName, currentData);
169+
170+
if (this.processID == null) {
171+
this.processID = loggersData.getProcessID();
172+
}
173+
174+
if (this.processName == null) {
175+
this.processName = loggersData.getProcessName();
176+
}
177+
178+
if (loggersData != null && loggersData.getLoggers() != null) {
179+
return loggersData;
180+
}
181+
}
182+
183+
throw new Exception("no loggers data received, lets try again");
184+
}
185+
186+
187+
@Override
188+
public SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
189+
if (actuatorConnection != null) {
190+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = new SpringProcessLiveDataExtractorOverHttp().configureLogLevel(getProcessType(), actuatorConnection, processID, processName, currentData, args);
191+
192+
if (this.processID == null) {
193+
this.processID = springProcessUpdatedLoggersData.getProcessID();
194+
}
195+
196+
if (this.processName == null) {
197+
this.processName = springProcessUpdatedLoggersData.getProcessName();
198+
return springProcessUpdatedLoggersData;
199+
}
200+
201+
}
202+
203+
throw new Exception("configure log levels failed, lets try again");
204+
}
160205

161206

162207
}

headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/livehover/v2/SpringProcessConnectorOverJMX.java

+44
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,50 @@ public void disconnect() throws Exception {
210210
log.error("error closing the JMX connection for: " + jmxURL, e);
211211
}
212212
}
213+
214+
@Override
215+
public SpringProcessLoggersData getLoggers(SpringProcessLiveData currentData) throws Exception {
216+
log.info("try to open JMX connection to: " + jmxURL);
217+
218+
if (jmxConnection != null) {
219+
try {
220+
SpringProcessLiveDataExtractorOverJMX springJMXConnector = new SpringProcessLiveDataExtractorOverJMX();
221+
222+
log.info("retrieve live data from: " + jmxURL);
223+
SpringProcessLoggersData loggersData = springJMXConnector.retrieveLoggersData(getProcessType(), jmxConnection, processID, processName, currentData);
224+
225+
if (loggersData != null) {
226+
return loggersData;
227+
}
228+
}
229+
catch (Exception e) {
230+
log.error("exception while connecting to jmx: " + jmxURL, e);
231+
}
232+
}
233+
234+
throw new Exception("no loggers data received, lets try again");
235+
}
236+
237+
@Override
238+
public SpringProcessUpdatedLogLevelData configureLogLevel(SpringProcessLiveData currentData, Map<String, String> args) throws Exception {
239+
log.info("try to open JMX connection to: " + jmxURL);
240+
241+
if (jmxConnection != null) {
242+
try {
243+
SpringProcessLiveDataExtractorOverJMX springJMXConnector = new SpringProcessLiveDataExtractorOverJMX();
244+
245+
log.info("retrieve live data from: " + jmxURL);
246+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = springJMXConnector.configureLogLevel(getProcessType(), jmxConnection, processID, processName, currentData, args);
247+
248+
return springProcessUpdatedLoggersData;
249+
}
250+
catch (Exception e) {
251+
log.error("exception while connecting to jmx: " + jmxURL, e);
252+
}
253+
}
254+
255+
throw new Exception("configure log level failed, lets try again");
256+
}
213257

214258
@Override
215259
public void addConnectorChangeListener(SpringProcessConnectionChangeListener listener) {

0 commit comments

Comments
 (0)