fix(health): check the active storage provider
Heimdall Gitea / Build and tests (pull_request) Successful in 15m57s
Heimdall Gitea / Publish versioned release (pull_request) Skipped
Heimdall Gitea / Build and scan server image (pull_request) Successful in 7m56s
Heimdall Gitea / Build and scan agent image (pull_request) Successful in 9m9s
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped

This commit is contained in:
Arnaud Dartois committed 2026-10-24 21:47:40 +02:00
1 parent cc6cbeccf5
commit 2d2e5bc211
7 files changed
+73 -51

No files matched your search

@@ -194,12 +194,20 @@ public sealed class AlarikStorageProvider : IStorageProvider, IDisposable
return false;
try
{
await _client.ListBucketsAsync(ct).ConfigureAwait(false);
await _client.ListObjectsV2Async(new ListObjectsV2Request
{
BucketName = _bucket,
MaxKeys = 1,
}, ct).ConfigureAwait(false);
return true;
}
catch (OperationCanceledException) when (ct.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Alarik/S3 health check failed");
_logger.LogWarning(ex, "S3 storage bucket health check failed");
return false;
}
}
@@ -195,19 +195,29 @@ public sealed class LocalStorageProvider : IStorageProvider
sorted.Length > pageSize ? objects[^1].Key : null));
}
public Task<bool> HealthCheckAsync(CancellationToken ct = default)
public async Task<bool> HealthCheckAsync(CancellationToken ct = default)
{
try
{
EnsureNoLinks(_root);
Directory.CreateDirectory(_root);
EnsureNoLinks(_root);
return Task.FromResult(true);
var probePath = Path.Combine(_root, $".heimdall-health-{Guid.NewGuid():N}.tmp");
await using var probe = new FileStream(probePath, FileMode.CreateNew, FileAccess.Write,
FileShare.None, bufferSize: 1, FileOptions.Asynchronous | FileOptions.DeleteOnClose);
await probe.WriteAsync(new byte[] { 0 }.AsMemory(), ct).ConfigureAwait(false);
await probe.FlushAsync(ct).ConfigureAwait(false);
return true;
}
catch (OperationCanceledException) when (ct.IsCancellationRequested)
{
throw;
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Local storage health check failed");
return Task.FromResult(false);
return false;
}
}
}