Skip to content

Commit

Permalink
Move from redis to valkey
Browse files Browse the repository at this point in the history
Our code uses an Cache interface so we just need to implement another implementation of the cache interface for valkey.
  • Loading branch information
jcscottiii committed Oct 29, 2024
1 parent 0da9899 commit 094c368
Show file tree
Hide file tree
Showing 36 changed files with 152 additions and 136 deletions.
4 changes: 2 additions & 2 deletions .dev/redis/Dockerfile → .dev/valkey/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Ensure the version matches what GCP supports https://cloud.google.com/memorystore/docs/redis/supported-versions
FROM redis:7.2.5-alpine3.20
# Ensure the version matches what GCP supports https://cloud.google.com/memorystore/docs/valkey/supported-versions
FROM valkey/valkey:8.0.1-alpine3.20
10 changes: 5 additions & 5 deletions .dev/redis/manifests/pod.yaml → .dev/valkey/manifests/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
apiVersion: v1
kind: Pod
metadata:
name: redis
name: valkey
labels:
app.kubernetes.io/name: redis
app.kubernetes.io/name: valkey
spec:
containers:
- name: redis
image: redis
- name: valkey
image: valkey
imagePullPolicy: Never # Need this for pushing directly into minikube
ports:
- containerPort: 6379
name: redis-port
name: valkey-port
resources:
limits:
cpu: 250m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
apiVersion: v1
kind: Service
metadata:
name: redis
name: valkey
spec:
selector:
app.kubernetes.io/name: redis
app.kubernetes.io/name: valkey
ports:
- protocol: TCP
port: 6379
targetPort: redis-port
targetPort: valkey-port
4 changes: 2 additions & 2 deletions .dev/redis/skaffold.yaml → .dev/valkey/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
apiVersion: skaffold/v4beta9
kind: Config
metadata:
name: redis-config
name: valkey-config
profiles:
- name: local
build:
artifacts:
- image: redis
- image: valkey
context: .
local:
useBuildkit: true
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ updates:
interval: 'weekly'

- package-ecosystem: 'docker'
directory: '/.dev/redis'
directory: '/.dev/valkey'
schedule:
interval: 'weekly'

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The above skaffold command deploys multiple resources:
| frontend | Frontend service in ./frontend | http://localhost:5555 | http://frontend:5555 |
| datastore | Datastore Emulator | N/A | http://datastore:8086 |
| spanner | Spanner Emulator | N/A | spanner:9010 (grpc)<br />http://spanner:9020 (rest) |
| redis | Redis | N/A | redis:6379 |
| valkey | Valkey | N/A | valkey:6379 |
| gcs | Google Cloud Storage Emulator | N/A | http://gcs:4443 |
| auth | Auth Emulator | http://localhost:9099<br />http://localhost:9100/auth (ui) | http://auth:9099<br />http://auth:9100/auth (ui) |

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ test: go-test node-test

# Clean up any dangling test containers
clean-up-go-testcontainers:
docker rm -f webstatus-dev-test-redis webstatus-dev-test-datastore webstatus-dev-test-spanner
docker rm -f webstatus-dev-test-valkey webstatus-dev-test-datastore webstatus-dev-test-spanner
# TODO. We run the tests sequentially with `-p 1` because the testcontainers
# do not play nicely together when running in parallel and take a long time to
# reconcile state. Once the testcontainers library becomes stable (goes v1.0.0),
Expand Down
14 changes: 7 additions & 7 deletions backend/cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"github.com/GoogleChrome/webstatus.dev/lib/gds/datastoreadapters"
"github.com/GoogleChrome/webstatus.dev/lib/httpmiddlewares"
"github.com/GoogleChrome/webstatus.dev/lib/opentelemetry"
"github.com/GoogleChrome/webstatus.dev/lib/rediscache"
"github.com/GoogleChrome/webstatus.dev/lib/valkeycache"
"github.com/go-chi/cors"
)

