Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: Update regex parsing for CGroup v1 to match agent spec. #2286

Merged
merged 2 commits into from Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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