Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
chigia001 authored Jul 5, 2023
2 parents 8b68bad + 3c5bd95 commit ee61ea7
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 363 deletions.
114 changes: 114 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"schedule": "every weekend",
"packageRules": [
{
"matchPaths": ["*"],
"ignorePaths": ["src/"],
"groupName": "config-no-service"
},
{
"matchPaths": ["src/accountingservice"],
"groupName": "accountingservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/adservice"],
"groupName": "adservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/cartservice"],
"groupName": "cartservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/checkoutservice"],
"groupName": "checkoutservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/currencyservice"],
"groupName": "currencyservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/emailservice"],
"groupName": "emailservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/featureflagservice"],
"groupName": "featureflagservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/frauddetectionservice"],
"groupName": "frauddetectionservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/frontend"],
"groupName": "frontend",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/frontendproxy"],
"groupName": "frontendproxy",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/grafana"],
"groupName": "grafana",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/kakfa"],
"groupName": "kakfa",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/loadgenerator"],
"groupName": "loadgenerator",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/otelcollector"],
"groupName": "otelcollector",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/paymentservice"],
"groupName": "paymentservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/productcatalogservice"],
"groupName": "productcatalogservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/prometheus"],
"groupName": "prometheus",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/quoteservice"],
"groupName": "quoteservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/recommendationservice"],
"groupName": "recommendationservice",
"assigneesFromCodeOwners": true
},
{
"matchPaths": ["src/shippingservice"],
"groupName": "shippingservice",
"assigneesFromCodeOwners": true
}
]
}
7 changes: 3 additions & 4 deletions src/cartservice/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@

var builder = WebApplication.CreateBuilder(args);
string redisAddress = builder.Configuration["REDIS_ADDR"];
RedisCartStore cartStore = null;
if (string.IsNullOrEmpty(redisAddress))
{
Console.WriteLine("REDIS_ADDR environment variable is required.");
Environment.Exit(1);
}
cartStore = new RedisCartStore(redisAddress);
var cartStore = new RedisCartStore(redisAddress);

// Initialize the redis store
await cartStore.InitializeAsync();
Expand All @@ -41,15 +40,15 @@

builder.Services.AddOpenTelemetry()
.ConfigureResource(appResourceBuilder)
.WithTracing(builder => builder
.WithTracing(tracerBuilder => tracerBuilder
.AddRedisInstrumentation(
cartStore.GetConnection(),
options => options.SetVerboseDatabaseStatements = true)
.AddAspNetCoreInstrumentation()
.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation()
.AddOtlpExporter())
.WithMetrics(builder => builder
.WithMetrics(meterBuilder => meterBuilder
.AddRuntimeInstrumentation()
.AddAspNetCoreInstrumentation()
.AddOtlpExporter());
Expand Down
17 changes: 8 additions & 9 deletions src/cartservice/src/cartstore/ICartStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
// SPDX-License-Identifier: Apache-2.0
using System.Threading.Tasks;

namespace cartservice.cartstore
namespace cartservice.cartstore;

public interface ICartStore
{
public interface ICartStore
{
Task InitializeAsync();
Task InitializeAsync();

Task AddItemAsync(string userId, string productId, int quantity);
Task EmptyCartAsync(string userId);
Task AddItemAsync(string userId, string productId, int quantity);
Task EmptyCartAsync(string userId);

Task<Oteldemo.Cart> GetCartAsync(string userId);
Task<Oteldemo.Cart> GetCartAsync(string userId);

bool Ping();
}
bool Ping();
}
85 changes: 41 additions & 44 deletions src/cartservice/src/cartstore/LocalCartStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@
using System.Linq;
using System.Threading.Tasks;

namespace cartservice.cartstore
namespace cartservice.cartstore;

internal class LocalCartStore : ICartStore
{
internal class LocalCartStore : ICartStore
{
// Maps between user and their cart
private ConcurrentDictionary<string, Oteldemo.Cart> userCartItems = new ConcurrentDictionary<string, Oteldemo.Cart>();
private readonly Oteldemo.Cart emptyCart = new Oteldemo.Cart();
// Maps between user and their cart
private readonly ConcurrentDictionary<string, Oteldemo.Cart> _userCartItems = new();
private readonly Oteldemo.Cart _emptyCart = new();

public Task InitializeAsync()
{
Console.WriteLine("Local Cart Store was initialized");
public Task InitializeAsync()
{
Console.WriteLine("Local Cart Store was initialized");

return Task.CompletedTask;
}
return Task.CompletedTask;
}

public Task AddItemAsync(string userId, string productId, int quantity)
public Task AddItemAsync(string userId, string productId, int quantity)
{
Console.WriteLine($"AddItemAsync called with userId={userId}, productId={productId}, quantity={quantity}");
var newCart = new Oteldemo.Cart
{
Console.WriteLine($"AddItemAsync called with userId={userId}, productId={productId}, quantity={quantity}");
var newCart = new Oteldemo.Cart
{
UserId = userId,
Items = { new Oteldemo.CartItem { ProductId = productId, Quantity = quantity } }
};
userCartItems.AddOrUpdate(userId, newCart,
(k, exVal) =>
UserId = userId,
Items = { new Oteldemo.CartItem { ProductId = productId, Quantity = quantity } }
};
_userCartItems.AddOrUpdate(userId, newCart,
(_, exVal) =>
{
// If the item exists, we update its quantity
var existingItem = exVal.Items.SingleOrDefault(item => item.ProductId == productId);
Expand All @@ -46,35 +46,32 @@ public Task AddItemAsync(string userId, string productId, int quantity)
return exVal;
});

return Task.CompletedTask;
}
return Task.CompletedTask;
}

public Task EmptyCartAsync(string userId)
{
var eventTags = new ActivityTagsCollection();
eventTags.Add("userId", userId);
Activity.Current?.AddEvent(new ActivityEvent("EmptyCartAsync called.", default, eventTags));
public Task EmptyCartAsync(string userId)
{
var eventTags = new ActivityTagsCollection {{"userId", userId}};
Activity.Current?.AddEvent(new ActivityEvent("EmptyCartAsync called.", default, eventTags));

userCartItems[userId] = new Oteldemo.Cart();
return Task.CompletedTask;
}
_userCartItems[userId] = new Oteldemo.Cart();
return Task.CompletedTask;
}

public Task<Oteldemo.Cart> GetCartAsync(string userId)
public Task<Oteldemo.Cart> GetCartAsync(string userId)
{
Console.WriteLine($"GetCartAsync called with userId={userId}");
if (!_userCartItems.TryGetValue(userId, out var cart))
{
Console.WriteLine($"GetCartAsync called with userId={userId}");
Oteldemo.Cart cart = null;
if (!userCartItems.TryGetValue(userId, out cart))
{
Console.WriteLine($"No carts for user {userId}");
return Task.FromResult(emptyCart);
}

return Task.FromResult(cart);
Console.WriteLine($"No carts for user {userId}");
return Task.FromResult(_emptyCart);
}

public bool Ping()
{
return true;
}
return Task.FromResult(cart);
}

public bool Ping()
{
return true;
}
}
Loading

0 comments on commit ee61ea7

Please sign in to comment.