Skip to content

Commit

Permalink
[cartservice] Increases health check timeout (#240)
Browse files Browse the repository at this point in the history
* Increases cartservice health check rpc timeout

* remove stopwatch from health check

* cleanup

* Cleanup
  • Loading branch information
askmeegs committed Aug 19, 2019
1 parent 13b7306 commit 156dfce
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions release/kubernetes-manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,12 @@ spec:
readinessProbe:
initialDelaySeconds: 15
exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"]
command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
livenessProbe:
initialDelaySeconds: 15
periodSeconds: 10
exec:
command: ["/bin/grpc_health_probe", "-addr=:7070"]
command: ["/bin/grpc_health_probe", "-addr=:7070", "-rpc-timeout=5s"]
---
apiVersion: v1
kind: Service
Expand Down
1 change: 0 additions & 1 deletion src/cartservice/HealthImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public HealthImpl (ICartStore dependency) {

public override Task<HealthCheckResponse> Check(HealthCheckRequest request, ServerCallContext context){
Console.WriteLine ("Checking CartService Health");

return Task.FromResult(new HealthCheckResponse {
Status = dependency.Ping() ? HealthCheckResponse.Types.ServingStatus.Serving : HealthCheckResponse.Types.ServingStatus.NotServing
});
Expand Down
2 changes: 1 addition & 1 deletion src/cartservice/cartservice.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="grpc.tools" Version="1.12.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
<PackageReference Include="StackExchange.Redis" Version="2.0.601" />
</ItemGroup>

<ItemGroup>
Expand Down
21 changes: 10 additions & 11 deletions src/cartservice/cartstore/RedisCartStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public RedisCartStore(string redisAddress)
var cart = new Hipstershop.Cart();
emptyCartBytes = cart.ToByteArray();
connectionString = $"{redisAddress},ssl=false,allowAdmin=true,connectRetry=5";

redisConnectionOptions = ConfigurationOptions.Parse(connectionString);

// Try to reconnect if first retry failed (up to 5 times with exponential backoff)
redisConnectionOptions.ConnectRetry = REDIS_RETRY_NUM;
redisConnectionOptions.ReconnectRetryPolicy = new ExponentialRetry(100);

redisConnectionOptions.KeepAlive = 180;
}

Expand All @@ -78,11 +78,11 @@ private void EnsureRedisConnected()

Console.WriteLine("Connecting to Redis: " + connectionString);
redis = ConnectionMultiplexer.Connect(redisConnectionOptions);

if (redis == null || !redis.IsConnected)
{
Console.WriteLine("Wasn't able to connect to redis");

// We weren't able to connect to redis despite 5 retries with exponential backoff
throw new ApplicationException("Wasn't able to connect to redis");
}
Expand All @@ -96,14 +96,14 @@ private void EnsureRedisConnected()
Console.WriteLine($"Small test result: {res}");

redis.InternalError += (o, e) => { Console.WriteLine(e.Exception); };
redis.ConnectionRestored += (o, e) =>
redis.ConnectionRestored += (o, e) =>
{
isRedisConnectionOpened = true;
Console.WriteLine("Connection to redis was retored successfully");
Console.WriteLine("Connection to redis was retored successfully");
};
redis.ConnectionFailed += (o, e) =>
redis.ConnectionFailed += (o, e) =>
{
Console.WriteLine("Connection failed. Disposing the object");
Console.WriteLine("Connection failed. Disposing the object");
isRedisConnectionOpened = false;
};

Expand All @@ -118,9 +118,9 @@ public async Task AddItemAsync(string userId, string productId, int quantity)
try
{
EnsureRedisConnected();

var db = redis.GetDatabase();

// Access the cart from the cache
var value = await db.HashGetAsync(userId, CART_FIELD_NAME);

Expand Down Expand Up @@ -202,7 +202,6 @@ public bool Ping()
{
try
{
var redis = ConnectionMultiplexer.Connect(redisConnectionOptions);
var cache = redis.GetDatabase();
var res = cache.Ping();
return res != TimeSpan.Zero;
Expand Down

0 comments on commit 156dfce

Please sign in to comment.