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

MM-57214: Integrate Redis into Terraform deployment #708

Merged
merged 8 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
6 changes: 6 additions & 0 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
"RestoreTimeoutMinutes": 45,
"ClusterTimeoutMinutes": 45
},
"RedisSettings": {
"Enabled": false,
"NodeType": "cache.m7g.2xlarge",
"ParameterGroupName": "default.redis7",
"EngineVersion": "7.1"
},
"JobServerSettings":{
"InstanceCount": 0,
"InstanceType": "c7i.xlarge"
Expand Down
12 changes: 12 additions & 0 deletions deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type Config struct {
// the deployment process.
LoadTestDownloadURL string `default:"https://github.com/mattermost/mattermost-load-test-ng/releases/download/v1.19.0/mattermost-load-test-ng-v1.19.0-linux-amd64.tar.gz" validate:"url"`
ElasticSearchSettings ElasticSearchSettings
RedisSettings RedisSettings
JobServerSettings JobServerSettings
LogSettings logger.Settings
Report report.Config
Expand Down Expand Up @@ -249,6 +250,17 @@ type ElasticSearchSettings struct {
ClusterTimeoutMinutes int `default:"45" validate:"range:[0,)"`
}

type RedisSettings struct {
// Enabled indicates whether to add Redis or not.
Enabled bool
// NodeType indicates the instance type.
NodeType string `default:"cache.m7g.2xlarge"`
// ParameterGroupName indicates the parameter group to attach.
ParameterGroupName string `default:"default.redis7"`
// EngineVersion indicates the engine version.
EngineVersion string `default:"7.1"`
}

// JobServerSettings contains the necessary data to deploy a job
// server.
type JobServerSettings struct {
Expand Down
41 changes: 32 additions & 9 deletions deployment/terraform/assets/bindata.go

Large diffs are not rendered by default.

33 changes: 32 additions & 1 deletion deployment/terraform/assets/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ resource "aws_instance" "app_server" {
"sudo apt-get install -y mysql-client-8.0",
"sudo apt-get install -y postgresql-client-14",
"sudo apt-get install -y prometheus-node-exporter",
# "sudo NEEDRESTART_MODE=a apt-get install -y redis-tools",
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the deal with this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is needed to install the redis-cli. But the thing is there is an UI intervention while installing, which is supposedly fixed with NEEDRESTART_MODE=a. But that still somehow didn't fix things. So just ignoring for now. If someone needs to connect to Redis, they can install manually.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, the command worked fine on my end (EC2 running Ubuntu 22.04).

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm .. weird. I will test it again later.

"sudo apt-get install -y numactl linux-tools-aws linux-tools-aws-lts-22.04"
]
}
Expand Down Expand Up @@ -129,7 +130,10 @@ resource "aws_instance" "metrics_server" {
"sudo dpkg -i inbucket_2.1.0_linux_amd64.deb",
"wget https://github.com/justwatchcom/elasticsearch_exporter/releases/download/v1.1.0/elasticsearch_exporter-1.1.0.linux-amd64.tar.gz",
"sudo mkdir /opt/elasticsearch_exporter",
"sudo tar -zxvf elasticsearch_exporter-1.1.0.linux-amd64.tar.gz -C /opt/elasticsearch_exporter --strip-components=1",
"sudo tar -zxf elasticsearch_exporter-1.1.0.linux-amd64.tar.gz -C /opt/elasticsearch_exporter --strip-components=1",
"wget https://github.com/oliver006/redis_exporter/releases/download/v1.58.0/redis_exporter-v1.58.0.linux-amd64.tar.gz",
"sudo mkdir /opt/redis_exporter",
"sudo tar -zxf redis_exporter-v1.58.0.linux-amd64.tar.gz -C /opt/redis_exporter --strip-components=1",
"sudo systemctl daemon-reload",
"sudo systemctl enable grafana-server",
"sudo service grafana-server start",
Expand Down Expand Up @@ -248,6 +252,19 @@ resource "aws_iam_user_policy" "s3userpolicy" {
EOF
}

resource "aws_elasticache_cluster" "redis_server" {
cluster_id = "${var.cluster_name}-redis"
engine = "redis"
node_type = "${var.redis_node_type}"
count = var.redis_enabled ? 1 : 0
num_cache_nodes = 1
parameter_group_name = "${var.redis_param_group_name}"
engine_version = "${var.redis_engine_version}"
port = 6379

security_group_ids = [aws_security_group.redis[0].id]
}

resource "aws_rds_cluster" "db_cluster" {
count = var.app_instance_count > 0 && var.db_instance_count > 0 && var.db_cluster_identifier == "" ? 1 : 0
cluster_identifier = var.db_cluster_identifier != "" ? "" : "${var.cluster_name}-db"
Expand Down Expand Up @@ -536,6 +553,20 @@ resource "aws_security_group_rule" "metrics-egress" {
security_group_id = aws_security_group.metrics[0].id
}

resource "aws_security_group" "redis" {
name = "${var.cluster_name}-redis-security-group"
description = "Security group for redis instance"

ingress {
from_port = 6379
to_port = 6379
protocol = "tcp"
security_groups = [aws_security_group.app[0].id, aws_security_group.metrics[0].id]
}

count = 1
}

resource "aws_security_group" "elastic" {
name = "${var.cluster_name}-elastic-security-group"
description = "Security group for elastic instance"
Expand Down
4 changes: 4 additions & 0 deletions deployment/terraform/assets/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ output "elasticRoleARN" {
value = aws_iam_role.es_role.arn
}

output "redisServer" {
value = aws_elasticache_cluster.redis_server
}

output "s3bucket" {
value = aws_s3_bucket.s3bucket
}
Expand Down
Loading
Loading