in src/Service/HealthCheck/HealthCheckHelper.cs [210:269]
private void PopulateEntityHealth(ComprehensiveHealthCheckReport ComprehensiveHealthCheckReport, KeyValuePair<string, Entity> entity, RuntimeConfig runtimeConfig)
{
// Global Rest and GraphQL Runtime Options
RuntimeOptions? runtimeOptions = runtimeConfig.Runtime;
string entityKeyName = entity.Key;
// Entity Health Check and Runtime Options
Entity entityValue = entity.Value;
if (runtimeOptions != null && entityValue != null)
{
if (runtimeOptions.IsRestEnabled && entityValue.IsRestEnabled)
{
ComprehensiveHealthCheckReport.Checks ??= new List<HealthCheckResultEntry>();
// In case of REST API, use the path specified in [entity.path] (if present).
// The path is trimmed to remove the leading '/' character.
// If the path is not present, use the entity key name as the path.
string entityPath = entityValue.Rest.Path != null ? entityValue.Rest.Path.TrimStart('/') : entityKeyName;
(int, string?) response = ExecuteRestEntityQuery(runtimeConfig.RestPath, entityPath, entityValue.EntityFirst);
bool isResponseTimeWithinThreshold = response.Item1 >= 0 && response.Item1 < entityValue.EntityThresholdMs;
// Add Entity Health Check Results
ComprehensiveHealthCheckReport.Checks.Add(new HealthCheckResultEntry
{
Name = entityKeyName,
ResponseTimeData = new ResponseTimeData
{
ResponseTimeMs = response.Item1,
ThresholdMs = entityValue.EntityThresholdMs
},
Tags = [HealthCheckConstants.REST, HealthCheckConstants.ENDPOINT],
Exception = response.Item2 ?? (!isResponseTimeWithinThreshold ? TIME_EXCEEDED_ERROR_MESSAGE : null),
Status = isResponseTimeWithinThreshold ? HealthStatus.Healthy : HealthStatus.Unhealthy
});
}
if (runtimeOptions.IsGraphQLEnabled && entityValue.IsGraphQLEnabled)
{
ComprehensiveHealthCheckReport.Checks ??= new List<HealthCheckResultEntry>();
(int, string?) response = ExecuteGraphQLEntityQuery(runtimeConfig.GraphQLPath, entityValue, entityKeyName);
bool isResponseTimeWithinThreshold = response.Item1 >= 0 && response.Item1 < entityValue.EntityThresholdMs;
ComprehensiveHealthCheckReport.Checks.Add(new HealthCheckResultEntry
{
Name = entityKeyName,
ResponseTimeData = new ResponseTimeData
{
ResponseTimeMs = response.Item1,
ThresholdMs = entityValue.EntityThresholdMs
},
Tags = [HealthCheckConstants.GRAPHQL, HealthCheckConstants.ENDPOINT],
Exception = response.Item2 ?? (!isResponseTimeWithinThreshold ? TIME_EXCEEDED_ERROR_MESSAGE : null),
Status = isResponseTimeWithinThreshold ? HealthStatus.Healthy : HealthStatus.Unhealthy
});
}
}
}