Skip to content

Commit d5ced24

Browse files
committed
adding quickstart
1 parent beb0ddb commit d5ced24

20 files changed

+1029
-69
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ out
4343
.project
4444
.classpath
4545
build
46+
*.terraform
47+
.gradle
Binary file not shown.

.gradle/file-system.probe

0 Bytes
Binary file not shown.

.tfvars.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ redis_cloud_account_key = "REDIS_CLOUD_ACCOUNT_KEY"
55
redis_cloud_api_key = "REDIS_CLOUD_API_KEY"
66
sub_name = "NAME_FOR_YOUR_SUBSCRIPTION"
77
db_name = "NAME_FOR_YOUR_DATABASE"
8-
last_four_digits="LAST_FOUR_DIGITS_OF_YOUR_CREDIT_CARD"
8+
last_four_digits="LAST_FOUR_DIGITS_OF_YOUR_CREDIT_CARD"
9+
gcloud_username="GCLOUD_USERNAME"
10+
gcloud_region = "GCLOUD_REGION"
11+
gcloud_zone = "GCLOUD_ZONE"
12+
ssh_key_file="ssh_key_file"

main.tf

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ provider "rediscloud" {
1515

1616
provider "google" {
1717
project = var.gcp_project
18-
region = "us-east1"
18+
region = var.gcloud_region
1919
}
2020

2121

@@ -26,7 +26,7 @@ resource "google_compute_network" "autoscale_test_vpc" {
2626

2727
resource "google_compute_subnetwork" "autoscale_test_subnet" {
2828
name = "autoscale-test-subnet"
29-
region = "us-east1"
29+
region = var.gcloud_region
3030
ip_cidr_range = "10.0.0.0/24"
3131
network = google_compute_network.autoscale_test_vpc.id
3232
private_ip_google_access = true
@@ -97,7 +97,7 @@ resource "rediscloud_subscription" "autoscaling_sub" {
9797
cloud_provider {
9898
provider = "GCP"
9999
region {
100-
region = "us-east1"
100+
region = var.gcloud_region
101101
multiple_availability_zones = false
102102
networking_deployment_cidr = "10.0.1.0/24"
103103
}
@@ -145,24 +145,6 @@ resource "rediscloud_subscription_database" "autoscale-database" {
145145
]
146146
}
147147

148-
#data "rediscloud_subscription" "autoscale-sub" {
149-
# name = var.sub_name
150-
#}
151-
152-
#data "rediscloud_database" "autoscale-db" {
153-
# subscription_id = rediscloud_subscription.autoscaling_sub.id
154-
# name = "autoscale-database"
155-
#}
156-
#
157-
#data "google_compute_network" "autoscale_test_vpc" {
158-
# name="autoscale-test-vpc"
159-
#}
160-
161-
#data "google_compute_subnetwork" "autoscale_test_subnet" {
162-
# name = "autoscale-test-subnet"
163-
# region = "us-east1"
164-
#}
165-
166148
# Extract the hostname portion of the private_endpoint
167149
locals {
168150
private_endpoint_host = join("", slice(split(":", rediscloud_subscription_database.autoscale-database.private_endpoint), 0, 1))
@@ -171,7 +153,7 @@ locals {
171153
resource "google_compute_instance" "autoscaler-vm"{
172154
name = "autoscaler-vm"
173155
machine_type = "n1-standard-1"
174-
zone = "us-east1-b"
156+
zone = var.gcloud_zone
175157
boot_disk {
176158
initialize_params {
177159
image = "ubuntu-2004-focal-v20240731"
@@ -181,8 +163,6 @@ resource "google_compute_instance" "autoscaler-vm"{
181163

182164
network_interface {
183165
network = google_compute_network.autoscale_test_vpc.id
184-
# network = data.google_compute_network.autoscale_test_vpc.id
185-
# subnetwork = data.google_compute_subnetwork.autoscale_test_subnet.id
186166
subnetwork = google_compute_subnetwork.autoscale_test_subnet.id
187167
access_config {
188168
}
@@ -203,7 +183,7 @@ resource "null_resource" "build_app" {
203183
}
204184

205185
provisioner "file" {
206-
source = "./autoscaler/redis-cloud-autoscaler/build/libs/redis-cloud-autoscaler-0.0.2.jar"
186+
source = "./autoscaler/redis-cloud-autoscaler/build/libs/redis-cloud-autoscaler.jar"
207187
destination = "autoscaler.jar"
208188
}
209189

@@ -232,7 +212,7 @@ resource "null_resource" "build_app" {
232212
"echo 'Environment=REDIS_PASSWORD=${rediscloud_subscription_database.autoscale-database.password}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
233213
"echo 'Environment=REDIS_CLOUD_API_KEY=${var.redis_cloud_api_key}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
234214
"echo 'Environment=REDIS_CLOUD_ACCOUNT_KEY=${var.redis_cloud_account_key}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
235-
"echo 'Environment=REDIS_CLOUD_SUBSCRIPTION_ID=${rediscloud_subscription.autoscaling_sub.id}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
215+
"echo 'Environment=REDIS_CLOUD_SUBSCRIPTION_ID=${rediscloud_subscription_database.autoscale-database.id}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
236216
"echo 'Environment=ALERT_MANAGER_HOST=${google_compute_instance.autoscale-vm-prometheus.network_interface[0].access_config[0].nat_ip}' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
237217
"echo 'Environment=ALERT_MANAGER_PORT=9093' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
238218
"echo 'ExecStart=/usr/bin/java -jar /usr/local/bin/autoscaler.jar' | sudo tee -a /etc/systemd/system/autoscaler.service > /dev/null",
@@ -265,7 +245,7 @@ resource "google_dns_record_set" "autoscaler_dns" {
265245
resource "google_compute_instance" "autoscale-vm-prometheus" {
266246
name = "autoscale-vm-prometheus"
267247
machine_type = "n1-standard-1"
268-
zone = "us-east1-b"
248+
zone = var.gcloud_zone
269249
boot_disk {
270250
initialize_params {
271251
image = "ubuntu-2004-focal-v20240731"
@@ -442,4 +422,4 @@ resource "google_dns_record_set" "autoscale_prometheus_dns" {
442422
type = "A"
443423
ttl = 300
444424
rrdatas = [google_compute_instance.autoscale-vm-prometheus.network_interface[0].access_config[0].nat_ip]
445-
}
425+
}

quickstart/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Redis Cloud Autoscaler Quickstart
2+
3+
## Purpose
4+
5+
This is a quickstart guide for the Redis Cloud Autoscaler. It will show you how you can deploy the Redis Cloud Autoscaler alongside your Redis Cloud subscription.
6+
7+
## Configure Environment
8+
9+
Inside of the `gcp` folder you will find the `.tfvars.example` file. This file contains the environment variables that you need to set before you start the Redis Cloud Autoscaler. You can create a copy of this file called `.tfvars` and fill out the variables.
10+
11+
### Spinning up the Redis Cloud Autoscaler with terraform in GCP
12+
13+
To spin up the Redis Cloud Autoscaler with terraform in GCP, you can cd into the `gcp` folder and run the following command: `terraform init && terraform apply --var-file=.tfvars`. This will start the Redis Cloud Autoscaler in detached mode. and enter `yes` when prompted to apply the changes.
14+
15+
### Create some Rules
16+
17+
You can open the postman collection in the `postman` folder to create some rules for the Redis Cloud Autoscaler.
18+
19+
#### Configure Postman
20+
21+
1. In Postman import the `autoscaler.postman_collection.json` file in the `postman` folder.
22+
2. In Postman import the `autoscaler.postman_environment.json` file in the `postman` folder.
23+
3. Open the `autoscaler` environment.
24+
4. Update the `base_url` to the base URL of the Redis Cloud Autoscaler.
25+
7. Update the `db_id` to the ID of the database you want to scale.
26+
27+
#### Create a Rule
28+
29+
In Postman, open the Throughput rules or Memory rules collection.
30+
31+
1. Click on the `IncreaseThroughputDeterministic` or `IncreaseMemoryDeterministic` request.
32+
2. Click on the `Body` tab.
33+
3. Update the `scale_value` to the value you want to scale to (in ops/sec).
34+
4. Click on the `Send` button.
35+
36+
You should see a 200 status code.

quickstart/docker-compose.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

quickstart/.env.example renamed to quickstart/docker/.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ REDIS_CLOUD_API_KEY=
44
REDIS_CLOUD_ACCOUNT_KEY=
55
REDIS_CLOUD_SUBSCRIPTION_ID=
66
ALERT_MANAGER_HOST=
7-
ALERT_MANAGER_PORT=
7+
ALERT_MANAGER_PORT=
8+
REDIS_CLOUD_INTERNAL_ENDPOINT=
9+
REDIS_CLOUD_AUTOSCALER_HOST=

quickstart/docker/docker-compose.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
services:
2+
autoscaler:
3+
image: ghcr.io/redis-field-engineering/redis-cloud-autoscaler:latest
4+
container_name: autoscaler
5+
env_file:
6+
- .env
7+
ports:
8+
- 8080:8080
9+
alertmanager:
10+
image: prom/alertmanager:latest
11+
container_name: alertmanager
12+
links:
13+
- autoscaler
14+
env_file:
15+
- .env
16+
volumes:
17+
- ./prometheus/alertmanager.yml:/etc/alertmanager/alertmanager.yml
18+
ports:
19+
- 9093:9093
20+
command:
21+
- '--config.file=/etc/alertmanager/alertmanager.yml'
22+
prometheus:
23+
image: prom/prometheus
24+
container_name: prometheus
25+
links:
26+
- alertmanager
27+
env_file:
28+
- .env
29+
volumes:
30+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
31+
- ./prometheus/alert.rules:/etc/prometheus/alert.rules
32+
- ./prometheus/alertmanager.yml:/etc/prometheus/alertmanager.yml
33+
command:
34+
- '--config.file=/etc/prometheus/prometheus.yml'
35+
ports:
36+
- 9090:9090
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
groups:
2+
- name: RedisAlerts
3+
rules:
4+
- alert: IncreaseMemory
5+
expr: sum by (instance, db) (redis_server_used_memory) / sum by (instance, db) (redis_server_maxmemory) * 100 > 80
6+
for: 1m
7+
labels:
8+
severity: warning
9+
annotations:
10+
summary: "High Redis Memory Usage"
11+
description: "Redis memory usage is high"
12+
- alert: DecreaseMemory
13+
expr: sum by (instance, db) (redis_server_used_memory) / sum by (instance, db) (redis_server_maxmemory) * 100 < 20
14+
for: 1m
15+
labels:
16+
severity: warning
17+
annotations:
18+
summary: "Low Redis Memory Usage"
19+
description: "Redis memory usage is low"
20+
- alert: IncreaseThroughput
21+
expr: sum by (db, instance) (irate(endpoint_write_requests[1m]) + irate(endpoint_read_requests[1m])) / on(db) group_left() redis_db_configured_throughput * 100 > 80
22+
for: 1m
23+
labels:
24+
severity: warning
25+
annotations:
26+
summary: "High Redis Throughput"
27+
description: "Redis throughput is high"
28+
- alert: DecreaseThroughput
29+
expr: sum by (db, instance) (irate(endpoint_write_requests[1m]) + irate(endpoint_read_requests[1m])) / on(db) group_left() redis_db_configured_throughput * 100 < 20
30+
for: 1m
31+
labels:
32+
severity: warning
33+
annotations:
34+
summary: "Low Redis Throughput"
35+
description: "Redis throughput is low"

quickstart/prometheus/prometheus.yml renamed to quickstart/docker/prometheus/prometheus.template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ alerting:
88
- static_configs:
99
- targets:
1010
# Alertmanager's default port is 9093
11-
- localhost:9093
11+
- alertmanager:9093
1212

1313
scrape_configs:
1414
- job_name: 'prometheus'

quickstart/gcp/.terraform.lock.hcl

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

quickstart/gcp/.tfvars.example

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
gcp_project = "YOUR_GCP_PROJECT_ID"
2+
dns-zone-name="DNS_ZONE_NAME"
3+
subdomain="FULLY_QUALIFIED_DNS_SUBDOMAIN"
4+
redis_cloud_account_key = "REDIS_CLOUD_ACCOUNT_KEY"
5+
redis_cloud_api_key = "REDIS_CLOUD_API_KEY"
6+
sub_name = "NAME_FOR_YOUR_SUBSCRIPTION"
7+
db_name = "NAME_FOR_YOUR_DATABASE"
8+
last_four_digits="LAST_FOUR_DIGITS_OF_YOUR_CREDIT_CARD"
9+
gcloud_username="YOUR_GCLOUD_USERNAME"
10+
gcloud_region = "GCLOUD_REGION"
11+
gcloud_zone = "GCLOUD_ZONE"
12+
ssh_key_file="ssh_key_file"

0 commit comments

Comments
 (0)