Skip to content

Commit 2b471a3

Browse files
authored
Merge pull request #2540 from newrelic/dockerid-logging-cleanup
Improve DockerData logging
2 parents 97e7777 + c51a5c8 commit 2b471a3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

newrelic-agent/src/main/java/com/newrelic/agent/utilization/DockerData.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,25 @@ public String getDockerContainerIdForEcsFargate(boolean isLinux) {
7171
Agent.LOG.log(Level.INFO, "Attempting to fetch ECS Fargate container id from URL (v4): {0}", fargateUrl);
7272
result = retrieveDockerIdFromFargateMetadata(new AwsFargateMetadataFetcher(fargateUrl));
7373
if (result != null) {
74+
Agent.LOG.log(Level.INFO, "Found container id: {0}", result);
7475
return result;
7576
}
7677
}
7778

7879
fargateUrl = System.getenv(AWS_ECS_METADATA_UNVERSIONED_ENV_VAR);
7980
if (fargateUrl != null) {
8081
Agent.LOG.log(Level.INFO, "Attempting to fetch ECS Fargate container id from URL (unversioned): {0}", fargateUrl);
81-
return retrieveDockerIdFromFargateMetadata(new AwsFargateMetadataFetcher(fargateUrl));
82+
result = retrieveDockerIdFromFargateMetadata(new AwsFargateMetadataFetcher(fargateUrl));
83+
if (result != null) {
84+
Agent.LOG.log(Level.INFO, "Found container id: {0}", result);
85+
return result;
86+
}
8287
}
8388
} catch (MalformedURLException e) {
8489
Agent.LOG.log(Level.FINEST, "Invalid AWS Fargate metadata URL: {0}", fargateUrl);
8590
}
91+
92+
Agent.LOG.log(Level.INFO, "No container id found in either fargate URL");
8693
}
8794

8895
return null;
@@ -92,18 +99,24 @@ public String getDockerContainerIdFromCGroups(boolean isLinux) {
9299
if (isLinux) {
93100
String result;
94101
//try to get the container id from the v2 location
102+
Agent.LOG.log(Level.INFO, "Attempting to fetch container id from cgroups v2: {0}", FILE_WITH_CONTAINER_ID_V2);
95103
File containerIdFileV2 = new File(FILE_WITH_CONTAINER_ID_V2);
96104
result = getDockerIdFromFile(containerIdFileV2, CGroup.V2);
97105
if (result != null) {
106+
Agent.LOG.log(Level.INFO, "Found container id: {0}", result);
98107
return result;
99108
}
100109

101110
//try to get container id from the v1 location
111+
Agent.LOG.log(Level.INFO, "Attempting to fetch container id from cgroups v1: {0}", FILE_WITH_CONTAINER_ID_V1);
102112
File containerIdFileV1 = new File(FILE_WITH_CONTAINER_ID_V1);
103113
result = getDockerIdFromFile(containerIdFileV1, CGroup.V1);
104114
if (result != null) {
115+
Agent.LOG.log(Level.INFO, "Found container id: {0}", result);
105116
return result;
106117
}
118+
119+
Agent.LOG.log(Level.INFO, "No container id found in either cgroup file");
107120
}
108121

109122
return null;
@@ -155,7 +168,7 @@ private boolean checkLineAndGetResultV1(String line, StringBuilder resultGoesHe
155168
if (checkAndGetMatch(DOCKER_CONTAINER_STRING_V1, resultGoesHere, mayContainId)) {
156169
return true;
157170
} else if (!mayContainId.equals("/")) {
158-
Agent.LOG.log(Level.FINE, "Docker Data: Ignoring unrecognized cgroup ID format: {0}", mayContainId);
171+
Agent.LOG.log(Level.FINE, "Ignoring unrecognized cgroup v1 ID format: {0}", mayContainId);
159172
}
160173
}
161174
return false;
@@ -221,12 +234,11 @@ String retrieveDockerIdFromFargateMetadata(AwsFargateMetadataFetcher awsFargateM
221234
dockerId = (String) jsonObject.get(FARGATE_DOCKER_ID_KEY);
222235
Agent.LOG.log(Level.INFO, "ECS Fargate container id: {0} ", dockerId);
223236
} catch (IOException e) {
224-
Agent.LOG.log(Level.WARNING, "Error opening input stream retrieving AWS Fargate metadata");
237+
Agent.LOG.log(Level.WARNING, "Error opening input stream retrieving AWS Fargate metadata: {0}", e.getMessage());
225238
} catch (ParseException e) {
226-
Agent.LOG.log(Level.WARNING, "Error parsing JSON blob for AWS Fargate metadata");
239+
Agent.LOG.log(Level.WARNING, "Error parsing JSON blob for AWS Fargate metadata: {0}", e.getMessage());
227240
}
228241

229242
return dockerId;
230243
}
231-
232244
}

0 commit comments

Comments
 (0)