Skip to content

Commit

Permalink
fix: Update regex parsing for CGroup v1 to match agent spec. (#2286)
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Feb 28, 2024
1 parent 61e200a commit 7fa3410
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/Agent/NewRelic/Agent/Core/Utilization/VendorInfo.cs
Expand Up @@ -24,8 +24,7 @@ public class VendorInfo
{
private const string ValidateMetadataRegex = @"^[a-zA-Z0-9-_. /]*$";
#if NETSTANDARD2_0
private const string ContainerIdV1Regex = @".*:cpu:/docker/([0-9a-f]{64}).*";
private const string ContainerIdV1FallbackRegex = @"([0-9a-f]{64})"; // This is the old regex that just looks for any 64-char hexadecimal string
private const string ContainerIdV1Regex = @".*cpu.*([0-9a-f]{64})";
private const string ContainerIdV2Regex = ".*/docker/containers/([0-9a-f]{64})/.*";
#endif

Expand Down Expand Up @@ -321,11 +320,6 @@ private IVendorModel TryGetDockerCGroupV1(string fileContent)
{
return new DockerVendorModel(id);
}
matches = Regex.Matches(fileContent, ContainerIdV1FallbackRegex);
if (TryGetIdFromRegexMatch(matches, out id))
{
return new DockerVendorModel(id);
}
return null;
}

Expand Down
Expand Up @@ -373,8 +373,9 @@ public void GetVendors_GetDockerVendorInfo_ParsesV1_IfV2LookupFailsToParseFile()
}

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

0 comments on commit 7fa3410

Please sign in to comment.