Expand Down Expand Up @@ -65,8 +65,8 @@ func main() {
// Allowed Origin. Can remove after UbP.
allowedOrigin := os.Getenv("CORS_ALLOWED_ORIGIN")

redisHost := os.Getenv("REDISHOST")
redisPort := os.Getenv("REDISPORT")
valkeyHost := os.Getenv("VALKEYHOST")
valkeyPort := os.Getenv("VALKEYPORT")

cacheDuration := os.Getenv("CACHE_TTL")
duration, err := time.ParseDuration(cacheDuration)
Expand All @@ -89,15 +89,15 @@ func main() {
cacheKeyPrefix := cmp.Or[string](os.Getenv("K_REVISION"), "test-revision")
slog.Info("cache settings", "duration", duration, "prefix", cacheKeyPrefix, "connections", connections)

cache, err := rediscache.NewRedisDataCache[string, []byte](
cache, err := valkeycache.NewValkeyDataCache[string, []byte](
cacheKeyPrefix,
redisHost,
redisPort,
valkeyHost,
valkeyPort,
duration,
connections,
)
if err != nil {
slog.Error("unable to create redis cache instance", "error", err)
slog.Error("unable to create valkey cache instance", "error", err)
os.Exit(1)
}
middlewares := []func(http.Handler) http.Handler{
Expand Down
1 change: 1 addition & 0 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ require (
github.com/prometheus/common v0.60.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/valkey-io/valkey-go v1.0.48 // indirect
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/bridges/prometheus v0.56.0 // indirect
Expand Down
4 changes: 4 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -1044,6 +1046,8 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/valkey-io/valkey-go v1.0.48 h1:FSkZbS8X852icAWDfsBinQe0kUGO9+p/9Qj7bgRNHTw=
github.com/valkey-io/valkey-go v1.0.48/go.mod h1:BXlVAPIL9rFQinSFM+N32JfWzfCaUAqBpZkc4vPY6fM=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd h1:doiVMUpXpmXP9Bmki9S5xBqOyn6S5//Itx/WkeiEDIA=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd/go.mod h1:hFjMfLPC8Iky81NPD+J1WdVmWHE+Cnd7brr/GjYWs/M=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
6 changes: 3 additions & 3 deletions backend/manifests/pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ spec:
value: 'datastore:8086'
- name: CORS_ALLOWED_ORIGIN
value: 'http://*'
- name: REDISHOST
value: redis
- name: REDISPORT
- name: VALKEYHOST
value: valkey
- name: VALKEYPORT
value: '6379'
- name: CACHE_TTL
value: 5m # Short TTL locally
Expand Down
2 changes: 1 addition & 1 deletion backend/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ metadata:
requires:
- path: ../.dev/auth
- path: ../.dev/datastore
- path: ../.dev/redis
- path: ../.dev/valkey
- path: ../.dev/spanner
profiles:
- name: local
Expand Down
8 changes: 4 additions & 4 deletions infra/backend/service.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ resource "google_cloud_run_v2_service" "service" {
value = var.cors_allowed_origin
}
env {
name = "REDISHOST"
value = var.redis_env_vars[each.key].host
name = "VALKEYHOST"
value = var.valkey_env_vars[each.key].host
}
env {
name = "REDISPORT"
value = var.redis_env_vars[each.key].port
name = "VALKEYPORT"
value = var.valkey_env_vars[each.key].port
}
env {
name = "CACHE_TTL"
Expand Down
4 changes: 2 additions & 2 deletions infra/backend/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ variable "projects" {
})
}

variable "redis_env_vars" {
variable "valkey_env_vars" {
type = map(object({
host = string
port = number
}))
description = "Map of Redis host and port per region"
description = "Map of Valkey host and port per region"
}

variable "cache_duration" {
Expand Down
2 changes: 1 addition & 1 deletion infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module "backend" {
custom_ssl_certificates = var.custom_ssl_certificates_for_backend
projects = var.projects
cache_duration = var.cache_duration
redis_env_vars = module.storage.redis_env_vars
valkey_env_vars = module.storage.valkey_env_vars
cors_allowed_origin = var.backend_cors_allowed_origin
min_instance_count = var.backend_min_instance_count
max_instance_count = var.backend_max_instance_count
Expand Down
2 changes: 1 addition & 1 deletion infra/network/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ resource "google_project_iam_member" "internal_network_user" {
member = "serviceAccount:service-${data.google_project.internal.number}@serverless-robot-prod.iam.gserviceaccount.com"
}

# Allocate address space for Google Managed Services (e.g. Redis) to use and communicate
# Allocate address space for Google Managed Services (e.g. Valkey) to use and communicate
# to our resources in our project.
resource "google_compute_global_address" "private_ip_address" {
name = "${var.env_id}-private-service-access-ip"
Expand Down
4 changes: 2 additions & 2 deletions infra/services/internal_project_services.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ resource "google_project_service" "internal_scheduler" {
disable_on_destroy = false
}

resource "google_project_service" "internal_redis" {
resource "google_project_service" "internal_memorystore" {
provider = google.internal_project
service = "redis.googleapis.com"
service = "memorystore.googleapis.com"

disable_dependent_services = true
disable_on_destroy = false
Expand Down
6 changes: 3 additions & 3 deletions infra/storage/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ output "buckets" {
}
}

output "redis_env_vars" {
output "valkey_env_vars" {
value = {
for region, _ in var.region_to_subnet_info_map :
region => {
host = google_redis_instance.redis_instances[region].host
port = google_redis_instance.redis_instances[region].port
host = google_memorystore_instance.valkey_instance[region].host
port = google_memorystore_instance.valkey_instance[region].port
}
}
}
25 changes: 0 additions & 25 deletions infra/storage/redis.tf

This file was deleted.

37 changes: 37 additions & 0 deletions infra/storage/valkey.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

resource "google_network_connectivity_service_connection_policy" "valkey_policy" {
for_each = var.region_to_subnet_info_map
name = "${var.env_id}-${each.key}-valkey-policy"
location = each.key
service_class = "gcp-memorystore"
description = "${var.env_id} service connection policy for ${each.key}"
network = google_compute_network.producer_net.id
psc_config {
subnetworks = [google_compute_subnetwork.producer_subnet.id]
}
}

resource "google_memorystore_instance" "valkey_instance" {
for_each = var.region_to_subnet_info_map
instance_id = "${var.env_id}-valkey-${each.key}"
shard_count = 2
desired_psc_auto_connections {
network = var.vpc_id
project_id = data.google_project.project.project_id
}
location = each.key
depends_on = [google_network_connectivity_service_connection_policy.valkey_policy]
}
5 changes: 3 additions & 2 deletions lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ require (
github.com/google/go-github/v60 v60.0.0
github.com/oapi-codegen/runtime v1.1.1
github.com/testcontainers/testcontainers-go v0.31.0
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd
github.com/valkey-io/valkey-go v1.0.48
github.com/web-platform-tests/wpt.fyi v0.0.0-20241029135702-72e945910908
go.opentelemetry.io/contrib/detectors/gcp v1.31.0
google.golang.org/api v0.203.0
google.golang.org/grpc v1.67.1
Expand All @@ -34,6 +35,7 @@ require (
github.com/getkin/kin-openapi v0.128.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/gomodule/redigo v1.9.2 // indirect
github.com/google/go-github/v65 v65.0.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down Expand Up @@ -85,7 +87,6 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/gomodule/redigo v1.9.2
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/s2a-go v0.1.8 // indirect
github.com/google/uuid v1.6.0
Expand Down
8 changes: 6 additions & 2 deletions lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k=
github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -1059,8 +1061,10 @@ github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+F
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd h1:doiVMUpXpmXP9Bmki9S5xBqOyn6S5//Itx/WkeiEDIA=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241028124407-3e70c0607edd/go.mod h1:hFjMfLPC8Iky81NPD+J1WdVmWHE+Cnd7brr/GjYWs/M=
github.com/valkey-io/valkey-go v1.0.48 h1:FSkZbS8X852icAWDfsBinQe0kUGO9+p/9Qj7bgRNHTw=
github.com/valkey-io/valkey-go v1.0.48/go.mod h1:BXlVAPIL9rFQinSFM+N32JfWzfCaUAqBpZkc4vPY6fM=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241029135702-72e945910908 h1:pkpM14RWLCNJWUVhWt5eHKVNRt4Vf5oQqx+2DQcOOlc=
github.com/web-platform-tests/wpt.fyi v0.0.0-20241029135702-72e945910908/go.mod h1:zrVUpyI1HjThN3jO+QqIiD0PRNXXtOfZIsxUziMtWkY=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
Loading

0 comments on commit 094c368

Please sign in to comment.