Skip to content

Commit

Permalink
[Valkey] Replace Redis with Valkey (#1619)
Browse files Browse the repository at this point in the history
* replace redis with valkey

* changelog

---------

Co-authored-by: Mikko Viitanen <74129181+mviitane@users.noreply.github.com>
  • Loading branch information
julianocosta89 and mviitane authored Jun 21, 2024
1 parent d335b8d commit 11ef3c6
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ JAEGERTRACING_IMAGE=jaegertracing/all-in-one:1.57
OPENSEARCH_IMAGE=opensearchproject/opensearch:2.14.0
POSTGRES_IMAGE=postgres:16.3
PROMETHEUS_IMAGE=quay.io/prometheus/prometheus:v2.52.0
REDIS_IMAGE=redis:7.2-alpine
VALKEY_IMAGE=valkey/valkey:7.2-alpine
# must also update the version arg in ./test/tracetesting/Dockerfile
TRACETEST_IMAGE=kubeshop/tracetest:v1.3.0

Expand Down Expand Up @@ -129,9 +129,9 @@ FLAGD_PORT=8013
KAFKA_SERVICE_PORT=9092
KAFKA_SERVICE_ADDR=kafka:${KAFKA_SERVICE_PORT}

# Redis
REDIS_PORT=6379
REDIS_ADDR=redis-cart:${REDIS_PORT}
# Valkey
VALKEY_PORT=6379
VALKEY_ADDR=valkey-cart:${VALKEY_PORT}

# ********************
# Telemetry Components
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ the release.

* [cartservice] bump .NET package to 1.9.0 release
([#1610](https://github.com/open-telemetry/opentelemetry-demo/pull/1610))
* [Valkey] Replace Redis with Valkey
([#1619](https://github.com/open-telemetry/opentelemetry-demo/pull/1619))

## 1.10.0

Expand Down
16 changes: 8 additions & 8 deletions docker-compose.minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ services:
environment:
- CART_SERVICE_PORT
- FLAGD_HOST
- REDIS_ADDR
- VALKEY_ADDR
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=cartservice
- ASPNETCORE_URLS=http://*:${CART_SERVICE_PORT}
depends_on:
redis-cart:
valkey-cart:
condition: service_started
otelcol:
condition: service_started
Expand Down Expand Up @@ -515,18 +515,18 @@ services:
logging:
*logging

# Redis used by Cart service
redis-cart:
image: ${REDIS_IMAGE}
container_name: redis-cart
user: redis
# Valkey used by Cart service
valkey-cart:
image: ${VALKEY_IMAGE}
container_name: valkey-cart
user: valkey
deploy:
resources:
limits:
memory: 20M
restart: unless-stopped
ports:
- "${REDIS_PORT}"
- "${VALKEY_PORT}"
logging: *logging


Expand Down
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ services:
- CART_SERVICE_PORT
- FLAGD_HOST
- FLAGD_PORT
- REDIS_ADDR
- VALKEY_ADDR
- OTEL_EXPORTER_OTLP_ENDPOINT
- OTEL_RESOURCE_ATTRIBUTES
- OTEL_SERVICE_NAME=cartservice
- ASPNETCORE_URLS=http://*:${CART_SERVICE_PORT}
depends_on:
redis-cart:
valkey-cart:
condition: service_started
otelcol:
condition: service_started
Expand Down Expand Up @@ -625,18 +625,18 @@ services:
retries: 10
logging: *logging

# Redis used by Cart service
redis-cart:
image: ${REDIS_IMAGE}
container_name: redis-cart
user: redis
# Valkey used by Cart service
valkey-cart:
image: ${VALKEY_IMAGE}
container_name: valkey-cart
user: valkey
deploy:
resources:
limits:
memory: 20M
restart: unless-stopped
ports:
- "${REDIS_PORT}"
- "${VALKEY_PORT}"
logging: *logging


Expand Down
2 changes: 1 addition & 1 deletion src/cartservice/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cart Service

This service stores user shopping carts in Redis.
This service stores user shopping carts in Valkey.

## Local Build

Expand Down
14 changes: 7 additions & 7 deletions src/cartservice/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
using OpenFeature.Contrib.Hooks.Otel;

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

Expand All @@ -33,7 +33,7 @@

builder.Services.AddSingleton<ICartStore>(x=>
{
var store = new RedisCartStore(x.GetRequiredService<ILogger<RedisCartStore>>(), redisAddress);
var store = new ValkeyCartStore(x.GetRequiredService<ILogger<ValkeyCartStore>>(), valkeyAddress);
store.Initialize();
return store;
});
Expand All @@ -48,7 +48,7 @@
builder.Services.AddSingleton(x =>
new CartService(
x.GetRequiredService<ICartStore>(),
new RedisCartStore(x.GetRequiredService<ILogger<RedisCartStore>>(), "badhost:1234"),
new ValkeyCartStore(x.GetRequiredService<ILogger<ValkeyCartStore>>(), "badhost:1234"),
x.GetRequiredService<IFeatureClient>()
));

Expand Down Expand Up @@ -79,8 +79,8 @@

var app = builder.Build();

var redisCartStore = (RedisCartStore) app.Services.GetRequiredService<ICartStore>();
app.Services.GetRequiredService<StackExchangeRedisInstrumentation>().AddConnection(redisCartStore.GetConnection());
var ValkeyCartStore = (ValkeyCartStore) app.Services.GetRequiredService<ICartStore>();
app.Services.GetRequiredService<StackExchangeRedisInstrumentation>().AddConnection(ValkeyCartStore.GetConnection());

app.MapGrpcService<CartService>();
app.MapGrpcHealthChecksService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace cartservice.cartstore;

public class RedisCartStore : ICartStore
public class ValkeyCartStore : ICartStore
{
private readonly ILogger _logger;
private const string CartFieldName = "cart";
Expand All @@ -25,13 +25,13 @@ public class RedisCartStore : ICartStore

private readonly ConfigurationOptions _redisConnectionOptions;

public RedisCartStore(ILogger<RedisCartStore> logger, string redisAddress)
public ValkeyCartStore(ILogger<ValkeyCartStore> logger, string valkeyAddress)
{
_logger = logger;
// Serialize empty cart into byte array.
var cart = new Oteldemo.Cart();
_emptyCartBytes = cart.ToByteArray();
_connectionString = $"{redisAddress},ssl=false,allowAdmin=true,abortConnect=false";
_connectionString = $"{valkeyAddress},ssl=false,allowAdmin=true,abortConnect=false";

_redisConnectionOptions = ConfigurationOptions.Parse(_connectionString);

Expand Down
3 changes: 2 additions & 1 deletion src/otelcollector/otelcol-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ receivers:
targets:
- endpoint: http://frontendproxy:${env:ENVOY_PORT}
redis:
endpoint: "redis-cart:6379"
endpoint: "valkey-cart:6379"
username: "valkey"
collection_interval: 10s

exporters:
Expand Down

0 comments on commit 11ef3c6

Please sign in to comment.