Skip to content

Commit 59fc4ac

Browse files
V UdayaniV Udayani
V Udayani
authored and
V Udayani
committed
Avoid caching loggers data
1 parent 8c00f7e commit 59fc4ac

File tree

7 files changed

+64
-85
lines changed

7 files changed

+64
-85
lines changed

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
@@ -52,9 +52,6 @@ public interface STS4LanguageClient extends LanguageClient, SpringIndexLanguageC
5252
@JsonNotification("sts/liveprocess/gcpauses/metrics/updated")
5353
void liveProcessGcPausesMetricsDataUpdated(LiveProcessSummary processKey);
5454

55-
@JsonNotification("sts/liveprocess/loggers/updated")
56-
void liveProcessLoggersDataUpdated(LiveProcessSummary liveProcessSummary);
57-
5855
@JsonNotification("sts/liveprocess/loglevel/updated")
5956
void liveProcessLogLevelUpdated(LiveProcessLoggersSummary liveProcessLoggersSummary);
6057

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

-4
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,6 @@ public void liveProcessMemoryMetricsDataUpdated(LiveProcessSummary processKey) {
433433
public void liveProcessGcPausesMetricsDataUpdated(LiveProcessSummary processKey) {
434434
}
435435

436-
@Override
437-
public void liveProcessLoggersDataUpdated(LiveProcessSummary processKey) {
438-
}
439-
440436
@Override
441437
public void indexUpdated() {
442438
receiveIndexUpdated();

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

+4-19
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class SpringProcessCommandHandler {
4545
private static final String COMMAND_GET_METRICS = "sts/livedata/get/metrics";
4646
private static final String COMMAND_GET_REFRESH_METRICS = "sts/livedata/refresh/metrics";
4747
private static final String COMMAND_GET_LOGGERS = "sts/livedata/getLoggers";
48-
private static final String COMMAND_FETCH_LOGGERS_DATA = "sts/livedata/fetch/loggersData";
4948
private static final String COMMAND_CONFIGURE_LOGLEVEL = "sts/livedata/configure/logLevel";
5049

5150
private final SpringProcessConnectorService connectorService;
@@ -98,11 +97,6 @@ public SpringProcessCommandHandler(SimpleLanguageServer server, SpringProcessCon
9897
});
9998
log.info("Registered command handler: {}",COMMAND_GET_LOGGERS);
10099

101-
server.onCommand(COMMAND_FETCH_LOGGERS_DATA, (params) -> {
102-
return handleFetchLoggersDataRequest(params);
103-
});
104-
log.info("Registered command handler: {}",COMMAND_FETCH_LOGGERS_DATA);
105-
106100
server.onCommand(COMMAND_CONFIGURE_LOGLEVEL, (params) -> {
107101
return configureLogLevel(params);
108102
});
@@ -341,24 +335,16 @@ private CompletableFuture<Object> handleLiveMetricsProcessRequest(ExecuteCommand
341335

342336

343337
private CompletableFuture<Object> getLoggers(ExecuteCommandParams params) {
338+
SpringProcessLoggersData loggersData = null;
344339
SpringProcessParams springProcessParams = new SpringProcessParams();
345340
springProcessParams.setProcessKey(getProcessKey(params));
346341
springProcessParams.setEndpoint(getArgumentByKey(params, "endpoint"));
347342
if (springProcessParams.getProcessKey() != null) {
348-
connectorService.getLoggers(springProcessParams);
343+
loggersData = connectorService.getLoggers(springProcessParams);
344+
return CompletableFuture.completedFuture(loggersData);
349345
}
350346

351-
return CompletableFuture.completedFuture(null);
352-
}
353-
354-
private CompletableFuture<Object> handleFetchLoggersDataRequest(ExecuteCommandParams params) {
355-
String processKey = getProcessKey(params);
356-
if (processKey != null) {
357-
SpringProcessLoggersData data = connectorService.getLoggersData(processKey);
358-
return CompletableFuture.completedFuture(data.getLoggers());
359-
}
360-
361-
return CompletableFuture.completedFuture(null);
347+
return CompletableFuture.completedFuture(loggersData);
362348
}
363349

364350
private CompletableFuture<Object> configureLogLevel(ExecuteCommandParams params) {
@@ -368,7 +354,6 @@ private CompletableFuture<Object> configureLogLevel(ExecuteCommandParams params)
368354
args.put("effectiveLevel", getArgumentByKey(params, "effectiveLevel"));
369355
SpringProcessParams springProcessParams = new SpringProcessParams();
370356
springProcessParams.setProcessKey(getProcessKey(params));
371-
springProcessParams.setEndpoint(getArgumentByKey(params, "endpoint"));
372357
springProcessParams.setArgs(args);
373358

374359
if (springProcessParams.getProcessKey() != null) {

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

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

13+
import java.util.concurrent.CompletableFuture;
1314
import java.util.concurrent.ConcurrentHashMap;
1415
import java.util.concurrent.ConcurrentMap;
16+
import java.util.concurrent.ExecutionException;
1517
import java.util.concurrent.ScheduledThreadPoolExecutor;
1618
import java.util.concurrent.TimeUnit;
1719

@@ -126,10 +128,6 @@ public SpringProcessMemoryMetricsLiveData getMemoryMetricsLiveData(String proces
126128
public SpringProcessGcPausesMetricsLiveData getGcPausesMetricsLiveData(String processKey) {
127129
return this.liveDataProvider.getGcPausesMetrics(processKey);
128130
}
129-
130-
public SpringProcessLoggersData getLoggersData(String processKey) {
131-
return this.liveDataProvider.getLoggersData(processKey);
132-
}
133131

134132
public void disconnectProcess(String processKey) {
135133
log.info("disconnect from process: " + processKey);
@@ -298,19 +296,24 @@ private IndefiniteProgressTask getProgressTask(String prefixId, String title, St
298296
return this.progressService.createIndefiniteProgressTask(prefixId + progressIdKey++, title, message);
299297
}
300298

301-
public void getLoggers(SpringProcessParams springProcessParams) {
299+
public SpringProcessLoggersData getLoggers(SpringProcessParams springProcessParams) {
302300
log.info("get loggers data: " + springProcessParams.getProcessKey());
303-
301+
CompletableFuture<SpringProcessLoggersData> loggerData = new CompletableFuture<>();
304302
SpringProcessConnector connector = this.connectors.get(springProcessParams.getProcessKey());
305303
if (connector != null) {
306304
final IndefiniteProgressTask progressTask = getProgressTask(
307305
"spring-process-connector-service-get-loggers-data" + springProcessParams.getProcessKey(), "Loggers", null);
308-
System.out.println(progressTask);
309-
getLoggersData(progressTask, springProcessParams, connector, 0, TimeUnit.SECONDS, 0);
306+
getLoggersData(progressTask, springProcessParams, connector, loggerData, 0, TimeUnit.SECONDS, 0);
307+
try {
308+
return loggerData.get();
309+
} catch (InterruptedException | ExecutionException e) {
310+
log.error("Failed to fetch loggers data for the process "+ springProcessParams.getProcessKey());
311+
}
310312
}
313+
return null;
311314
}
312315

313-
public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessParams springProcessParams, SpringProcessConnector connector, long delay, TimeUnit unit, int retryNo) {
316+
public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessParams springProcessParams, SpringProcessConnector connector, CompletableFuture<SpringProcessLoggersData> loggerData, long delay, TimeUnit unit, int retryNo) {
314317
String processKey = springProcessParams.getProcessKey();
315318
String endpoint = springProcessParams.getEndpoint();
316319

@@ -325,10 +328,7 @@ public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessPar
325328
SpringProcessLoggersData loggersData = connector.getLoggers(this.liveDataProvider.getCurrent(processKey));
326329

327330
if (loggersData != null) {
328-
if (!this.liveDataProvider.addLoggers(processKey, loggersData)) {
329-
this.liveDataProvider.updateLoggers(processKey, loggersData);
330-
}
331-
331+
loggerData.complete(loggersData);
332332
this.connectedSuccess.put(processKey, true);
333333
}
334334

@@ -340,7 +340,7 @@ public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessPar
340340
log.info("problem occured during process live data refresh", e);
341341

342342
if (retryNo < maxRetryCount && isKnownProcessKey(processKey)) {
343-
getLoggersData(progressTask, springProcessParams, connector, retryDelayInSeconds, TimeUnit.SECONDS,
343+
getLoggersData(progressTask, springProcessParams, connector, loggerData, retryDelayInSeconds, TimeUnit.SECONDS,
344344
retryNo + 1);
345345
}
346346
else {
@@ -352,6 +352,7 @@ public void getLoggersData(IndefiniteProgressTask progressTask, SpringProcessPar
352352
.error("Failed to refresh live data from process " + processKey + " after retries: " + retryNo, e));
353353

354354
if (!connectedSuccess.containsKey(connector.getProcessKey())) {
355+
loggerData.complete(null);
355356
disconnectProcess(processKey);
356357
}
357358
}
@@ -369,15 +370,13 @@ public void configureLogLevel(SpringProcessParams springProcessParams) {
369370
if (connector != null) {
370371
final IndefiniteProgressTask progressTask = getProgressTask(
371372
"spring-process-connector-service-configure-log-level" + springProcessParams.getProcessKey(), "Loggers", null);
372-
System.out.println(progressTask);
373373
configureLogLevel(progressTask, springProcessParams, connector, 0, TimeUnit.SECONDS, 0);
374374
}
375375
}
376376

377377
private void configureLogLevel(IndefiniteProgressTask progressTask, SpringProcessParams springProcessParams,
378378
SpringProcessConnector connector, long delay, TimeUnit unit, int retryNo) {
379379
String processKey = springProcessParams.getProcessKey();
380-
String endpoint = springProcessParams.getEndpoint();
381380

382381
String progressMessage = "configure log level for Spring process: " + processKey + " - retry no: " + retryNo;
383382
log.info(progressMessage);
@@ -386,14 +385,12 @@ private void configureLogLevel(IndefiniteProgressTask progressTask, SpringProces
386385

387386
try {
388387
progressTask.progressEvent(progressMessage);
389-
if(LOGGERS.equals(endpoint)) {
390-
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = connector.configureLogLevel(this.liveDataProvider.getCurrent(processKey), springProcessParams.getArgs());
388+
SpringProcessUpdatedLogLevelData springProcessUpdatedLoggersData = connector.configureLogLevel(this.liveDataProvider.getCurrent(processKey), springProcessParams.getArgs());
391389

392-
if(springProcessUpdatedLoggersData != null) {
393-
this.liveDataProvider.updateLogLevel(processKey, springProcessUpdatedLoggersData);
394-
this.connectedSuccess.put(processKey, true);
395-
}
396-
}
390+
if(springProcessUpdatedLoggersData != null) {
391+
this.liveDataProvider.updateLogLevel(processKey, springProcessUpdatedLoggersData);
392+
this.connectedSuccess.put(processKey, true);
393+
}
397394

398395
progressTask.done();
399396
}

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

-22
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,6 @@ public boolean addGcPausesMetrics(String processKey, SpringProcessGcPausesMetric
7676
}
7777
return oldData == null;
7878
}
79-
80-
public boolean addLoggers(String processKey, SpringProcessLoggersData loggerData) {
81-
SpringProcessLoggersData oldData = this.loggersData.putIfAbsent(processKey, loggerData);
82-
if (oldData == null) {
83-
getClient().liveProcessLoggersDataUpdated(createLoggersSummary(processKey, loggerData));
84-
}
85-
return oldData == null;
86-
}
8779

8880
private STS4LanguageClient getClient() {
8981
STS4LanguageClient client = server.getClient();
@@ -115,11 +107,6 @@ public void updateGcPausesMetrics(String processKey, SpringProcessGcPausesMetric
115107
getClient().liveProcessGcPausesMetricsDataUpdated(createGcPausesMetricsSummary(processKey, liveData));
116108
}
117109

118-
public void updateLoggers(String processKey, SpringProcessLoggersData loggerData) {
119-
this.loggersData.put(processKey, loggerData);
120-
getClient().liveProcessLoggersDataUpdated(createLoggersSummary(processKey, loggerData));
121-
}
122-
123110
public void updateLogLevel(String processKey, SpringProcessUpdatedLogLevelData updatedLogLevelData) {
124111
getClient().liveProcessLogLevelUpdated(createUpdatedLogLevelSummary(processKey, updatedLogLevelData));
125112
}
@@ -183,15 +170,6 @@ public static LiveProcessSummary createGcPausesMetricsSummary(String processKey,
183170
p.setPid(liveData.getProcessID());
184171
return p;
185172
}
186-
187-
public static LiveProcessSummary createLoggersSummary(String processKey, SpringProcessLoggersData loggersData) {
188-
LiveProcessSummary p = new LiveProcessSummary();
189-
p.setType(loggersData.getProcessType().jsonName());
190-
p.setProcessKey(processKey);
191-
p.setProcessName(loggersData.getProcessName());
192-
p.setPid(loggersData.getProcessID());
193-
return p;
194-
}
195173

196174
public static LiveProcessLoggersSummary createUpdatedLogLevelSummary(String processKey, SpringProcessUpdatedLogLevelData updatedLogLevelData) {
197175
LiveProcessLoggersSummary p = new LiveProcessLoggersSummary(updatedLogLevelData.getProcessType().jsonName(),

vscode-extensions/vscode-spring-boot/lib/notification.ts

-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ export namespace SpringIndexUpdatedNotification {
5454
export const type = new NotificationType<void>('spring/index/updated');
5555
}
5656

57-
export namespace LiveProcessLoggersUpdatedNotification {
58-
export const type = new NotificationType<LiveProcess>('sts/liveprocess/loggers/updated');
59-
}
60-
6157
export namespace LiveProcessLogLevelUpdatedNotification {
6258
export const type = new NotificationType<LiveProcessUpdatedLogLevel>('sts/liveprocess/loglevel/updated');
6359
}

vscode-extensions/vscode-spring-boot/lib/set-log-levels-ui.ts

+40-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import * as VSCode from 'vscode';
44
import { LanguageClient } from "vscode-languageclient/node";
55
import { ActivatorOptions } from '@pivotal-tools/commons-vscode';
6-
import { LiveProcess, LiveProcessLoggersUpdatedNotification, LiveProcessLogLevelUpdatedNotification, LiveProcessUpdatedLogLevel } from './notification';
6+
import { LiveProcess, LiveProcessLogLevelUpdatedNotification, LiveProcessUpdatedLogLevel } from './notification';
77

88
interface ProcessCommandInfo {
99
processKey : string;
@@ -26,6 +26,13 @@ export interface LoggersData {
2626
loggers: Loggers;
2727
}
2828

29+
export interface ProcessLoggersData {
30+
loggers: LoggersData;
31+
processID: string;
32+
processName: string;
33+
processType: number;
34+
}
35+
2936
export interface LoggerItem {
3037
logger: Logger;
3138
name: string;
@@ -48,17 +55,41 @@ async function setLogLevelHandler() {
4855
const picked = await VSCode.window.showQuickPick(choices);
4956
if (picked) {
5057
const chosen = choiceMap.get(picked);
51-
const loggers = await VSCode.commands.executeCommand('sts/livedata/getLoggers', chosen, {"endpoint": "loggers"});
58+
try {
59+
const loggers: ProcessLoggersData = await getLoggers(chosen);
60+
await displayLoggers(loggers, chosen.processKey);
61+
} catch (error) {
62+
VSCode.window.showErrorMessage("Failed to fetch loggers for the process " + chosen.processKey);
63+
}
5264
}
5365
}
5466
}
5567

56-
async function getLoggersList(process: LiveProcess) {
57-
const loggers: LoggersData = await VSCode.commands.executeCommand('sts/livedata/fetch/loggersData', process);
68+
async function getLoggers(processInfo: ProcessCommandInfo): Promise<ProcessLoggersData> {
69+
70+
return new Promise(async (resolve, reject) => {
71+
await VSCode.window.withProgress({
72+
location: VSCode.ProgressLocation.Window,
73+
title: "Fetching Loggers Data for process "+processInfo.processKey,
74+
cancellable: false
75+
}, async (progress) => {
76+
try {
77+
const loggers: ProcessLoggersData = await VSCode.commands.executeCommand('sts/livedata/getLoggers', processInfo, {"endpoint": "loggers"});
78+
progress.report({});
79+
resolve(loggers);
80+
} catch (error) {
81+
reject(error);
82+
}
83+
});
84+
});
85+
}
86+
87+
async function displayLoggers(processLoggersData: ProcessLoggersData, processKey: string) {
5888
let items;
59-
if(loggers) {
60-
items = Object.keys(loggers.loggers).map(packageName => {
61-
const logger: Logger = loggers.loggers[packageName];
89+
const loggersData = processLoggersData.loggers;
90+
if(loggersData.loggers) {
91+
items = Object.keys(loggersData.loggers).map(packageName => {
92+
const logger: Logger = loggersData.loggers[packageName];
6293
const effectiveLevel = logger.effectiveLevel;
6394
const label = packageName + ' (' + effectiveLevel + ')';
6495
return {
@@ -71,8 +102,8 @@ async function getLoggersList(process: LiveProcess) {
71102
if(items) {
72103
const chosenPackage = await VSCode.window.showQuickPick(items);
73104
if (chosenPackage) {
74-
const chosenlogLevel = await VSCode.window.showQuickPick(loggers.levels);
75-
const changeLogLevel = await VSCode.commands.executeCommand('sts/livedata/configure/logLevel', {"endpoint": "loggers"}, process, chosenPackage, {"configuredLevel":chosenlogLevel});
105+
const chosenlogLevel = await VSCode.window.showQuickPick(loggersData.levels);
106+
await VSCode.commands.executeCommand('sts/livedata/configure/logLevel', {"processKey": processKey}, chosenPackage, {"configuredLevel":chosenlogLevel});
76107
}
77108
}
78109

@@ -89,7 +120,6 @@ export function activate(
89120
options: ActivatorOptions,
90121
context: VSCode.ExtensionContext
91122
) {
92-
client.onNotification(LiveProcessLoggersUpdatedNotification.type, getLoggersList)
93123
client.onNotification(LiveProcessLogLevelUpdatedNotification.type, logLevelUpdated)
94124
context.subscriptions.push(
95125
VSCode.commands.registerCommand('vscode-spring-boot.set.log-levels', () => {

0 commit comments

Comments
 (0)