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

feat: Enable configuration of ignored and expected HTTP status code errors with environment variables #2487

Merged
merged 5 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,10 @@ private void ParseExpectedErrorConfigurations()
var expectedStatusCodesArrayLocal = _localConfiguration.errorCollector.expectedStatusCodes?.Split(StringSeparators.Comma, StringSplitOptions.RemoveEmptyEntries);
var expectedStatusCodesArrayServer = _serverConfiguration.RpmConfig.ErrorCollectorExpectedStatusCodes;

var expectedStatusCodesArray = ServerOverrides(expectedStatusCodesArrayServer, expectedStatusCodesArrayLocal);
var expectedStatusCodesArray = EnvironmentOverrides(ServerOverrides(expectedStatusCodesArrayServer, expectedStatusCodesArrayLocal)?.ToList(), "NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES");
nr-ahemsath marked this conversation as resolved.
Show resolved Hide resolved

ExpectedStatusCodes = ParseExpectedStatusCodesArray(expectedStatusCodesArray);
ExpectedErrorStatusCodesForAgentSettings = expectedStatusCodesArray ?? new string[0];
ExpectedErrorStatusCodesForAgentSettings = expectedStatusCodesArray ?? new List<string>();

ExpectedErrorsConfiguration = new ReadOnlyDictionary<string, IEnumerable<string>>(expectedErrorInfo);
ExpectedErrorMessagesForAgentSettings = new ReadOnlyDictionary<string, IEnumerable<string>>(expectedMessages);
Expand Down Expand Up @@ -2677,7 +2677,7 @@ private void ParseIgnoreErrorConfigurations()
}
}

var ignoreStatusCodes = _serverConfiguration.RpmConfig.ErrorCollectorStatusCodesToIgnore;
IEnumerable<string> ignoreStatusCodes = EnvironmentOverrides(_serverConfiguration.RpmConfig.ErrorCollectorStatusCodesToIgnore?.ToList(), "NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES");
if (ignoreStatusCodes == null)
{
ignoreStatusCodes = _localConfiguration.errorCollector.ignoreStatusCodes.code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -999,19 +999,43 @@ public string IgnoreErrorsAndIgnoreClassesCombineTests(string[] ignoreClasses, s
return string.Join(",", _defaultConfig.IgnoreErrorsConfiguration.Keys);
}

[TestCase("401", new[] { "405" }, ExpectedResult = new[] { "405" })]
[TestCase("401", new string[0], ExpectedResult = new string[0])]
[TestCase("401", null, ExpectedResult = new[] { "401" })]
public string[] ExpectedStatusCodesSetFromLocalAndServerOverrides(string local, string[] server)
[TestCase("401", new[] { "405" }, null, ExpectedResult = new[] { "405" })]
[TestCase("401", new string[0], null, ExpectedResult = new string[0])]
[TestCase("401", null, null, ExpectedResult = new[] { "401" })]
[TestCase(null, null, "401", ExpectedResult = new[] { "401" })]
[TestCase(null, new[] { "405" }, "401", ExpectedResult = new[] { "401" })]
[TestCase("402", new string[0], "401", ExpectedResult = new[] { "401" })]
[TestCase("402", new string[0], "401, 503", ExpectedResult = new[] { "401", "503" })]
public string[] ExpectedStatusCodesSetFromLocalServerAndEnvironmentOverrides(string local, string[] server, string env)
nr-ahemsath marked this conversation as resolved.
Show resolved Hide resolved
{
_serverConfig.RpmConfig.ErrorCollectorExpectedStatusCodes = server;
_localConfig.errorCollector.expectedStatusCodes = (local);
Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_ERROR_COLLECTOR_EXPECTED_ERROR_CODES")).Returns(env);

CreateDefaultConfiguration();

return _defaultConfig.ExpectedErrorStatusCodesForAgentSettings.ToArray();
}

[TestCase(new[] { 401f }, new[] { "405" }, null, ExpectedResult = new[] { "405" })]
[TestCase(new[] { 401f }, new string[0], null, ExpectedResult = new string[0])]
[TestCase(new[] { 401f }, null, null, ExpectedResult = new[] { "401" })]
[TestCase(new[] { 401.5f }, null, null, ExpectedResult = new[] { "401.5" })]
[TestCase(new float[0], null, "401", ExpectedResult = new[] { "401" })]
[TestCase(new float[0], new[] { "405" }, "401", ExpectedResult = new[] { "401" })]
[TestCase(new[] { 401f }, new string[0], "402", ExpectedResult = new[] { "402" })]
[TestCase(new[] { 401f }, new string[0], "401.5, 503", ExpectedResult = new[] { "401.5", "503" })]
public string[] IgnoredStatusCodesSetFromLocalServerAndEnvironmentOverrides(float[] local, string[] server, string env)
{
_serverConfig.RpmConfig.ErrorCollectorStatusCodesToIgnore = server;
_localConfig.errorCollector.ignoreStatusCodes.code = (local.ToList());
Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES")).Returns(env);

CreateDefaultConfiguration();

return _defaultConfig.HttpStatusCodesToIgnore.ToArray();
}

[TestCase("401-404", new string[] { "401.5", "402.3" }, new bool[] { false, false })] //does not support full status codes
[TestCase("400,401,404", new string[] { "400", "401", "402", "403", "404" }, new bool[] { true, true, false, false, true })]
[TestCase("400, 401 ,404", new string[] { "400", "401", "402", "403", "404" }, new bool[] { true, true, false, false, true })]
Expand Down
Loading