Skip to content

Commit

Permalink
feat(bench): Add field to allow configuring custom redis memory limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarun Pratap Singh committed Dec 30, 2024
1 parent e6fe659 commit b3dc9ab
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 11 deletions.
2 changes: 1 addition & 1 deletion press/docker/config/redis-cache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dir /home/frappe/frappe-bench/config/pids
pidfile /home/frappe/frappe-bench/config/pids/redis-cache.pid
bind 127.0.0.1
port 13000
maxmemory 512mb
maxmemory {{ doc.redis_cache_size }}mb
maxmemory-policy allkeys-lru
appendonly no
save ""
Expand Down
1 change: 1 addition & 0 deletions press/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,4 @@ press.press.doctype.server.patches.set_plan_and_subscription
press.patches.v0_7_0.move_site_db_access_users_to_site_db_perm_manager
press.press.doctype.drip_email.patches.set_correct_field_for_html
press.patches.v0_7_0.set_label_for_site_database_user
press.press.doctype.press_settings.patches.set_redis_cache_size
10 changes: 9 additions & 1 deletion press/press/doctype/deploy_candidate/deploy_candidate.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"docker_image_tag",
"feature_flags_section",
"is_redisearch_enabled",
"redis_cache_size",
"use_app_cache",
"compress_app_cache",
"column_break_tkdd",
Expand Down Expand Up @@ -415,6 +416,13 @@
"fieldname": "no_cache",
"fieldtype": "Check",
"label": "No Cache"
},
{
"default": "512",
"fetch_from": "group.redis_cache_size",
"fieldname": "redis_cache_size",
"fieldtype": "Int",
"label": "Redis Cache Size (MB)"
}
],
"links": [
Expand All @@ -431,7 +439,7 @@
"link_fieldname": "document_name"
}
],
"modified": "2024-06-21 14:12:47.335402",
"modified": "2024-12-27 11:59:09.917364",
"modified_by": "Administrator",
"module": "Press",
"name": "Deploy Candidate",
Expand Down
1 change: 1 addition & 0 deletions press/press/doctype/deploy_candidate/deploy_candidate.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class DeployCandidate(Document):
pending_duration: DF.Time | None
pending_end: DF.Datetime | None
pending_start: DF.Datetime | None
redis_cache_size: DF.Int
retry_count: DF.Int
scheduled_time: DF.Datetime | None
status: DF.Literal["Draft", "Scheduled", "Pending", "Preparing", "Running", "Success", "Failure"]
Expand Down
11 changes: 11 additions & 0 deletions press/press/doctype/press_settings/patches/set_redis_cache_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import frappe
from frappe.core.utils import find


def execute():
frappe.reload_doctype("Press Settings")
settings = frappe.get_single("Press Settings")
if not settings.redis_cache_size:
redis_cache_size_field = find(settings.meta.fields, lambda x: x.fieldname == "redis_cache_size")
settings.redis_cache_size = redis_cache_size_field.default
settings.save()
18 changes: 12 additions & 6 deletions press/press/doctype/press_settings/press_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
"use_staging_ca",
"ssh_section",
"ssh_certificate_authority",
"bench_section",
"redis_cache_size",
"monitoring_section",
"monitor_server",
"monitor_token",
Expand All @@ -193,7 +195,6 @@
"column_break_rdlr",
"disable_auto_retry",
"disable_agent_job_deduplication",
"enable_email_pre_verification",
"section_break_jstu",
"enable_app_grouping",
"default_apps",
Expand Down Expand Up @@ -1268,15 +1269,20 @@
"options": "App Group"
},
{
"default": "0",
"fieldname": "enable_email_pre_verification",
"fieldtype": "Check",
"label": "Enable Email Pre-Verification"
"fieldname": "bench_section",
"fieldtype": "Section Break",
"label": "Bench"
},
{
"default": "512",
"fieldname": "redis_cache_size",
"fieldtype": "Int",
"label": "Redis Cache Size (MB)"
}
],
"issingle": 1,
"links": [],
"modified": "2024-12-10 15:07:57.494659",
"modified": "2024-12-27 11:44:09.454080",
"modified_by": "Administrator",
"module": "Press",
"name": "Press Settings",
Expand Down
2 changes: 1 addition & 1 deletion press/press/doctype/press_settings/press_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ class PressSettings(Document):
domain: DF.Link | None
eff_registration_email: DF.Data
enable_app_grouping: DF.Check
enable_email_pre_verification: DF.Check
enable_google_oauth: DF.Check
enable_site_pooling: DF.Check
enforce_storage_limits: DF.Check
Expand Down Expand Up @@ -115,6 +114,7 @@ class PressSettings(Document):
razorpay_key_secret: DF.Password | None
razorpay_webhook_secret: DF.Data | None
realtime_job_updates: DF.Check
redis_cache_size: DF.Int
remote_access_key_id: DF.Data | None
remote_link_expiry: DF.Int
remote_secret_access_key: DF.Password | None
Expand Down
9 changes: 8 additions & 1 deletion press/press/doctype/release_group/release_group.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"column_break_14",
"bench_config",
"gunicorn_threads_per_worker",
"redis_cache_size",
"automatic_worker_allocation_section",
"min_gunicorn_workers",
"min_background_workers",
Expand Down Expand Up @@ -367,10 +368,16 @@
"fieldtype": "Link",
"label": "Build Server",
"options": "Server"
},
{
"default": "512",
"fieldname": "redis_cache_size",
"fieldtype": "Int",
"label": "Redis Cache Size (MB)"
}
],
"links": [],
"modified": "2024-09-17 14:44:01.541194",
"modified": "2024-12-27 11:58:29.907938",
"modified_by": "Administrator",
"module": "Press",
"name": "Release Group",
Expand Down
10 changes: 9 additions & 1 deletion press/press/doctype/release_group/release_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class ReleaseGroup(Document, TagHelpers):
from press.press.doctype.release_group_variable.release_group_variable import (
ReleaseGroupVariable,
)
from press.press.doctype.resource_tag.resource_tag import ResourceTag
from press.press.doctype.resource_tag.resource_tag import (
ResourceTag,
)

apps: DF.Table[ReleaseGroupApp]
bench_config: DF.Code | None
Expand All @@ -111,6 +113,7 @@ class ReleaseGroup(Document, TagHelpers):
mounts: DF.Table[ReleaseGroupMount]
packages: DF.Table[ReleaseGroupPackage]
public: DF.Check
redis_cache_size: DF.Int
saas_app: DF.Link | None
saas_bench: DF.Check
servers: DF.Table[ReleaseGroupServer]
Expand Down Expand Up @@ -370,11 +373,16 @@ def update_config_in_release_group(self, common_site_config, bench_config):
else:
value = d.value
self.append("common_site_config_table", {"key": d.key, "value": value, "type": d.type})
# redis_cache_size is a field on release group but we want to treat it as config key
# TODO: add another interface for updating similar values
if d["key"] == "redis_cache_size":
self.redis_cache_size = int(d.value)

Check warning on line 379 in press/press/doctype/release_group/release_group.py

View check run for this annotation

Codecov / codecov/patch

press/press/doctype/release_group/release_group.py#L379

Added line #L379 was not covered by tests

for d in bench_config:
if d["key"] == "http_timeout":
# http_timeout should be the only thing configurable in bench_config
self.bench_config = json.dumps({"http_timeout": int(d["value"])}, indent=4)

if bench_config == []:
self.bench_config = json.dumps({})

Expand Down

0 comments on commit b3dc9ab

Please sign in to comment.