Skip to content

Commit

Permalink
drop duplicated status in health check details
Browse files Browse the repository at this point in the history
  • Loading branch information
TimHess committed Jan 25, 2025
1 parent 6cffbc0 commit 80a3801
Show file tree
Hide file tree
Showing 11 changed files with 1 addition and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public CosmosDbHealthContributor(string serviceName, IServiceProvider servicePro
await task.WaitAsync(Timeout, cancellationToken);

result.Status = HealthStatus.Up;
result.Details.Add("status", HealthStatus.Up.ToSnakeCaseString(SnakeCaseStyle.AllCaps));

_logger.LogTrace("{DbConnection} at {Host} is up!", Id, Host);
}
Expand All @@ -82,7 +81,6 @@ public CosmosDbHealthContributor(string serviceName, IServiceProvider servicePro
result.Status = HealthStatus.Down;
result.Description = $"{Id} health check failed";
result.Details.Add("error", $"{exception.GetType().Name}: {exception.Message}");
result.Details.Add("status", HealthStatus.Down.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public MongoDbHealthContributor(string serviceName, IServiceProvider serviceProv
using IDisposable cursor = await _mongoClientShim.ListDatabaseNamesAsync(cancellationToken);

result.Status = HealthStatus.Up;
result.Details.Add("status", HealthStatus.Up.ToSnakeCaseString(SnakeCaseStyle.AllCaps));

_logger.LogTrace("{DbConnection} at {Host} is up!", Id, Host);
}
Expand All @@ -77,7 +76,6 @@ public MongoDbHealthContributor(string serviceName, IServiceProvider serviceProv
result.Status = HealthStatus.Down;
result.Description = $"{Id} health check failed";
result.Details.Add("error", $"{exception.GetType().Name}: {exception.Message}");
result.Details.Add("status", HealthStatus.Down.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public RabbitMQHealthContributor(object connectionFactory, string host, ILogger<
}

result.Status = HealthStatus.Up;
result.Details.Add("status", HealthStatus.Up.ToSnakeCaseString(SnakeCaseStyle.AllCaps));

_logger.LogTrace("{DbConnection} at {Host} is up!", Id, Host);
}
Expand All @@ -86,7 +85,6 @@ public RabbitMQHealthContributor(object connectionFactory, string host, ILogger<
result.Status = HealthStatus.Down;
result.Description = $"{Id} health check failed";
result.Details.Add("error", $"{exception.GetType().Name}: {exception.Message}");
result.Details.Add("status", HealthStatus.Down.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
}

return Task.FromResult<HealthCheckResult?>(result);
Expand Down
2 changes: 0 additions & 2 deletions src/Connectors/src/Connectors/Redis/RedisHealthContributor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ internal void SetConnectionMultiplexer(object connectionMultiplexer)
TimeSpan roundTripTime = await _databaseInterfaceShim.PingAsync();

result.Status = HealthStatus.Up;
result.Details.Add("status", HealthStatus.Up.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
result.Details.Add("ping", roundTripTime.TotalMilliseconds);

_logger.LogTrace("{DbConnection} at {Host} is up!", Id, Host);
Expand All @@ -98,7 +97,6 @@ internal void SetConnectionMultiplexer(object connectionMultiplexer)
result.Status = HealthStatus.Down;
result.Description = $"{Id} health check failed";
result.Details.Add("error", $"{exception.GetType().Name}: {exception.Message}");
result.Details.Add("status", HealthStatus.Down.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public RelationalDatabaseHealthContributor(DbConnection connection, string? host
await command.ExecuteScalarAsync(cancellationToken);

result.Status = HealthStatus.Up;
result.Details.Add("status", HealthStatus.Up.ToSnakeCaseString(SnakeCaseStyle.AllCaps));

_logger.LogTrace("{DbConnection} at {Host} is up!", Id, Host);
}
Expand All @@ -74,7 +73,6 @@ public RelationalDatabaseHealthContributor(DbConnection connection, string? host
result.Status = HealthStatus.Down;
result.Description = $"{Id} health check failed";
result.Details.Add("error", $"{exception.GetType().Name}: {exception.Message}");
result.Details.Add("status", HealthStatus.Down.ToSnakeCaseString(SnakeCaseStyle.AllCaps));
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public async Task Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", serviceName);
result.Details.Should().Contain("error", "HttpRequestException: No connection could be made because ...");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand All @@ -71,7 +70,6 @@ public async Task Not_Connected_With_Timeout_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", serviceName);
result.Details.Should().Contain("error", "TimeoutException: The operation has timed out.");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand All @@ -94,7 +92,6 @@ public async Task Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand Down Expand Up @@ -146,7 +143,6 @@ public async Task Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

private static ServiceProvider CreateServiceProvider(string serviceName, string connectionString, CosmosClient cosmosClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public async Task Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().ContainKey("error").WhoseValue.As<string>().Should().StartWith("TimeoutException: A timeout occurred after 1ms selecting ");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand All @@ -62,7 +61,6 @@ public async Task Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand Down Expand Up @@ -116,7 +114,6 @@ public async Task Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

private ServiceProvider CreateServiceProvider(string serviceName, string connectionString, IMongoClient mongoClient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public async Task Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().Contain("error", "BrokerUnreachableException: None of the specified endpoints were reachable");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand Down Expand Up @@ -64,7 +63,6 @@ public async Task Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
result.Details.Should().Contain("version", "1.2.3");
}

Expand Down Expand Up @@ -100,7 +98,6 @@ public async Task Lost_Connection_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().Contain("error", "IOException: RabbitMQ connection is closed!");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand Down Expand Up @@ -137,7 +134,6 @@ public async Task Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
result.Details.Should().ContainKey("version");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public async Task Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().ContainKey("error").WhoseValue.As<string>().Should().StartWith("RedisConnectionException: It was not possible to connect ");
result.Details.Should().Contain("status", "DOWN");
}

[Fact]
Expand Down Expand Up @@ -64,7 +63,6 @@ public async Task Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
result.Details.Should().Contain("ping", 50D);
}

Expand Down Expand Up @@ -98,7 +96,6 @@ public async Task Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
result.Details.Should().ContainKey("ping");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public async Task PostgreSQL_Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().ContainKey("error").WhoseValue.As<string>().Should().Match("NpgsqlException: Failed to connect to *:9999");
result.Details.Should().Contain("status", "DOWN");
}

[Fact(Skip = "Integration test - Requires local PostgreSQL server")]
Expand All @@ -53,7 +52,6 @@ public async Task PostgreSQL_Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand All @@ -74,7 +72,6 @@ public async Task MySQL_Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().ContainKey("error").WhoseValue.As<string>().Should().StartWith("MySqlException: ");
result.Details.Should().Contain("status", "DOWN");
}

[Fact(Skip = "Integration test - Requires local MySQL server")]
Expand All @@ -94,7 +91,6 @@ public async Task MySQL_Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand All @@ -116,7 +112,6 @@ public async Task SQLServer_Not_Connected_Returns_Down_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().ContainKey("error").WhoseValue.As<string>().Should().StartWith("SqlException: Connection Timeout Expired.");
result.Details.Should().Contain("status", "DOWN");
}

[Fact(Skip = "Integration test - Requires local SQL Server instance")]
Expand All @@ -136,7 +131,6 @@ public async Task SQLServer_Integration_Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand All @@ -162,7 +156,6 @@ public async Task Is_Connected_Returns_Up_Status()
result.Details.Should().Contain("host", "localhost");
result.Details.Should().Contain("service", "Example");
result.Details.Should().NotContainKey("error");
result.Details.Should().Contain("status", "UP");
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// See the LICENSE file in the project root for more information.

using Microsoft.Extensions.Options;
using Steeltoe.Common.CasingConventions;
using Steeltoe.Common.HealthChecks;

namespace Steeltoe.Management.Endpoint.Actuators.Health.Contributors;
Expand Down Expand Up @@ -70,8 +69,7 @@ public DiskSpaceContributor(IOptionsMonitor<DiskSpaceContributorOptions> options
Description = "Failed to determine free disk space.",
Details =
{
["error"] = "The configured path is invalid or does not exist.",
["status"] = HealthStatus.Unknown.ToSnakeCaseString(SnakeCaseStyle.AllCaps)
["error"] = "The configured path is invalid or does not exist."
}
};
}
Expand Down

0 comments on commit 80a3801

Please sign in to comment.