Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis updates #161

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions docs/redis.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
# Migrating Redis database from Heroku infrastructure
# Migrating Redis databases

**General considerations:**
There are two templates examples in this repo:
- `redis` - basic non-persistent template. It is good for review-apps or staging or where no persistence is required
- `redis2` - basic persistent template. Good for production where persistence is needed, but cluster is overkill.

Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List items should be surrounded by blank lines for better readability.

+ 
There are two templates examples in this repo:
- `redis` - basic non-persistent template. It is good for review-apps or staging or where no persistence is required
- `redis2` - basic persistent template. Good for production where persistence is needed, but cluster is overkill.
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
There are two templates examples in this repo:
- `redis` - basic non-persistent template. It is good for review-apps or staging or where no persistence is required
- `redis2` - basic persistent template. Good for production where persistence is needed, but cluster is overkill.
There are two templates examples in this repo:
- `redis` - basic non-persistent template. It is good for review-apps or staging or where no persistence is required
- `redis2` - basic persistent template. Good for production where persistence is needed, but cluster is overkill.

## Option 1: use SLAVEOF (easier way)

1. create a redis workload that will accept data
2. execute `SLAVEOF source_host source_port`, if needed use `masterauth` to provide auth details
3. wait for replication to pick up all changes (usually quickly), use `INFO` or `DBSIZE` to check progress
4. stop app completely and ensure nothing is writing to any of redises
5. execute `SLAVEOF no one` to disconnect replication
6. switch `REDIS_URL` in the app to point to new server
7. start the app

## Option 2: use Redis-RIOT (harder way, where option 1 is not possible)

### General considerations:

1. Heroku uses self-signed TLS certificates, which are not verifiable. It needs special handling by setting
TLS verification to `none`, otherwise most apps are not able to connect.
TLS verification to `none`; otherwise, most apps cannot connect.

justin808 marked this conversation as resolved.
Show resolved Hide resolved
2. We are moving to private Redis that don't have a public URL, so have to do it from a Control Plane GVC container.

The tool that satisfies those criteria is [Redis-RIOT](https://developer.redis.com/riot/riot-redis/index.html)

**Heroku Redis:**
### Heroku Redis:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure code blocks are surrounded by blank lines for proper formatting.

+ 
### Heroku Redis:
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Heroku Redis:
### Heroku Redis:

As Redis-RIOT says, master redis should have keyspace-notifications set to `KA` to be able to do live replication.
To do that:
Expand All @@ -23,7 +39,7 @@ Connect to heroku Redis CLI:
heroku redis:cli -a my-app
```

**Control Plane Redis:**
### Control Plane Redis:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure code blocks are surrounded by blank lines for proper formatting.

+ 
### Control Plane Redis:
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Control Plane Redis:
### Control Plane Redis:

Connect to Control Plane Redis CLI:

Expand All @@ -36,10 +52,10 @@ apt-get update
apt-get install redis -y

# connect to local cloud Redis
redis-cli -u MY_CONTROL_PLANE_REDIS_URL
redis-cli -u MY_CONTROL_PLANE_REDIS_URL -p 6379
```
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify the language for the code block to enhance syntax highlighting.

+ ```bash
55~
redis-cli -u MY_CONTROL_PLANE_REDIS_URL -p 6379
56~
+ ```


**Useful Redis CLI commands:**
### Useful Redis CLI commands:

Quick-check keys qty:
```
Expand All @@ -49,7 +65,7 @@ info keyspace
db0:keys=9496,expires=2941,avg_ttl=77670114535
```

**Create a Control Plane sync workload**
### Create a Control Plane sync workload

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure code blocks are surrounded by blank lines for proper formatting.

+ 
### Create a Control Plane sync workload
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Create a Control Plane sync workload
### Create a Control Plane sync workload

```
name: riot-redis
Expand All @@ -76,7 +92,7 @@ command args:
live
```

**Sync process**
### Sync process

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure code blocks are surrounded by blank lines for proper formatting.

+ 
### Sync process
+ 

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
### Sync process

Sync process


</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

1. open 1st terminal window with heroku redis CLI, check keys qty
2. open 2nd terminal window with controlplane redis CLI, check keys qty
Expand Down
6 changes: 3 additions & 3 deletions templates/memcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ spec:
type: standard
containers:
- name: memcached
cpu: 3m
memory: 10Mi
cpu: 25m
memory: 32Mi
args:
- "-l"
- 0.0.0.0
Expand All @@ -15,7 +15,7 @@ spec:
protocol: tcp
defaultOptions:
autoscaling:
metric: latency
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
Expand Down
2 changes: 1 addition & 1 deletion templates/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
uri: "scratch://postgres-vol"
defaultOptions:
autoscaling:
metric: latency
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
Expand Down
6 changes: 3 additions & 3 deletions templates/redis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ spec:
type: standard
containers:
- name: redis
cpu: 3m
memory: 20Mi
cpu: 25m
memory: 32Mi
image: "redis:latest"
ports:
- number: 6379
protocol: tcp
defaultOptions:
autoscaling:
metric: latency
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
Expand Down
37 changes: 37 additions & 0 deletions templates/redis2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
kind: volumeset
name: redis-data
spec:
fileSystemType: ext4
initialCapacity: 10
performanceClass: general-purpose-ssd
---
kind: workload
name: redis2
spec:
type: stateful
containers:
- name: redis
args:
- '--appendonly'
- 'yes'
- '--maxmemory'
- 25mb
cpu: 25m
memory: 32Mi
image: "redis:latest"
ports:
- number: 6379
protocol: tcp
volumes:
- path: /data
recoveryPolicy: retain
uri: cpln://volumeset/redis-data
defaultOptions:
autoscaling:
metric: disabled
minScale: 1
maxScale: 1
capacityAI: false
firewallConfig:
internal:
inboundAllowType: same-gvc
Loading