Merge pull request #1292 from navi-infra/INFRA-3746
INFRA-3746 | Abhishek | Support heap dump for golang services
This commit is contained in:
@@ -3,13 +3,14 @@ package com.navi.infra.portal.domain.manifest;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.navi.infra.portal.domain.JsonEntity;
|
||||
import com.navi.infra.portal.dto.manifest.CloneManifestRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.persistence.CascadeType;
|
||||
@@ -85,7 +86,7 @@ public class Deployment extends JsonEntity implements StatusMarker {
|
||||
if (hasField("allowEgress") && !cloneRequest.isCopyOutbound()) {
|
||||
getData().put("allowEgress", new ArrayList<>());
|
||||
}
|
||||
if (!Objects.equals(this.getSecurityGroups(),Collections.emptyList())){
|
||||
if (!Objects.equals(this.getSecurityGroups(), Collections.emptyList())) {
|
||||
removeSecurityGroupIds();
|
||||
}
|
||||
|
||||
@@ -143,4 +144,20 @@ public class Deployment extends JsonEntity implements StatusMarker {
|
||||
return (String) getData().get("controller");
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public List<HashMap> getExposedPorts() {
|
||||
return (List<HashMap>) this.getData().get("exposedPorts");
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public Integer getMetricsPort() {
|
||||
List<HashMap> exposedPorts = getExposedPorts();
|
||||
var servicePort = exposedPorts.stream()
|
||||
.filter(exposedPort -> exposedPort.get("name").equals("metrics"))
|
||||
.collect(Collectors.toList());
|
||||
if (!servicePort.isEmpty()) {
|
||||
return (Integer) servicePort.stream().findFirst().get().get("port");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,10 @@ public class AirflowClient {
|
||||
Map.entry("pod_name", diagnosticTriggerRequest.getPodName()),
|
||||
Map.entry("target_container_name", diagnosticTriggerRequest.getContainerName()),
|
||||
Map.entry("image", diagnosticTriggerRequest.getRunnerImage()),
|
||||
Map.entry("language", diagnosticTriggerRequest.getLanguage()),
|
||||
Map.entry("port",
|
||||
Optional.ofNullable(diagnosticTriggerRequest.getPort()).map(Object::toString)
|
||||
.orElse("")),
|
||||
Map.entry("pre_signed_url",
|
||||
Optional.ofNullable(diagnosticTriggerRequest.getPreSignedUrl()).orElse("")),
|
||||
Map.entry("sample_pre_signed_url",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.navi.infra.portal.v2.diagnostic;
|
||||
|
||||
import com.navi.infra.portal.domain.BaseEntity;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.persistence.Convert;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
@@ -27,6 +28,10 @@ public class Diagnostic extends BaseEntity {
|
||||
private String cluster;
|
||||
private String namespace;
|
||||
private String podName;
|
||||
private String language;
|
||||
|
||||
@Nullable
|
||||
private Integer port;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private DiagnosticStatus status;
|
||||
|
||||
@@ -9,7 +9,9 @@ import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.get
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getDiagnosticPath;
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getDiagnosticTaskLogUrl;
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getEnvironment;
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getLanguage;
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getNamespace;
|
||||
import static com.navi.infra.portal.v2.diagnostic.DiagnosticServiceUtilities.getPort;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import com.navi.infra.portal.client.AwsS3Client;
|
||||
@@ -69,8 +71,10 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
final var namespace = getNamespace(manifest);
|
||||
final var environment = getEnvironment(manifest);
|
||||
final var manifestName = manifest.getName();
|
||||
final var language = getLanguage(manifest);
|
||||
final var port = getPort(manifest);
|
||||
return createDiagnostic(
|
||||
triggerDiagnosticRequest, cluster, namespace, environment, manifestName
|
||||
triggerDiagnosticRequest, cluster, namespace, environment, manifestName, language, port
|
||||
)
|
||||
.map(DiagnosticDto::new)
|
||||
.collect(toList());
|
||||
@@ -81,7 +85,9 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
String cluster,
|
||||
String namespace,
|
||||
String env,
|
||||
String manifestName
|
||||
String manifestName,
|
||||
String language,
|
||||
Integer port
|
||||
) {
|
||||
Function<AirflowApiResponse, Diagnostic> toDiagnosticEntity = response -> {
|
||||
var diagnostic = new Diagnostic();
|
||||
@@ -90,6 +96,8 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
diagnostic.setManifestId(triggerDiagnosticRequest.getManifestId());
|
||||
diagnostic.setCluster(response.getCluster());
|
||||
diagnostic.setNamespace(response.getNamespace());
|
||||
diagnostic.setLanguage(language);
|
||||
diagnostic.setPort(port);
|
||||
diagnostic.setPodName(response.getPodName());
|
||||
diagnostic.setStatus(DiagnosticStatus.STARTED);
|
||||
diagnostic.setDiagnosticResultName(response.getDiagnosticResultName());
|
||||
@@ -106,7 +114,9 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
cluster,
|
||||
namespace,
|
||||
env,
|
||||
manifestName
|
||||
manifestName,
|
||||
language,
|
||||
port
|
||||
)
|
||||
)
|
||||
.map(airflowClient::triggerDag)
|
||||
@@ -119,7 +129,9 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
String cluster,
|
||||
String namespace,
|
||||
String environment,
|
||||
String manifestName
|
||||
String manifestName,
|
||||
String language,
|
||||
Integer port
|
||||
) {
|
||||
return podName -> {
|
||||
final var instant = LocalDateTime.now(ZoneId.of(ASIA_KOLKATA));
|
||||
@@ -136,6 +148,8 @@ class DiagnosticServiceImpl implements DiagnosticService {
|
||||
.cluster(cluster)
|
||||
.namespace(namespace)
|
||||
.podName(podName)
|
||||
.language(language)
|
||||
.port(port)
|
||||
.dagId(dagId)
|
||||
.runId(createRunId(podName, instant))
|
||||
.containerName(getContainerFromPod(podName))
|
||||
|
||||
@@ -58,6 +58,16 @@ public class DiagnosticServiceUtilities {
|
||||
"Environment is not present in manifest " + manifest.fullName());
|
||||
}
|
||||
|
||||
static String getLanguage(Manifest manifest) {
|
||||
return requireNonNull(manifest.getMetadata().getLanguage(),
|
||||
"Language is not present in manifest " + manifest.fullName());
|
||||
}
|
||||
|
||||
static Integer getPort(Manifest manifest) {
|
||||
return requireNonNull(manifest.getDeployment().getMetricsPort(),
|
||||
"Metrics port is not present in manifest " + manifest.fullName());
|
||||
}
|
||||
|
||||
static String getNamespace(Manifest manifest) {
|
||||
return requireNonNull(manifest.getDeployment().getNamespace(),
|
||||
"Namespace is not present in manifest " + manifest.fullName());
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.navi.infra.portal.v2.diagnostic;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -14,6 +15,8 @@ public class DiagnosticTriggerRequest {
|
||||
private String namespace;
|
||||
private String runId;
|
||||
private String podName;
|
||||
private String language;
|
||||
private Integer port;
|
||||
private String containerName;
|
||||
private String runnerImage;
|
||||
private String preSignedUrl;
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
ALTER TABLE diagnostic ADD COLUMN port integer;
|
||||
ALTER TABLE diagnostic ADD COLUMN language VARCHAR(255) NOT NULL DEFAULT 'Java';
|
||||
Reference in New Issue
Block a user