Skip to content

Commit 7fa3410

Browse files
authored
fix: Update regex parsing for CGroup v1 to match agent spec. (#2286)
1 parent 61e200a commit 7fa3410

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/Agent/NewRelic/Agent/Core/Utilization/VendorInfo.cs

+1-7
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public class VendorInfo
2424
{
2525
private const string ValidateMetadataRegex = @"^[a-zA-Z0-9-_. /]*$";
2626
#if NETSTANDARD2_0
27-
private const string ContainerIdV1Regex = @".*:cpu:/docker/([0-9a-f]{64}).*";
28-
private const string ContainerIdV1FallbackRegex = @"([0-9a-f]{64})"; // This is the old regex that just looks for any 64-char hexadecimal string
27+
private const string ContainerIdV1Regex = @".*cpu.*([0-9a-f]{64})";
2928
private const string ContainerIdV2Regex = ".*/docker/containers/([0-9a-f]{64})/.*";
3029
#endif
3130

@@ -321,11 +320,6 @@ private IVendorModel TryGetDockerCGroupV1(string fileContent)
321320
{
322321
return new DockerVendorModel(id);
323322
}
324-
matches = Regex.Matches(fileContent, ContainerIdV1FallbackRegex);
325-
if (TryGetIdFromRegexMatch(matches, out id))
326-
{
327-
return new DockerVendorModel(id);
328-
}
329323
return null;
330324
}
331325

tests/Agent/UnitTests/Core.UnitTest/Utilization/VendorInfoTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ public void GetVendors_GetDockerVendorInfo_ParsesV1_IfV2LookupFailsToParseFile()
373373
}
374374

375375
// See https://new-relic.atlassian.net/browse/NR-221128 and https://new-relic.atlassian.net/browse/NR-230908
376+
// The sample files below are from a customer issue where the cgroup file was not being parsed correctly
376377
[Test]
377-
public void GetVendors_GetDockerVendorInfo_ParsesV1WithFallback_IfCpuMissing()
378+
public void GetVendors_GetDockerVendorInfo_ParsesV1_ForCustomerIssue()
378379
{
379380
var vendorInfo = new VendorInfo(_configuration, _agentHealthReporter, _environment, _vendorHttpApiRequestor);
380381
var mockFileReaderWrapper = Mock.Create<IFileReaderWrapper>();

0 commit comments

Comments
 (0)