Skip to content

gcPauses -> jvm.gc.pause, memory -> jvm.memory.used #875

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.springframework.ide.vscode.boot.java.livehover.v2;

import java.io.IOException;
import java.net.URI;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
Expand All @@ -28,8 +29,10 @@ public class HttpActuatorConnection implements ActuatorConnection {

private Gson gson;
private RestTemplate restTemplate;
private String actuatorUrl;

public HttpActuatorConnection(String actuatorUrl) {
this.actuatorUrl = actuatorUrl;
this.restTemplate = new RestTemplateBuilder().rootUri(actuatorUrl).build();
this.gson = new Gson();
}
Expand Down Expand Up @@ -80,11 +83,12 @@ public String getBeans() throws IOException {
@Override
public String getLiveMetrics(String metricName, String tags) throws IOException {
UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromPath("/metrics/"+metricName);
if (tags != null) {
if (tags != null && !tags.isBlank()) {
uriBuilder.queryParam("tag", tags);
}
String url = uriBuilder.encode().toUriString();
return restTemplate.getForObject(url, String.class);
// /{ownerId}/new cases make REST Template URI template handler to think that {ownerId} is a URI parameter which it is not.
String url = actuatorUrl + uriBuilder.toUriString();
return restTemplate.getForObject(URI.create(url), String.class);
}

@Override
Expand All @@ -95,8 +99,9 @@ public String getMetrics(String metric, Map<String, String> tags) throws IOExcep
uriBuilder.queryParam("tag", e.getKey() + ":" + e.getValue());
}
}
String url = uriBuilder.encode().toUriString();
return restTemplate.getForObject(url, String.class);
// /{ownerId}/new cases make REST Template URI template handler to think that {ownerId} is a URI parameter which it is not.
String url = actuatorUrl + uriBuilder.toUriString();
return restTemplate.getForObject(URI.create(url), String.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
/*******************************************************************************
* Copyright (c) 2022 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.livehover.v2;

public class Measurements {

private String statistic;
private Long value;
private Double value;

public String getStatistic() {
return statistic;
}


public Long getValue() {
public Double getValue() {
return value;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*******************************************************************************
* Copyright (c) 2022 VMware, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* VMware, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.livehover.v2;

public enum ProcessType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ private CompletableFuture<Object> handleLiveMetricsProcessRequest(ExecuteCommand
String metricName = getArgumentByKey(params, "metricName");
if (processKey != null) {
switch(metricName) {
case "gcPauses": {
case SpringProcessConnectorService.GC_PAUSES: {
SpringProcessGcPausesMetricsLiveData data = connectorService.getGcPausesMetricsLiveData(processKey);
return CompletableFuture.completedFuture(data.getGcPausesMetrics());
}
case "memory": {
case SpringProcessConnectorService.MEMORY: {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metricName passed here are ("gcPauses", "heapMemory", "nonHeapMemory"). This is used to fetch the region-specific metric data separately.
(This is the result of my bad naming convention again ;-) )

@BoykoAlex I would like to discuss and get your feedback on how to improve this.

SpringProcessMemoryMetricsLiveData data = connectorService.getMemoryMetricsLiveData(processKey);
return CompletableFuture.completedFuture(data.getMemoryMetrics());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
*/
public class SpringProcessConnectorService {

private static final String METRICS = "metrics";
public static final String GC_PAUSES = "gcPauses";
public static final String MEMORY = "memory";

private static final Logger log = LoggerFactory.getLogger(SpringProcessConnectorService.class);

private final SpringProcessLiveDataProvider liveDataProvider;
Expand Down Expand Up @@ -171,8 +175,8 @@ private void scheduleConnect(ProgressTask progressTask, String processKey, Sprin
progressTask.progressDone();

refreshProcess(new SpringProcessParams(processKey, "", "", ""));
refreshProcess(new SpringProcessParams(processKey, "metrics", "memory", "area:heap"));
refreshProcess(new SpringProcessParams(processKey, "metrics", "gcPauses", ""));
refreshProcess(new SpringProcessParams(processKey, METRICS, MEMORY, "area:heap"));
refreshProcess(new SpringProcessParams(processKey, METRICS, GC_PAUSES, ""));
}
catch (Exception e) {
log.info("problem occured during process connect", e);
Expand Down Expand Up @@ -232,7 +236,7 @@ private void scheduleRefresh(ProgressTask progressTask, SpringProcessParams spri

try {
progressTask.progressEvent(progressMessage);
if(endpoint.equals("metrics") && metricName.equals("memory")) {
if(METRICS.equals(endpoint) && MEMORY.equals(metricName)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The metricName passed from the API call here is ("memory", "gcPauses"). This is to identify the type of metric and not the actual metricName used for the actuator call. (Probably I should have named it metricType. But I wanted to keep the metricQuery more generic to be used for other metric calls.

The getMemoryMetrics function is where the metric names ("jvm.memory.used, jvm.memory.max") are passed.

Also, with the current implementation, the retrieveLiveMemoryMetricsData has the logic to fetch the heap and non-heap memory metrics together.

SpringProcessMemoryMetricsLiveData newMetricsLiveData = connector.refreshMemoryMetrics(this.liveDataProvider.getCurrent(processKey), metricName, springProcessParams.getTags());

if (newMetricsLiveData != null) {
Expand All @@ -243,7 +247,7 @@ private void scheduleRefresh(ProgressTask progressTask, SpringProcessParams spri
this.connectedSuccess.put(processKey, true);
}

} else if(endpoint.equals("metrics") && metricName.equals("gcPauses")) {
} else if(METRICS.equals(endpoint) && GC_PAUSES.equals(metricName)) {
SpringProcessGcPausesMetricsLiveData newMetricsLiveData = connector.refreshGcPausesMetrics(this.liveDataProvider.getCurrent(processKey), metricName, springProcessParams.getTags());

if (newMetricsLiveData != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.client.HttpClientErrorException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -198,7 +200,7 @@ public SpringProcessGcPausesMetricsLiveData retrieveLiveGcPausesMetricsData(Proc
}
}

LiveMemoryMetricsModel metrics = getLiveMetrics(connection, metricName, tags);
LiveMemoryMetricsModel metrics = getLiveMetrics(connection, "jvm.gc.pause", tags);
if(metrics != null) {
memoryMetricsList.add(metrics);
}
Expand Down Expand Up @@ -240,7 +242,12 @@ public RequestMappingMetrics getRequestMappingMetrics(String[] paths, String[] r

return RequestMappingMetrics.parse(metricsData);
} catch (IOException e) {
// ignore
} catch (HttpClientErrorException e) {
if (e.getStatusCode() != null && e.getStatusCode() == HttpStatus.NOT_FOUND) {
// not found 404 - don't log it - means metric is unavailable
} else {
log.error("", e);
}
} catch (Exception e) {
log.error("", e);
}
Expand Down