Skip to content

Commit

Permalink
Cleanup & bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jan 24, 2025
1 parent a8b8f65 commit 2c27c4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
19 changes: 8 additions & 11 deletions src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,27 @@ public void TrySetHealth((bool IsHealthy, string Code, string Status) healthStat
IsHealthy = healthStatus.IsHealthy;
}

if (!Status.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(Status) || !Status.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase))
{
if (statusParams != null && statusParams.Length > 0)
{
Status = string.Format(Status, statusParams);
}
else
{
Status = healthStatus.Status;
}
Status = statusParams is { Length: > 0 } ?
string.Format(healthStatus.Status, statusParams)
:
healthStatus.Status;
}

if (!LastError.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(LastError) || !LastError.Equals(healthStatus.Code, StringComparison.OrdinalIgnoreCase))
{
LastError = healthStatus.Code;
}

StatusTime = DateTime.UtcNow;
}
}

public string ToYaml()
{
lock (this)
{
StatusTime = DateTime.UtcNow;
return
$"healthy: {IsHealthy}\nstatus: {Status}\nlast_error: {LastError}\nstart_time_unix_nano: {StartTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}\nstatus_time_unix_nano: {StatusTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}";
}
Expand Down
3 changes: 3 additions & 0 deletions src/Agent/NewRelic/Agent/Core/Config/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright 2020 New Relic, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

// ------------------------------------------------------------------------------
// <auto-generated>
// Generated by Xsd2Code. Version 3.6.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,9 @@ public virtual string AgentLicenseKey
_agentLicenseKey = _configurationManagerStatic.GetAppSetting(Constants.AppSettingsLicenseKey)
?? EnvironmentOverrides(_localConfiguration.service.licenseKey, "NEW_RELIC_LICENSE_KEY", "NEWRELIC_LICENSEKEY");

if (_agentLicenseKey != null)
_agentLicenseKey = _agentLicenseKey.Trim();
_agentLicenseKey = _agentLicenseKey?.Trim();

if (_agentLicenseKey == null && !ServerlessModeEnabled)
if (string.IsNullOrEmpty(_agentLicenseKey) && !ServerlessModeEnabled)
{
TrySetAgentControlStatus(HealthCodes.LicenseKeyMissing);
}
Expand Down

0 comments on commit 2c27c4d

Please sign in to comment.