Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public AgentHealthReporter(IMetricBuilder metricBuilder, IScheduler scheduler, I
_customInstrumentationCounter = new InterlockedCounter();

if (_configuration.AgentControlEnabled)
{
_healthCheck = new() { IsHealthy = true, Status = "Agent starting", LastError = string.Empty };
}
}

public override void Dispose()
Expand Down Expand Up @@ -840,7 +842,7 @@ public void PublishAgentControlHealthCheck()
return;
}

var healthCheckYaml = _healthCheck.ToYaml();
var healthCheckYaml = _healthCheck.ToYaml(_configuration.EntityGuid);

Log.Finest("Publishing Agent Control health check report: {HealthCheckYaml}", healthCheckYaml);

Expand Down
4 changes: 2 additions & 2 deletions src/Agent/NewRelic/Agent/Core/AgentHealth/HealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public void TrySetHealth((bool IsHealthy, string Code, string Status) healthStat
}
}

public string ToYaml()
public string ToYaml(string entityGuid)
{
lock (this)
{
return
$"healthy: {IsHealthy}\nstatus: {Status}\nlast_error: {LastError}\nstart_time_unix_nano: {StartTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}\nstatus_time_unix_nano: {StatusTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}";
$"entity_guid: {entityGuid}\nhealthy: {IsHealthy}\nstatus: {Status}\nlast_error: {LastError}\nstart_time_unix_nano: {StartTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}\nstatus_time_unix_nano: {StatusTime.ToUnixTimeMilliseconds() * NanoSecondsPerMillisecond}";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ public void ToYaml_ReturnsCorrectYamlString()
var healthStatus = (IsHealthy: true, Code: "200", Status: "OK");
_healthCheck.TrySetHealth(healthStatus);

var yaml = _healthCheck.ToYaml();
var yaml = _healthCheck.ToYaml("someEntityGuid");

Assert.Multiple(() =>
{
Assert.That(yaml, Does.Contain("entity_guid: someEntityGuid"));
Assert.That(yaml, Does.Contain("healthy: True"));
Assert.That(yaml, Does.Contain("status: OK"));
Assert.That(yaml, Does.Contain("last_error: 200"));
Expand Down Expand Up @@ -172,10 +173,11 @@ public void TrySetHealth_HandlesFalseIsHealthy()
[Test]
public void ToYaml_HandlesNullValues()
{
var yaml = _healthCheck.ToYaml();
var yaml = _healthCheck.ToYaml(null);

Assert.Multiple(() =>
{
Assert.That(yaml, Does.Match(@"entity_guid:\s\n"));
Assert.That(yaml, Does.Match(@"healthy:\sFalse"));
Assert.That(yaml, Does.Match(@"status:\s\n"));
Assert.That(yaml, Does.Match(@"last_error:\s\n"));
Expand Down
Loading