Skip to content

Commit

Permalink
Log k8s server response for HttpOeprationException (#65)
Browse files Browse the repository at this point in the history
Co-authored-by: Timm Hoffmeister <hoffmeistert@bluelizard.org.uk>
  • Loading branch information
vader1986 and Timm Hoffmeister authored Mar 2, 2023
1 parent 72e8973 commit 5133298
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using k8s.Autorest;

namespace Orleans.Clustering.Kubernetes.Extensions;

public static class HttpOperationExceptionExtensions
{
public static string GetServerResponse(this HttpOperationException exception)
{
try
{
return exception.Response.Content;
}
catch
{
return null;
}
}
}
16 changes: 11 additions & 5 deletions src/Orleans.Clustering.Kubernetes/KubeMembershipTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using k8s;
using k8s.Models;
using k8s.Autorest;
using Orleans.Clustering.Kubernetes.Extensions;

namespace Orleans.Clustering.Kubernetes;

Expand Down Expand Up @@ -136,8 +137,7 @@ public async Task<bool> InsertRow(MembershipEntry entry, TableVersion tableVersi
}
catch (Exception exc)
{
this._logger?.LogError(exc, "Unable to insert Silo Entry");

_logger?.LogError(exc, "Unable to insert Silo Entry");
throw;
}
}
Expand Down Expand Up @@ -359,7 +359,7 @@ private async Task TryInitClusterVersion()

try
{
version = ((JsonElement) await this._kubeClient.GetNamespacedCustomObjectAsync(
version = ((JsonElement)await this._kubeClient.GetNamespacedCustomObjectAsync(
Constants.ORLEANS_GROUP,
Constants.PROVIDER_MODEL_VERSION,
this._namespace,
Expand Down Expand Up @@ -396,14 +396,20 @@ private async Task TryInitClusterVersion()

if (created != null)
{
this._logger?.LogInformation("Created new Cluster Version entity for Cluster {ClusterId}", this._clusterOptions.ClusterId);
this._logger?.LogInformation("Created new Cluster Version entity for Cluster {ClusterId}",
this._clusterOptions.ClusterId);
}
}
else
{
this._logger?.LogInformation("Cluster {ClusterId} already exists. Trying to join it", this._clusterOptions.ClusterId);
this._logger?.LogInformation("Cluster {ClusterId} already exists. Trying to join it",
this._clusterOptions.ClusterId);
}
}
catch (HttpOperationException exception)
{
this._logger?.LogWarning(exception, "Failed to initialize ClusterVersion: {details}", exception.GetServerResponse());
}
catch (Exception exc)
{
// TODO: Handle conflicts better when the schema is already deployed
Expand Down

0 comments on commit 5133298

Please sign in to comment.