From b91f8f5aabd73698876aba9353e8bfa6a05f2a76 Mon Sep 17 00:00:00 2001 From: Jacob Affinito Date: Fri, 22 Nov 2024 10:27:37 -0800 Subject: [PATCH] SuperAgent Health Check PoC. --- .../Core/AgentHealth/AgentHealthReporter.cs | 98 ++++++++++++- .../Agent/Core/AgentHealth/HealthCheck.cs | 58 ++++++++ .../Agent/Core/AgentHealth/HealthCodes.cs | 84 ++++++++++++ .../Core/AgentHealth/IAgentHealthReporter.cs | 2 + src/Agent/NewRelic/Agent/Core/AgentManager.cs | 15 +- .../Agent/Core/Config/Configuration.cs | 129 +++++++++++++++++- .../Agent/Core/Config/Configuration.xsd | 46 +++++++ .../Configuration/ConfigurationService.cs | 9 +- .../Configuration/DefaultConfiguration.cs | 53 ++++++- .../Configuration/InternalConfiguration.cs | 5 +- .../Configuration/ReportedConfiguration.cs | 9 ++ .../Core/DataTransport/ConnectionHandler.cs | 20 ++- .../Core/DataTransport/ConnectionManager.cs | 3 +- .../Core/DependencyInjection/AgentServices.cs | 1 - .../Agent/Core/Metrics/MetricNames.cs | 13 +- .../Configuration/IConfiguration.cs | 4 + .../AttributeDefinitionServiceTests.cs | 6 +- .../Attributes/LogContextDataFilterTests.cs | 6 +- .../Configuration/ConfigurationService.cs | 14 +- .../DefaultConfigurationTests.cs | 115 ++++++++-------- .../DataTransport/CollectorHostNameTests.cs | 9 +- .../RumTests/RumClientConfigTests.cs | 4 +- .../ServerSentEvent/ServerSentEventTests.cs | 5 +- .../ExhaustiveTestConfiguration.cs | 4 + .../Core.UnitTest/Errors/ErrorServiceTests.cs | 3 +- .../Spans/SpanEventMakerTests.cs | 7 +- .../TransactionAttributeMakerTests.cs | 9 +- .../Builders/DatabaseStatementParserTest.cs | 4 +- 28 files changed, 639 insertions(+), 96 deletions(-) create mode 100644 src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs create mode 100644 src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCodes.cs diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs index 7e0ae88485..95ebd04b14 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/AgentHealthReporter.cs @@ -17,6 +17,10 @@ using System.Linq; using System.Net; using System.Threading; +using System.IO; +using System.Security.Policy; +using System.Runtime.InteropServices; +using Grpc.Core; namespace NewRelic.Agent.Core.AgentHealth { @@ -38,10 +42,27 @@ public class AgentHealthReporter : ConfigurationBasedService, IAgentHealthReport private InterlockedCounter _traceContextCreateSuccessCounter; private InterlockedCounter _traceContextAcceptSuccessCounter; + private readonly HealthCheck _healthCheck; + public AgentHealthReporter(IMetricBuilder metricBuilder, IScheduler scheduler) { + _healthCheck = new() + { + IsHealthy = true, + Status = "Agent starting", + LastError = string.Empty + }; + _metricBuilder = metricBuilder; _scheduler = scheduler; + + // Want this to start immediately and write out the first health check - only if fl + if (string.IsNullOrWhiteSpace(_configuration.FleetId)) + { + Log.Info(">>>>>>>>>AgentHealthReporter: Starting health check"); + _scheduler.ExecuteEvery(PublishSuperAgentHealthCheck, TimeSpan.FromSeconds(_configuration.HealthFrequency), TimeSpan.Zero); + } + _scheduler.ExecuteEvery(LogPeriodicReport, _timeBetweenExecutions); var agentHealthEvents = Enum.GetValues(typeof(AgentHealthEvent)) as AgentHealthEvent[]; foreach (var agentHealthEvent in agentHealthEvents) @@ -667,6 +688,81 @@ public void ReportLogForwardingConfiguredValues() #endregion + #region Super Agent + + private void ReportIfSuperAgentHealthEnabled() + { + if (!string.IsNullOrWhiteSpace(_configuration.FleetId)) + { + ReportSupportabilityCountMetric(MetricNames.SupportabilitySuperAgentHealthEnabled); + } + } + + public void SetSuperAgentStatus((bool IsHealthy, string Code, string Status) healthStatus, params string[] statusParams) + { + Log.Info($">>>>>>>>>SetSuperAgentStatus code:'{healthStatus.Code}' status:'{healthStatus.Status}' params:'{(statusParams == null ? string.Empty : string.Join(",", statusParams))}'"); + + // Do nothing if super agent is not enabled + if (string.IsNullOrWhiteSpace(_configuration.FleetId)) + { + return; + } + + if (healthStatus.Equals(HealthCodes.AgentShutdownHealthy)) + { + if (_healthCheck.IsHealthy) + { + _healthCheck.TrySetHealth(healthStatus); + } + } + else + { + _healthCheck.TrySetHealth(healthStatus, statusParams); + } + } + + public void PublishSuperAgentHealthCheck() + { + Log.Info(">>>>>>>>>PublishSuperAgentHealthCheck"); + if (string.IsNullOrWhiteSpace(_configuration.FleetId) + || string.IsNullOrWhiteSpace(_configuration.HealthDeliveryLocation)) + { + Log.Info(">>>>>>>>>PublishSuperAgentHealthCheck.NOPE"); + return; + } + + Log.Info(">>>>>>>>>PublishSuperAgentHealthCheck.YEP"); + + var fileUri = new Uri(_configuration.HealthDeliveryLocation); + if (fileUri.Scheme != Uri.UriSchemeFile) + { + Log.Debug("The provided superagent.health.delivery_location is not a file URL, skipping super agent health check: " + _configuration.HealthDeliveryLocation); + return; + } + + // Ensure the path is cleaned up for Windows by removing a possible leading slash + var cleanedPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? fileUri.LocalPath.TrimStart('/') : fileUri.LocalPath; + if (!Directory.Exists(cleanedPath)) + { + try + { + Directory.CreateDirectory(cleanedPath); + } + catch (Exception ex) + { + Log.Error(ex, "Error creating directory for super agent health check: " + cleanedPath); + return; + } + } + + using (StreamWriter writer = new StreamWriter(Path.Combine(cleanedPath, _healthCheck.FileName))) + { + writer.WriteAsync(_healthCheck.ToYaml()).GetAwaiter().GetResult(); + } + } + + #endregion + public void ReportSupportabilityPayloadsDroppeDueToMaxPayloadSizeLimit(string endpoint) { TrySend(_metricBuilder.TryBuildSupportabilityPayloadsDroppedDueToMaxPayloadLimit(endpoint)); @@ -685,6 +781,7 @@ private void CollectOneTimeMetrics() ReportIfLoggingDisabled(); ReportIfInstrumentationIsDisabled(); ReportIfGCSamplerV2IsEnabled(); + ReportIfSuperAgentHealthEnabled(); } public void CollectMetrics() @@ -849,6 +946,5 @@ private void ReportIfGCSamplerV2IsEnabled() } } - } } diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs new file mode 100644 index 0000000000..7bfc35d593 --- /dev/null +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs @@ -0,0 +1,58 @@ +// Copyright 2020 New Relic, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +using System; +using NewRelic.Agent.Core.Utilities; + +namespace NewRelic.Agent.Core.AgentHealth +{ + public class HealthCheck + { + private const int NanoSecondsPerMillisecond = 1000000; + + public bool IsHealthy { get; internal set; } + public string Status { get; internal set; } + public string LastError { get; internal set; } + public DateTime StartTime { get; } = DateTime.UtcNow; + public DateTime StatusTime { get; internal set; } + public string FileName { get; } = "health-" + System.Guid.NewGuid().ToString("N") + ".yml"; + + /// + /// Set the health status of the agent, but only update changed values. + /// + /// + /// + /// + public void TrySetHealth((bool IsHealthy, string Code, string Status) healthStatus, params string[] statusParams) + { + // Threading! + if (IsHealthy != healthStatus.IsHealthy) + { + IsHealthy = healthStatus.IsHealthy; + } + + if (!Status.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase)) + { + if (statusParams != null && statusParams.Length > 0) + { + Status = string.Format(Status, statusParams); + } + else + { + Status = healthStatus.Status; + } + } + + if (!LastError.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase)) + { + LastError = healthStatus.Code; + } + } + + public string ToYaml() + { + StatusTime = DateTime.UtcNow; + return $"healthy: {IsHealthy}\nstatus: {Status}\nlast_error: {LastError}\nstatus_time_unix_nano: {StatusTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}\nstart_time_unix_nano: {StartTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}"; + } + } +} diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCodes.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCodes.cs new file mode 100644 index 0000000000..5c60eaf6fe --- /dev/null +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCodes.cs @@ -0,0 +1,84 @@ +// Copyright 2020 New Relic, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +namespace NewRelic.Agent.Core.AgentHealth +{ + public static class HealthCodes + { + /// + /// Healthy + /// + public static readonly (bool IsHealthy, string Code, string Status) Healthy = (true, "NR-APM-000", + "Healthy"); + + /// + /// Invalid license key (HTTP status code 401) + /// + public static readonly (bool IsHealthy, string Code, string Status) LicenseKeyInvalid = (false, "NR-APM-001", + "Invalid license key (HTTP status code 401)"); + + /// + /// License key missing in configuration + /// + public static readonly (bool IsHealthy, string Code, string Status) LicenseKeyMissing = (false, "NR-APM-002", + "License key missing in configuration"); + + /// + /// Forced disconnect received from New Relic (HTTP status code 410) + /// + public static readonly (bool IsHealthy, string Code, string Status) ForceDisconnect = (false, "NR-APM-003", + "Forced disconnect received from New Relic (HTTP status code 410)"); + + /// + /// HTTP error response code [%s] received from New Relic while sending data type [%s] + /// + public static readonly (bool IsHealthy, string Code, string Status) HttpError = (false, "NR-APM-004", + "HTTP error response code {0} received from New Relic while sending data type {1}"); + + /// + /// Missing application name in agent configuration + /// + public static readonly (bool IsHealthy, string Code, string Status) ApplicationNameMissing = (false, "NR-APM-005", + "Missing application name in agent configuration"); + + /// + /// The maximum number of configured app names (3) exceeded + /// + public static readonly (bool IsHealthy, string Code, string Status) MaxApplicationNamesExceeded = (false, "NR-APM-006", + "The maximum number of configured app names (3) exceeded"); + + /// + /// HTTP Proxy configuration error; response code [%s] + /// + public static readonly (bool IsHealthy, string Code, string Status) HttpProxyError = (false, "NR-APM-007", + "HTTP Proxy configuration error; response code {0}"); + + /// + /// Agent is disabled via configuration + /// + public static readonly (bool IsHealthy, string Code, string Status) AgentDisabledByConfiguration = (false, "NR-APM-008", + "Agent is disabled via configuration"); + + /// + /// Failed to connect to New Relic data collector + /// + public static readonly (bool IsHealthy, string Code, string Status) FailedToConnect = (false, "NR-APM-009", + "Failed to connect to New Relic data collector"); + + /// + /// Agent has shutdown + /// Only be reported if agent is "healthy" on shutdown. + /// If the agent status is not Healthy on agent shutdown, the existing error MUST not be overwritten. + /// + public static readonly (bool IsHealthy, string Code, string Status) AgentShutdownHealthy = (true, "NR-APM-099", + "Agent has shutdown"); + + // Agent health codes for the .NET agent are 200-299 + + /// + /// Agent has shutdown with exception [%s] + /// + public static readonly (bool IsHealthy, string Code, string Status) AgentShutdownError = (false, "NR-APM-200", + "Agent has shutdown with exception {0}"); + } +} diff --git a/src/Agent/NewRelic/Agent/Core/AgentHealth/IAgentHealthReporter.cs b/src/Agent/NewRelic/Agent/Core/AgentHealth/IAgentHealthReporter.cs index 23eed86cf7..255d69432f 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentHealth/IAgentHealthReporter.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentHealth/IAgentHealthReporter.cs @@ -151,5 +151,7 @@ public interface IAgentHealthReporter : IOutOfBandMetricSource void ReportLogForwardingEnabledWithFramework(string logFramework); void ReportByteMetric(string metricName, long totalBytes, long? exclusiveBytes = null); void ReportLoggingEventsEmpty(int count = 1); + void SetSuperAgentStatus((bool IsHealthy, string Code, string Status) healthStatus, params string[] statusParams); + void PublishSuperAgentHealthCheck(); } } diff --git a/src/Agent/NewRelic/Agent/Core/AgentManager.cs b/src/Agent/NewRelic/Agent/Core/AgentManager.cs index 2fccadd0c7..3a1dd0cf2e 100644 --- a/src/Agent/NewRelic/Agent/Core/AgentManager.cs +++ b/src/Agent/NewRelic/Agent/Core/AgentManager.cs @@ -3,6 +3,7 @@ using NewRelic.Agent.Api; using NewRelic.Agent.Configuration; +using NewRelic.Agent.Core.AgentHealth; using NewRelic.Agent.Core.Commands; using NewRelic.Agent.Core.Config; using NewRelic.Agent.Core.Configuration; @@ -81,6 +82,7 @@ public static IAgentManager Instance private IConfiguration Configuration { get { return _configurationSubscription.Configuration; } } private ThreadProfilingService _threadProfilingService; private readonly IWrapperService _wrapperService; + private readonly IAgentHealthReporter _agentHealthReporter; private volatile bool _shutdownEventReceived; private volatile bool _isInitialized; @@ -154,6 +156,9 @@ private AgentManager() var agentApi = _container.Resolve(); _wrapperService = _container.Resolve(); + // Start the AgentHealthReporter early so that we can potentially report health issues during startup + _agentHealthReporter = _container.Resolve(); + // Attempt to auto start the agent once all services have resolved, except in serverless mode if (!bootstrapConfig.ServerlessModeEnabled) _container.Resolve().AttemptAutoStart(); @@ -288,6 +293,7 @@ private void LogInitialized() "NEW_RELIC_SEND_DATA_ON_EXIT", "NEW_RELIC_SEND_DATA_ON_EXIT_THRESHOLD_MS", "NEW_RELIC_AZURE_FUNCTION_MODE_ENABLED", + "NEW_RELIC_SUPERAGENT_HEALTH_FREQUENCY" }; List environmentVariablesSensitive = new List { @@ -297,7 +303,9 @@ private void LogInitialized() "NEW_RELIC_PROXY_USER", "NEW_RELIC_PROXY_PASS", "NEW_RELIC_CONFIG_OBSCURING_KEY", - "NEW_RELIC_PROXY_PASS_OBFUSCATED" + "NEW_RELIC_PROXY_PASS_OBFUSCATED", + "NEW_RELIC_SUPERAGENT_FLEET_ID", + "NEW_RELIC_SUPERAGENT_HEALTH_DELIVERY_LOCATION" }; List<(string,string)> environmentVariablesDeprecated = new List<(string, string)> @@ -409,7 +417,7 @@ public ITracer GetTracerImpl(string tracerFactoryName, uint tracerArguments, str private void ProcessExit(object sender, EventArgs e) { Log.Debug("Received a ProcessExit CLR event for the application domain. About to shut down the .NET Agent..."); - + Shutdown(true); } @@ -437,13 +445,16 @@ private void Shutdown(bool cleanShutdown) Log.Debug("Shutting down public agent services..."); StopServices(); + _agentHealthReporter?.SetSuperAgentStatus(HealthCodes.AgentShutdownHealthy); } catch (Exception e) { + _agentHealthReporter?.SetSuperAgentStatus(HealthCodes.AgentShutdownError, e.Message); Log.Info(e, "Unexpected exception during agent shutdown"); } finally { + _agentHealthReporter?.PublishSuperAgentHealthCheck(); Log.Debug("Shutting down internal agent services..."); Dispose(); diff --git a/src/Agent/NewRelic/Agent/Core/Config/Configuration.cs b/src/Agent/NewRelic/Agent/Core/Config/Configuration.cs index 06bfb02b88..83159be15c 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/Configuration.cs +++ b/src/Agent/NewRelic/Agent/Core/Config/Configuration.cs @@ -1,7 +1,7 @@ // Copyright 2020 New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -// ------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ // // Generated by Xsd2Code. Version 3.6.0.0 // NewRelic.Agent.Core.ConfigListCSharpFalseFalseFalseFalseFalseTrueFalseFalseEntityBaseFalseFalseFalseTrueFalseNet20SerializeDeserializeSaveToFileLoadFromFileTrueFalseFalseFalseFalseFalseDefaultUTF8FalseAllTrue @@ -100,6 +100,8 @@ public partial class configuration private configurationCloud cloudField; + private configurationSuperagent superagentField; + private bool agentEnabledField; private bool rootAgentEnabledField; @@ -123,6 +125,7 @@ public partial class configuration /// public configuration() { + this.superagentField = new configurationSuperagent(); this.cloudField = new configurationCloud(); this.codeLevelMetricsField = new configurationCodeLevelMetrics(); this.processHostField = new configurationProcessHost(); @@ -615,6 +618,18 @@ public configurationCloud cloud } } + public configurationSuperagent superagent + { + get + { + return this.superagentField; + } + set + { + this.superagentField = value; + } + } + /// /// Set this to true to enable the agent. /// @@ -6175,6 +6190,118 @@ public virtual configurationCloudAws Clone() #endregion } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.6.0.20097")] + [System.SerializableAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:newrelic-config")] + public partial class configurationSuperagent + { + + private configurationSuperagentHealth healthField; + + private string fleetIdField; + + /// + /// configurationSuperagent class constructor + /// + public configurationSuperagent() + { + this.healthField = new configurationSuperagentHealth(); + } + + public configurationSuperagentHealth health + { + get + { + return this.healthField; + } + set + { + this.healthField = value; + } + } + + [System.Xml.Serialization.XmlAttributeAttribute()] + public string fleetId + { + get + { + return this.fleetIdField; + } + set + { + this.fleetIdField = value; + } + } + + #region Clone method + /// + /// Create a clone of this configurationSuperagent object + /// + public virtual configurationSuperagent Clone() + { + return ((configurationSuperagent)(this.MemberwiseClone())); + } + #endregion + } + + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.6.0.20097")] + [System.SerializableAttribute()] + [System.ComponentModel.DesignerCategoryAttribute("code")] + [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:newrelic-config")] + public partial class configurationSuperagentHealth + { + + private string deliveryLocationField; + + private int frequencyField; + + /// + /// configurationSuperagentHealth class constructor + /// + public configurationSuperagentHealth() + { + this.frequencyField = 5; + } + + [System.Xml.Serialization.XmlAttributeAttribute()] + public string deliveryLocation + { + get + { + return this.deliveryLocationField; + } + set + { + this.deliveryLocationField = value; + } + } + + [System.Xml.Serialization.XmlAttributeAttribute()] + [System.ComponentModel.DefaultValueAttribute(5)] + public int frequency + { + get + { + return this.frequencyField; + } + set + { + this.frequencyField = value; + } + } + + #region Clone method + /// + /// Create a clone of this configurationSuperagentHealth object + /// + public virtual configurationSuperagentHealth Clone() + { + return ((configurationSuperagentHealth)(this.MemberwiseClone())); + } + #endregion + } + [System.CodeDom.Compiler.GeneratedCodeAttribute("Xsd2Code", "3.6.0.20097")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="urn:newrelic-config")] diff --git a/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd b/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd index 0fcc34e732..16bed88a93 100644 --- a/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd +++ b/src/Agent/NewRelic/Agent/Core/Config/Configuration.xsd @@ -2072,6 +2072,52 @@ + + + + + These configuration properties will be set via the super agent (or one of its components) prior to agent startup. + + + + + + + + These configuration properties will be set via the super agent (or one of its components) prior to agent startup. + + + + + + + A "file:" URI that specifies the fully qualified path and filename of the health file. For example: file:///opt/newrelic/health.yml. + + + + + + + + The interval, in seconds, of how often the health file is to be written. + + + + + + + + + + + This assigns a fleet id to the language agent. This id is generated by the super agent. If this setting is present, it denotes that the agent is running in a super agent/fleet environment and the health file is to be generated. + + + + + + + diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/ConfigurationService.cs b/src/Agent/NewRelic/Agent/Core/Configuration/ConfigurationService.cs index 9bf25bfd2d..8dfc961c8b 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/ConfigurationService.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/ConfigurationService.cs @@ -11,6 +11,7 @@ using NewRelic.Agent.Core.SharedInterfaces.Web; using System; using System.Linq; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Configuration { @@ -27,6 +28,7 @@ public class ConfigurationService : IConfigurationService, IDisposable private readonly IHttpRuntimeStatic _httpRuntimeStatic; private readonly IConfigurationManagerStatic _configurationManagerStatic; private readonly IDnsStatic _dnsStatic; + private readonly IAgentHealthReporter _agentHealthReporter; /// /// Do not use this field outside of this class. It only exists for testing purposes. @@ -35,15 +37,16 @@ public class ConfigurationService : IConfigurationService, IDisposable public IConfiguration Configuration { get; private set; } - public ConfigurationService(IEnvironment environment, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) + public ConfigurationService(IEnvironment environment, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) { _environment = environment; _processStatic = processStatic; _httpRuntimeStatic = httpRuntimeStatic; _configurationManagerStatic = configurationManagerStatic; _dnsStatic = dnsStatic; + _agentHealthReporter = agentHealthReporter; - Configuration = new InternalConfiguration(_environment, _localConfiguration, _serverConfiguration, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, dnsStatic); + Configuration = new InternalConfiguration(_environment, _localConfiguration, _serverConfiguration, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, dnsStatic, _agentHealthReporter); _subscriptions.Add(OnConfigurationDeserialized); _subscriptions.Add(OnServerConfigurationUpdated); @@ -122,7 +125,7 @@ private void UpdateAndPublishConfiguration(ConfigurationUpdateSource configurati { var previousLogLevel = Configuration.LoggingLevel; - Configuration = new InternalConfiguration(_environment, _localConfiguration, _serverConfiguration, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + Configuration = new InternalConfiguration(_environment, _localConfiguration, _serverConfiguration, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); UpdateLogLevel(previousLogLevel); diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs index df2518d29b..c68ac82cc0 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/DefaultConfiguration.cs @@ -18,6 +18,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Configuration { @@ -47,6 +48,7 @@ public class DefaultConfiguration : IConfiguration private readonly IHttpRuntimeStatic _httpRuntimeStatic = new HttpRuntimeStatic(); private readonly IConfigurationManagerStatic _configurationManagerStatic = new ConfigurationManagerStaticMock(); private readonly IDnsStatic _dnsStatic; + private readonly IAgentHealthReporter _agentHealthReporter; /// /// Default configuration. It will contain reasonable default values for everything and never anything more. Useful when you don't have configuration off disk or a collector response yet. @@ -72,7 +74,7 @@ private DefaultConfiguration() ConfigurationVersion = Interlocked.Increment(ref _currentConfigurationVersion); } - protected DefaultConfiguration(IEnvironment environment, configuration localConfiguration, ServerConfiguration serverConfiguration, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) + protected DefaultConfiguration(IEnvironment environment, configuration localConfiguration, ServerConfiguration serverConfiguration, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) : this() { _environment = environment; @@ -84,7 +86,7 @@ protected DefaultConfiguration(IEnvironment environment, configuration localConf _utilizationFullHostName = new Lazy(_dnsStatic.GetFullHostName); _utilizationHostName = new Lazy(_dnsStatic.GetHostName); - + _agentHealthReporter = agentHealthReporter; if (localConfiguration != null) { @@ -217,6 +219,11 @@ public virtual string AgentLicenseKey if (_agentLicenseKey != null) _agentLicenseKey = _agentLicenseKey.Trim(); + if (_agentLicenseKey == null && !ServerlessModeEnabled) + { + TrySetSuperAgentStatus(HealthCodes.LicenseKeyMissing); + } + return _agentLicenseKey; } } @@ -316,6 +323,7 @@ private IEnumerable GetApplicationNames() return new List { _processStatic.GetCurrentProcess().ProcessName }; } + TrySetSuperAgentStatus(HealthCodes.ApplicationNameMissing); throw new Exception("An application name must be provided"); } @@ -2495,7 +2503,35 @@ public TimeSpan StackExchangeRedisCleanupCycle public bool GCSamplerV2Enabled => _bootstrapConfiguration.GCSamplerV2Enabled; - #endregion + #region Super Agent + + public virtual string FleetId + { + get + { + return EnvironmentOverrides(_localConfiguration.superagent.fleetId, "NEW_RELIC_SUPERAGENT_FLEET_ID"); + } + } + + public virtual string HealthDeliveryLocation + { + get + { + return EnvironmentOverrides(_localConfiguration.superagent.health.deliveryLocation, "NEW_RELIC_SUPERAGENT_HEALTH_DELIVERY_LOCATION"); + } + } + + public virtual int HealthFrequency + { + get + { + return EnvironmentOverrides(_localConfiguration.superagent.health.frequency, "NEW_RELIC_SUPERAGENT_HEALTH_FREQUENCY") ?? 5; + } + } + + #endregion Super Agent + + #endregion Properties #region Helpers @@ -2859,6 +2895,17 @@ private static string TryGetValidPrefix(string prefix) return specified ? value : default(int?); } + // Since the configuration is initialized before the AgentHealthReporter, needed a way to not call it till it was ready + private void TrySetSuperAgentStatus((bool IsHealthy, string Code, string Status) healthStatus) + { + if (_agentHealthReporter == null) + { + return; + } + + _agentHealthReporter.SetSuperAgentStatus(healthStatus); + } + #endregion #region deprecated/disabled parameter group settings diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/InternalConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/InternalConfiguration.cs index cbe0332ac6..f61859fdf3 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/InternalConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/InternalConfiguration.cs @@ -1,6 +1,7 @@ // Copyright 2020 New Relic, Inc. All rights reserved. // SPDX-License-Identifier: Apache-2.0 +using NewRelic.Agent.Core.AgentHealth; using NewRelic.Agent.Core.Config; using NewRelic.Agent.Core.SharedInterfaces; using NewRelic.Agent.Core.SharedInterfaces.Web; @@ -12,8 +13,8 @@ namespace NewRelic.Agent.Core.Configuration /// internal class InternalConfiguration : DefaultConfiguration { - public InternalConfiguration(IEnvironment environment, configuration localConfiguration, ServerConfiguration serverConfiguration, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) : - base(environment, localConfiguration, serverConfiguration, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic) + public InternalConfiguration(IEnvironment environment, configuration localConfiguration, ServerConfiguration serverConfiguration, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) : + base(environment, localConfiguration, serverConfiguration, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic, agentHealthReporter) { } } } diff --git a/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs b/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs index 8aae7c13f7..8d7711c4af 100644 --- a/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Core/Configuration/ReportedConfiguration.cs @@ -728,6 +728,15 @@ public IReadOnlyDictionary GetAppSettings() return _configuration.GetAppSettings(); } + [JsonProperty("superagent.fleet_id")] + public string FleetId => _configuration.FleetId; + + [JsonProperty("superagent.health.delivery_location")] + public string HealthDeliveryLocation => _configuration.HealthDeliveryLocation; + + [JsonProperty("superagent.health.frequency")] + public int HealthFrequency => _configuration.HealthFrequency; + #endregion } } diff --git a/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionHandler.cs b/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionHandler.cs index eb67f8c641..c7f2aac884 100644 --- a/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionHandler.cs +++ b/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionHandler.cs @@ -105,6 +105,7 @@ public void Connect() EventBus.Publish(new AgentConnectedEvent()); Log.Info("Agent fully connected."); + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.Healthy); } catch (Exception e) @@ -432,9 +433,26 @@ private T SendDataOverWire(ICollectorWire wire, string method, params object[ { Log.Debug(ex, "Request({0}): Received a {1} {2} response invoking method \"{3}\" with payload \"{4}\"", requestGuid, (int)ex.StatusCode, ex.StatusCode, method, serializedData); - if (ex.StatusCode == HttpStatusCode.Gone) + if (ex.StatusCode == HttpStatusCode.Unauthorized) + { + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.LicenseKeyInvalid); + } + else if (ex.StatusCode == HttpStatusCode.Gone) { Log.Info(ex, "Request({0}): The server has requested that the agent disconnect. The agent is shutting down.", requestGuid); + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.ForceDisconnect); + } + else if (ex.StatusCode == HttpStatusCode.ProxyAuthenticationRequired) + { + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.HttpProxyError, ex.StatusCode.ToString()); + } + else if (method.Equals("connect")) + { + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.FailedToConnect, ex.StatusCode.ToString()); + } + else + { + _agentHealthReporter.SetSuperAgentStatus(HealthCodes.HttpError, ex.StatusCode.ToString(), method); } throw; diff --git a/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionManager.cs b/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionManager.cs index e31d2c5a34..b360e92066 100644 --- a/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionManager.cs +++ b/src/Agent/NewRelic/Agent/Core/DataTransport/ConnectionManager.cs @@ -10,6 +10,8 @@ using System.IO; using System.Linq; using System.Net; +using NewRelic.Agent.Core.AgentHealth; + #if !NETFRAMEWORK using System.Net.Http; #endif @@ -45,7 +47,6 @@ public ConnectionManager(IConnectionHandler connectionHandler, IScheduler schedu { _connectionHandler = connectionHandler; _scheduler = scheduler; - _subscriptions.Add(OnStartAgent); _subscriptions.Add(OnRestartAgent); diff --git a/src/Agent/NewRelic/Agent/Core/DependencyInjection/AgentServices.cs b/src/Agent/NewRelic/Agent/Core/DependencyInjection/AgentServices.cs index 0b424e3434..341cc86d78 100644 --- a/src/Agent/NewRelic/Agent/Core/DependencyInjection/AgentServices.cs +++ b/src/Agent/NewRelic/Agent/Core/DependencyInjection/AgentServices.cs @@ -243,7 +243,6 @@ public static void StartServices(IContainer container, bool serverlessModeEnable container.Resolve(); container.Resolve(); - container.Resolve(); #if NETFRAMEWORK // Start GCSampler on separate thread due to delay in collecting Instance Names, // which can stall application startup and cause the app start to timeout diff --git a/src/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs b/src/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs index 2f399603a7..13059bc2c1 100644 --- a/src/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs +++ b/src/Agent/NewRelic/Agent/Core/Metrics/MetricNames.cs @@ -708,7 +708,7 @@ public static string GetSupportabilityAgentApi(string methodName) }; - ///DistributedTracing + //DistributedTracing private const string SupportabilityDistributedTracePs = SupportabilityPs + "DistributedTrace" + PathSeparator; @@ -761,7 +761,7 @@ public static string GetSupportabilityAgentApi(string methodName) public const string SupportabilityDistributedTraceCreatePayloadException = SupportabilityDistributedTraceCreatePayloadPs + "Exception"; - ///Trace Context + //Trace Context private const string SupportabilityTraceContextPs = SupportabilityPs + "TraceContext" + PathSeparator; @@ -1154,5 +1154,14 @@ public static string GetSupportabilityLogForwardingEnabledWithFrameworkName(stri } #endregion + + #region Super Agent + + private const string SuperAgent = "SuperAgent"; + private const string Health = "Health"; + private const string SupportabilitySuperAgentPs = SupportabilityPs + SuperAgent + PathSeparator; + public const string SupportabilitySuperAgentHealthEnabled = SupportabilitySuperAgentPs + Health + PathSeparator + Enabled; + + #endregion } } diff --git a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs index 95d45a6b32..aeec6ca824 100644 --- a/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs +++ b/src/Agent/NewRelic/Agent/Extensions/NewRelic.Agent.Extensions/Configuration/IConfiguration.cs @@ -236,5 +236,9 @@ public interface IConfiguration string AwsAccountId { get; } bool GCSamplerV2Enabled { get; } + + string FleetId { get; } + string HealthDeliveryLocation { get; } + int HealthFrequency { get; } } } diff --git a/tests/Agent/UnitTests/Core.UnitTest/Attributes/AttributeDefinitionServiceTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Attributes/AttributeDefinitionServiceTests.cs index e95b099766..ccf7a47ba0 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Attributes/AttributeDefinitionServiceTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Attributes/AttributeDefinitionServiceTests.cs @@ -19,6 +19,7 @@ using NewRelic.Agent.Core.WireModels; using NewRelic.Agent.Core.Segments; using System.Collections.Generic; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Attributes.Tests { @@ -43,6 +44,7 @@ public class AttributeDefinitionServiceTests private IProcessStatic _processStatic; private IConfigurationManagerStatic _configurationManagerStatic; private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; private ConfigurationAutoResponder _configAutoResponder; @@ -63,7 +65,7 @@ public void SetUp() _dnsStatic = Mock.Create(); _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); - + _agentHealthReporter = Mock.Create(); _runTimeConfiguration = new RunTimeConfiguration(); _serverConfig = new ServerConfiguration(); _localConfig = new configuration(); @@ -86,7 +88,7 @@ public void SetUp() private void UpdateConfig() { - _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); EventBus.Publish(new ConfigurationUpdatedEvent(_configuration, ConfigurationUpdateSource.Local)); } diff --git a/tests/Agent/UnitTests/Core.UnitTest/Attributes/LogContextDataFilterTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Attributes/LogContextDataFilterTests.cs index ec5c4527b2..ca37a34444 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Attributes/LogContextDataFilterTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Attributes/LogContextDataFilterTests.cs @@ -15,6 +15,7 @@ using NewRelic.Agent.Core.Config; using NewRelic.Agent.Core.Configuration.UnitTest; using NUnit.Framework.Constraints; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Attributes.Tests { @@ -35,6 +36,7 @@ public class LogContextDataFilterTests private IProcessStatic _processStatic; private IConfigurationManagerStatic _configurationManagerStatic; private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; private Dictionary _unfilteredContextData = new Dictionary() @@ -57,7 +59,7 @@ public void SetUp() _dnsStatic = Mock.Create(); _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); - + _agentHealthReporter = Mock.Create(); _runTimeConfiguration = new RunTimeConfiguration(); _serverConfig = new ServerConfiguration(); _localConfig = new configuration(); @@ -158,7 +160,7 @@ public void LogContextDataFilterRule(string inputRuleText, bool isInclude, strin } private void UpdateConfig() { - _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); EventBus.Publish(new ConfigurationUpdatedEvent(_configuration, ConfigurationUpdateSource.Local)); } diff --git a/tests/Agent/UnitTests/Core.UnitTest/Configuration/ConfigurationService.cs b/tests/Agent/UnitTests/Core.UnitTest/Configuration/ConfigurationService.cs index 987fb13df9..00ea0de93e 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Configuration/ConfigurationService.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Configuration/ConfigurationService.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Configuration.UnitTest { @@ -27,7 +28,8 @@ public class Event_ConfigurationDeserialized public void SetUp() { _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), - Mock.Create(), Mock.Create(), Mock.Create()); + Mock.Create(), Mock.Create(), Mock.Create(), + Mock.Create()); } [TearDown] @@ -57,7 +59,7 @@ public class Event_ConnectedToCollector public void publishes_ConfigurationUpdatedEvent() { var wasCalled = false; - using (new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create())) + using (new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create())) using (new EventSubscription(_ => wasCalled = true)) { EventBus.Publish(new ServerConfigurationUpdatedEvent(new ServerConfiguration @@ -78,7 +80,7 @@ public class Event_AppNameUpdateEvent public void publishes_AppNameUpdateEvent() { var wasCalled = false; - using (new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create())) + using (new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create())) using (new EventSubscription(_ => wasCalled = true)) { EventBus.Publish(new AppNameUpdateEvent(new[] { "NewAppName" })); @@ -99,7 +101,7 @@ public class Event_ErrorGroupCallbackUpdateEvent [SetUp] public void SetUp() { - _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); + _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); } [TearDown] @@ -144,7 +146,7 @@ public class Request_GetCurrentConfiguration [SetUp] public void SetUp() { - _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); + _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); } [TearDown] @@ -192,7 +194,7 @@ public class ConfigurationSeviceUpdatesLogLevel [SetUp] public void SetUp() { - _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); + _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); _logLevelChanged = false; _newLogLevel = null; diff --git a/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs index d6559d45ff..3d0141b8da 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Configuration/DefaultConfigurationTests.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Xml.Serialization; +using NewRelic.Agent.Core.AgentHealth; using NewRelic.Agent.Core.Config; using NewRelic.Agent.Core.DataTransport; using NewRelic.Agent.Core.SharedInterfaces; @@ -18,8 +19,8 @@ namespace NewRelic.Agent.Core.Configuration.UnitTest { internal class TestableDefaultConfiguration : DefaultConfiguration { - public TestableDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) - : base(environment, localConfig, serverConfig, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic) { } + public TestableDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) + : base(environment, localConfig, serverConfig, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic, agentHealthReporter) { } public static void ResetStatics() { @@ -42,6 +43,7 @@ public class DefaultConfigurationTests private IBootstrapConfiguration _bootstrapConfiguration; private DefaultConfiguration _defaultConfig; private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; [SetUp] public void SetUp() @@ -56,8 +58,9 @@ public void SetUp() _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); _dnsStatic = Mock.Create(); + _agentHealthReporter = Mock.Create(); - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); TestableDefaultConfiguration.ResetStatics(); } @@ -94,7 +97,7 @@ public bool TransactionEventsCanBeDisabledByServer(bool? server, bool local) [Test] public void EveryConfigShouldGetNewVersionNumber() { - var newConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var newConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(newConfig.ConfigurationVersion - 1, Is.EqualTo(_defaultConfig.ConfigurationVersion)); } @@ -736,7 +739,7 @@ private void SetupNewConfigsWithSecurityPolicy(string securityPolicyName, bool s { var securityPolicies = new Dictionary { { securityPolicyName, new SecurityPolicyState(securityPolicyEnabled, false) } }; _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(securityPolicies); - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); } [TestCase(true, true, ExpectedResult = true)] @@ -939,7 +942,7 @@ public void Decodes_IgnoreAndExpectedClasses_IgnoreAndExpectedMessages_ExpectedS localConfiguration = serializer.Deserialize(reader) as configuration; } - _defaultConfig = new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(new[] { "404", "500" }, Is.EquivalentTo(_defaultConfig.ExpectedErrorStatusCodesForAgentSettings)); @@ -1356,7 +1359,7 @@ public void ThreadProfilingIgnoreMethodFromXmlDecodesIntoListOfStrings() localConfiguration = serializer.Deserialize(reader) as configuration; } - _defaultConfig = new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(_defaultConfig.ThreadProfilingIgnoreMethods, Does.Contain("System.Threading.WaitHandle:WaitAny")); } @@ -2152,7 +2155,7 @@ public void ApplicationNamesUsesAzureFunctionName_IfAzureFunctionMode_IsEnabled( _runTimeConfig.ApplicationNames = new List(); _localConfig.appSettings.Add(new configurationAdd { key = "AzureFunctionModeEnabled", value = functionModeEnabled.ToString() }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Mock.Arrange(() => _bootstrapConfiguration.AzureFunctionModeDetected).Returns(functionModeEnabled); @@ -2177,7 +2180,7 @@ public void ApplicationNameDoesNotUserAzureFunctionName_IfAzureModeIsEnabled_But _runTimeConfig.ApplicationNames = new List(); _localConfig.appSettings.Add(new configurationAdd { key = "AzureFunctionModeEnabled", value = "true" }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Mock.Arrange(() => _bootstrapConfiguration.AzureFunctionModeDetected).Returns(true); @@ -2218,7 +2221,7 @@ public void UseResourceBasedNamingIsEnabled() value = "true" }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.UseResourceBasedNamingForWCFEnabled, Is.True); } @@ -2226,7 +2229,7 @@ public void UseResourceBasedNamingIsEnabled() [Test] public void UseResourceBasedNamingIsDisabledByDefault() { - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.UseResourceBasedNamingForWCFEnabled, Is.False); } @@ -2295,7 +2298,7 @@ public void CrossApplicationTracingEnabledIsTrueWithNewServerConfig() _localConfig.crossApplicationTracer.enabled = true; _serverConfig = new ServerConfiguration(); _serverConfig.CatId = "123#456"; - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(_defaultConfig.CrossApplicationTracingEnabled, Is.True); } @@ -2307,7 +2310,7 @@ public void CrossApplicationTracingEnabledIsFalseWithGetDefaultServerConfig() _localConfig.crossApplicationTracer.enabled = true; _serverConfig = ServerConfiguration.GetDefault(); _serverConfig.CatId = "123#456"; - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(_defaultConfig.CrossApplicationTracingEnabled, Is.False); } @@ -2322,7 +2325,7 @@ public void CrossApplicationTracingEnabledIs_False_InServerlessMode() _localConfig.crossApplicationTracer.enabled = true; _serverConfig = new ServerConfiguration(); _serverConfig.CatId = "123#456"; - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(_defaultConfig.CrossApplicationTracingEnabled, Is.False); } @@ -2342,7 +2345,7 @@ public void DistributedTracingEnabled(bool localConfig, bool expectedResult) [Test] public void DistributedTracingEnabledIsFalseByDefault() { - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(_defaultConfig.DistributedTracingEnabled, Is.False); } @@ -2394,7 +2397,7 @@ public void SamplingTarget_Is10_InServerlessMode() Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.SamplingTarget, Is.EqualTo(10)); @@ -2416,7 +2419,7 @@ public void SamplingTargetPeriodInSeconds_Is60_InServerlessMode() Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.SamplingTargetPeriodInSeconds, Is.EqualTo(60)); @@ -2430,7 +2433,7 @@ public void PrimaryApplicationIdValueIsSetFromEnvironmentVariable_WhenInServerle Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_PRIMARY_APPLICATION_ID")).Returns("PrimaryApplicationIdValue"); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.PrimaryApplicationId, Is.EqualTo("PrimaryApplicationIdValue")); @@ -2443,7 +2446,7 @@ public void TrustedAccountKeyValueIsSetFromEnvironmentVariable_WhenInServerlessM Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_TRUSTED_ACCOUNT_KEY")).Returns("TrustedAccountKeyValue"); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.TrustedAccountKey, Is.EqualTo("TrustedAccountKeyValue")); @@ -2456,7 +2459,7 @@ public void AccountIdValueIsSetFromEnvironmentVariable_WhenInServerlessMode() Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_ACCOUNT_ID")).Returns("AccountIdValue"); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.AccountId, Is.EqualTo("AccountIdValue")); @@ -2468,7 +2471,7 @@ public void PrimaryApplicationId_DefaultsToUnknown_WhenInServerlessMode() Mock.Arrange(() => _bootstrapConfiguration.ServerlessModeEnabled).Returns(true); // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.PrimaryApplicationId, Is.EqualTo("Unknown")); @@ -2481,7 +2484,7 @@ public void PrimaryApplicationId_ComesFromLocalConfig_WhenInServerlessMode() _localConfig.distributedTracing.primary_application_id = "PrimaryApplicationIdValue"; // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.PrimaryApplicationId, Is.EqualTo("PrimaryApplicationIdValue")); @@ -2494,7 +2497,7 @@ public void TrustedAccountKey_ComesFromLocalConfig_WhenInServerlessMode() _localConfig.distributedTracing.trusted_account_key = "TrustedAccountKeyValue"; // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.TrustedAccountKey, Is.EqualTo("TrustedAccountKeyValue")); @@ -2507,7 +2510,7 @@ public void AccountId_ComesFromLocalConfig_WhenInServerlessMode() _localConfig.distributedTracing.account_id = "AccountIdValue"; // Act - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); // Assert Assert.That(defaultConfig.AccountId, Is.EqualTo("AccountIdValue")); @@ -2532,7 +2535,7 @@ public bool SpanEventsEnabledHasCorrectValue(bool distributedTracingEnabled, boo _localConfig.spanEvents.enabled = spanEventsEnabled; _localConfig.distributedTracing.enabled = distributedTracingEnabled; - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return _defaultConfig.SpanEventsEnabled; } @@ -2627,7 +2630,7 @@ public int InfiniteTracing_SpanQueueSize(string envConfigValue, int? localConfig _localConfig.infiniteTracing.span_events.queue_size = localConfigValue.Value; } - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingQueueSizeSpans; } @@ -2660,7 +2663,7 @@ public void InfiniteTracing_TraceObserver _localConfig.appSettings.Add(new configurationAdd() { key = "InfiniteTracingTraceObserverSsl", value = localSsl }); } - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); var expectedHost = envHost != null ? envHost @@ -2697,7 +2700,7 @@ public int InfiniteTracing_TimeoutData(string envConfigVal, string appSettingsVa _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingTimeoutSend", value = appSettingsValue }); Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_TIMEOUT_SEND")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingTraceTimeoutMsSendData; } @@ -2715,7 +2718,7 @@ public int InfiniteTracing_TimeoutConnect(string envConfigVal, string appSetting _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingTimeoutConnect", value = appSettingsValue }); Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_TIMEOUT_CONNECT")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingTraceTimeoutMsConnect; } @@ -2737,7 +2740,7 @@ public int InfiniteTracing_TimeoutConnect(string envConfigVal, string appSetting _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsTestFlaky", value = appSettingsValue }); Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_TEST_FLAKY")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingTraceObserverTestFlaky; } @@ -2760,7 +2763,7 @@ public int InfiniteTracing_SpanBatchSize(string envConfigVal, string appSettingV _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsBatchSize", value = appSettingVal }); Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_BATCH_SIZE")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingBatchSizeSpans; } @@ -2783,7 +2786,7 @@ public int InfiniteTracing_SpanPartitionCount(string envConfigVal, string appSet _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsPartitionCount", value = appSettingVal }); Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_PARTITION_COUNT")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingPartitionCountSpans; } @@ -2802,7 +2805,7 @@ public int InfiniteTracing_SpanPartitionCount(string envConfigVal, string appSet _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsTestDelay", value = appSettingsValue }); Mock.Arrange(() => _environment.GetEnvironmentVariable("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_TEST_DELAY")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingTraceObserverTestDelayMs; } @@ -2827,7 +2830,7 @@ public void InfiniteTracing_SpanStreamsCount _localConfig.appSettings.Add(new configurationAdd { key = "InfiniteTracingSpanEventsStreamsCount", value = appSettingsValue }); Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_INFINITE_TRACING_SPAN_EVENTS_STREAMS_COUNT")).Returns(envConfigVal); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.InfiniteTracingTraceCountConsumers, Is.EqualTo(expectedResult)); } @@ -2846,7 +2849,7 @@ public bool InfiniteTracing_Compression(string envConfigVal, bool? localConfigVa _localConfig.infiniteTracing.compression = localConfigVal.Value; } - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.InfiniteTracingCompression; } @@ -3554,7 +3557,7 @@ public bool SecurityPoliciesTokenExists(string environmentValue, string localCon _localConfig.securityPoliciesToken = localConfigValue; Mock.Arrange(() => _environment.GetEnvironmentVariableFromList("NEW_RELIC_SECURITY_POLICIES_TOKEN")) .Returns(environmentValue); - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return _defaultConfig.SecurityPoliciesTokenExists; } @@ -3568,7 +3571,7 @@ public bool SecurityPoliciesTokenExists(string environmentValue, string localCon public bool AsyncHttpClientSegmentsDoNotCountTowardsParentExclusiveTimeTests(string localConfigValue) { _localConfig.appSettings.Add(new configurationAdd { key = "ForceSynchronousTimingCalculation.HttpClient", value = localConfigValue }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.ForceSynchronousTimingCalculationHttpClient; } @@ -3580,7 +3583,7 @@ public bool AsyncHttpClientSegmentsDoNotCountTowardsParentExclusiveTimeTests(str public bool AspNetCore6PlusBrowserInjectionTests(string localConfigValue) { _localConfig.appSettings.Add(new configurationAdd { key = "EnableAspNetCore6PlusBrowserInjection", value = localConfigValue }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); return defaultConfig.EnableAspNetCore6PlusBrowserInjection; } @@ -3650,7 +3653,7 @@ public bool ShouldCodeLevelMetricsBeEnabled(bool? localConfigValue, string envCo [Test] public void HarvestCycleOverride_DefaultOrNotSet() { - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.Multiple(() => { @@ -3677,7 +3680,7 @@ public void HarvestCycleOverride_Metrics_NotValidValueSet(string value) value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.MetricsHarvestCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3695,7 +3698,7 @@ public void HarvestCycleOverride_TransactionTraces_NotValidValueSet(string value value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.TransactionTracesHarvestCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3713,7 +3716,7 @@ public void HarvestCycleOverride_ErrorTraces_NotValidValueSet(string value) value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.ErrorTracesHarvestCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3731,7 +3734,7 @@ public void HarvestCycleOverride_SpanEvents_NotValidValueSet(string value) value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.SpanEventsHarvestCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3749,7 +3752,7 @@ public void HarvestCycleOverride_GetAgentCommands_NotValidValueSet(string value) value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.GetAgentCommandsCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3767,7 +3770,7 @@ public void HarvestCycleOverride_SqlTraces_NotValidValueSet(string value) value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.SqlTracesHarvestCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3785,7 +3788,7 @@ public void HarvestCycleOverride_StackExchangeRedisCleanup_NotValidValueSet(stri value = value }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.StackExchangeRedisCleanupCycle.TotalSeconds, Is.EqualTo(60)); } @@ -3800,7 +3803,7 @@ public void HarvestCycleOverride_Metrics_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.MetricsHarvestCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3824,7 +3827,7 @@ public void HarvestCycleOverride_TransactionTraces_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.TransactionTracesHarvestCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3848,7 +3851,7 @@ public void HarvestCycleOverride_ErrorTraces_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.ErrorTracesHarvestCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3872,7 +3875,7 @@ public void HarvestCycleOverride_SpanEvents_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.SpanEventsHarvestCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3896,7 +3899,7 @@ public void HarvestCycleOverride_GetAgentCommands_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.GetAgentCommandsCycle.Seconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3920,7 +3923,7 @@ public void HarvestCycleOverride_SqlTraces_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.SqlTracesHarvestCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -3944,7 +3947,7 @@ public void HarvestCycleOverride_StackExchangeRedisCleanup_ValidValueSet() value = expectedSeconds }); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.StackExchangeRedisCleanupCycle.TotalSeconds, Is.EqualTo(Convert.ToInt32(expectedSeconds))); @@ -4105,7 +4108,7 @@ public void AiMonitoringRecordContentDisabledWhenAiMonitoringDisabled() public void LlmTokenCountingCallbackComesFromRuntimeConfig() { var runtimeConfig = new RunTimeConfiguration(Enumerable.Empty(), null, (s1, s2) => 42); - var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, runtimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, runtimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Assert.That(defaultConfig.LlmTokenCountingCallback("foo", "bar"), Is.EqualTo(42)); } #endregion @@ -4522,12 +4525,12 @@ private DefaultConfiguration GenerateConfigFromXml(string xml) localConfiguration = serializer.Deserialize(reader) as configuration; } - return new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + return new TestableDefaultConfiguration(_environment, localConfiguration, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); } private void CreateDefaultConfiguration() { - _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _defaultConfig = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); } } } diff --git a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs index 310262fa83..693598dbd4 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/DataTransport/CollectorHostNameTests.cs @@ -14,12 +14,14 @@ using NewRelic.Agent.Core.DataTransport; using System.Reflection; using NewRelic.Agent.TestUtilities; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.CrossAgentTests.DataTransport { internal class TestDefaultConfiguration : DefaultConfiguration { - public TestDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration _securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) : base(environment, localConfig, serverConfig, runTimeConfiguration, _securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic) { } + public TestDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration _securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) : + base(environment, localConfig, serverConfig, runTimeConfiguration, _securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic, agentHealthReporter) { } } [TestFixture] @@ -47,6 +49,8 @@ public class CollectorHostNameTests private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; + public static List CollectorHostnameTestData { get { return GetCollectorHostnameTestData(); } @@ -65,7 +69,8 @@ public void Setup() _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); _dnsStatic = Mock.Create(); - _defaultConfig = new TestDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _agentHealthReporter = Mock.Create(); + _defaultConfig = new TestDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfig, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); } diff --git a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/RumTests/RumClientConfigTests.cs b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/RumTests/RumClientConfigTests.cs index 039a9de4c0..7af4c1e4e1 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/RumTests/RumClientConfigTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/RumTests/RumClientConfigTests.cs @@ -54,6 +54,7 @@ public class RumClientConfigTests private IProcessStatic _processStatic; private IConfigurationManagerStatic _configurationManagerStatic; private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; private ConfigurationAutoResponder _configAutoResponder; @@ -88,6 +89,7 @@ private void SetUp(TestCase testCase) _dnsStatic = Mock.Create(); _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); + _agentHealthReporter = Mock.Create(); _runTimeConfiguration = new RunTimeConfiguration(); _serverConfig = new ServerConfiguration(); @@ -107,7 +109,7 @@ private void SetUp(TestCase testCase) _serverConfig.RumSettingsApplicationId = testCase.ConnectReply.ApplicationId; _localConfig.browserMonitoring.attributes.enabled = testCase.BrowserMonitoringAttributesEnabled; - _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); _configurationService = Mock.Create(); Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); diff --git a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/ServerSentEvent/ServerSentEventTests.cs b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/ServerSentEvent/ServerSentEventTests.cs index 0bd5b7b310..197b429bdb 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/ServerSentEvent/ServerSentEventTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/CrossAgentTests/ServerSentEvent/ServerSentEventTests.cs @@ -27,12 +27,13 @@ using System.Reflection; using NewRelic.Agent.TestUtilities; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.CrossAgentTests { internal class TestableDefaultConfiguration : DefaultConfiguration { - public TestableDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic) : base(environment, localConfig, serverConfig, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic) { } + public TestableDefaultConfiguration(IEnvironment environment, configuration localConfig, ServerConfiguration serverConfig, RunTimeConfiguration runTimeConfiguration, SecurityPoliciesConfiguration securityPoliciesConfiguration, IBootstrapConfiguration bootstrapConfiguration, IProcessStatic processStatic, IHttpRuntimeStatic httpRuntimeStatic, IConfigurationManagerStatic configurationManagerStatic, IDnsStatic dnsStatic, IAgentHealthReporter agentHealthReporter) : base(environment, localConfig, serverConfig, runTimeConfiguration, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic, agentHealthReporter) { } } [TestFixture] @@ -82,7 +83,7 @@ public void SetUp() _bootstrapConfig = Mock.Create(); _defaultConfig = new TestableDefaultConfiguration(Mock.Create(), _localConfig, _serverConfig, _runTimeConfig, new SecurityPoliciesConfiguration(), _bootstrapConfig, Mock.Create(), Mock.Create(), Mock.Create(), - Mock.Create()); + Mock.Create(), Mock.Create()); _transactionMetricNameMaker = Mock.Create(); Mock.Arrange(() => _transactionMetricNameMaker.GetTransactionMetricName(Arg.Matches(txName => txName.IsWeb))) diff --git a/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs b/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs index 71ae896d5e..f7b8c727ba 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/DataTransport/ExhaustiveTestConfiguration.cs @@ -499,5 +499,9 @@ public IReadOnlyDictionary GetAppSettings() public string AwsAccountId => ""; public bool GCSamplerV2Enabled => true; + + public string FleetId => "FleetId"; + public string HealthDeliveryLocation => "file:///tmp/health"; + public int HealthFrequency => 5; } } diff --git a/tests/Agent/UnitTests/Core.UnitTest/Errors/ErrorServiceTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Errors/ErrorServiceTests.cs index 310879020b..3d24267def 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Errors/ErrorServiceTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Errors/ErrorServiceTests.cs @@ -13,6 +13,7 @@ using NewRelic.Agent.Core.SharedInterfaces.Web; using NUnit.Framework; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Errors { @@ -32,7 +33,7 @@ private class ExceptionWithTypeParameter : Exception [SetUp] public void SetUp() { - _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); + _configurationService = new ConfigurationService(Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create(), Mock.Create()); _errorService = new ErrorService(_configurationService); _customAttributes = new Dictionary() { { "custom.key", "custom.value" } }; diff --git a/tests/Agent/UnitTests/Core.UnitTest/Spans/SpanEventMakerTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Spans/SpanEventMakerTests.cs index 0fd6e1e378..57e2928678 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Spans/SpanEventMakerTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Spans/SpanEventMakerTests.cs @@ -29,6 +29,7 @@ using NewRelic.Testing.Assertions; using NUnit.Framework; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Spans.UnitTest { @@ -101,7 +102,7 @@ public class SpanEventMakerTests private ServerConfiguration _serverConfig; private IBootstrapConfiguration _bootstrapConfiguration; private configuration _localConfig; - + private IAgentHealthReporter _agentHealthReporter; private void SetLocalConfigurationDefaults() { @@ -123,7 +124,7 @@ private void SetLocalConfigurationDefaults() private void PublishConfig() { - var config = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + var config = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); _config = config; EventBus.Publish(new ConfigurationUpdatedEvent(_config, ConfigurationUpdateSource.Local)); } @@ -138,7 +139,7 @@ public void SetUp() _dnsStatic = Mock.Create(); _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _bootstrapConfiguration = Mock.Create(); - + _agentHealthReporter = Mock.Create(); _runTimeConfiguration = new RunTimeConfiguration(); _serverConfig = new ServerConfiguration(); diff --git a/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs b/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs index 3baf1bad11..a28a77ed06 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Transformers/TransactionTransformer/TransactionAttributeMakerTests.cs @@ -31,6 +31,7 @@ using System.Collections.ObjectModel; using System.Linq; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Transformers.TransactionTransformer.UnitTest { @@ -57,12 +58,13 @@ public class TransactionAttributeMakerTests private IProcessStatic _processStatic; private IConfigurationManagerStatic _configurationManagerStatic; private IDnsStatic _dnsStatic; + private IAgentHealthReporter _agentHealthReporter; private ConfigurationAutoResponder _configAutoResponder; private void UpdateConfiguration() { - _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic); + _configuration = new TestableDefaultConfiguration(_environment, _localConfig, _serverConfig, _runTimeConfiguration, _securityPoliciesConfiguration, _bootstrapConfiguration, _processStatic, _httpRuntimeStatic, _configurationManagerStatic, _dnsStatic, _agentHealthReporter); Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); EventBus.Publish(new ConfigurationUpdatedEvent(_configuration, ConfigurationUpdateSource.Local)); } @@ -78,7 +80,7 @@ public void SetUp() _securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); _configurationService = Mock.Create(); _bootstrapConfiguration = Mock.Create(); - + _agentHealthReporter = Mock.Create(); _runTimeConfiguration = new RunTimeConfiguration(); _serverConfig = new ServerConfiguration(); _localConfig = new configuration(); @@ -1669,8 +1671,9 @@ public object HostDisplayName_WithLocalConfigurationAndEnvironmentVariableSet(st var securityPoliciesConfiguration = new SecurityPoliciesConfiguration(); var dnsStatic = Mock.Create(); var bootstrapConfiguration = Mock.Create(); + var agentHealthReporter = Mock.Create(); - _configuration = new TestableDefaultConfiguration(environment, localConfig, serverConfig, runTimeConfig, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic); + _configuration = new TestableDefaultConfiguration(environment, localConfig, serverConfig, runTimeConfig, securityPoliciesConfiguration, bootstrapConfiguration, processStatic, httpRuntimeStatic, configurationManagerStatic, dnsStatic, agentHealthReporter); Mock.Arrange(() => _configurationService.Configuration).Returns(_configuration); Mock.Arrange(() => dnsStatic.GetHostName()).Returns("coconut"); diff --git a/tests/Agent/UnitTests/Core.UnitTest/Wrapper/AgentWrapperApi/Builders/DatabaseStatementParserTest.cs b/tests/Agent/UnitTests/Core.UnitTest/Wrapper/AgentWrapperApi/Builders/DatabaseStatementParserTest.cs index e0d0f3c412..6a47ea88f9 100644 --- a/tests/Agent/UnitTests/Core.UnitTest/Wrapper/AgentWrapperApi/Builders/DatabaseStatementParserTest.cs +++ b/tests/Agent/UnitTests/Core.UnitTest/Wrapper/AgentWrapperApi/Builders/DatabaseStatementParserTest.cs @@ -12,6 +12,7 @@ using System.Data; using System.Threading; using Telerik.JustMock; +using NewRelic.Agent.Core.AgentHealth; namespace NewRelic.Agent.Core.Wrapper.AgentWrapperApi.Builders { @@ -88,7 +89,8 @@ public void CacheCapacity_ChangesApplied() Mock.Create(), Mock.Create(), Mock.Create(), - Mock.Create()); + Mock.Create(), + Mock.Create()); const string sql1 = "select * from table1"; const string sql2 = "select * from table2";