Skip to content

Commit 4077939

Browse files
authored
feat: allow admin to run in read-only mode (#3790)
From now until when we cut over prod to MozCloud we're going to run the database as a replica of the GCPv1 database. This means we can't make any writes through MozCloud infra. We need to accommodate the heartbeat function of admin, and make it operate as read-only until we cut over. I intend to back this patch out entirely after cut-over.
1 parent 5d8cf92 commit 4077939

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/auslib/web/admin/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ def should_time_request():
4646
return True
4747

4848

49-
def create_app():
49+
def create_app(allow_read_only=False):
5050
connexion_app = connexion.App(__name__, debug=False, options={"swagger_ui": False})
5151
connexion_app.add_api(spec, validator_map=validator_map, strict_validation=True)
5252
connexion_app.add_api(path.join(current_dir, "swagger", "api_v2.yml"), base_path="/v2", strict_validation=True, validate_responses=True)
5353
flask_app = connexion_app.app
5454

55-
create_dockerflow_endpoints(flask_app)
55+
if allow_read_only:
56+
create_dockerflow_endpoints(flask_app, heartbeat_database_fn=lambda dbo: dbo.rules.count())
57+
else:
58+
create_dockerflow_endpoints(flask_app)
5659

5760
@flask_app.before_request
5861
def setup_statsd():

uwsgi/admin.wsgi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ log = logging.getLogger(__file__)
7171
# statsd environment also needs to be set up before importing the application
7272
statsd.defaults.PREFIX = "balrog.admin"
7373

74+
# temporarily allow admin to run in read-only mode, until MozCloud migration
75+
# is completed
76+
allow_read_only = bool(os.environ.get("BALROG_ALLOW_READ_ONLY"))
77+
7478
from auslib.global_state import cache, dbo # noqa
7579
from auslib.web.admin.base import create_app
7680

77-
application = create_app().app
81+
application = create_app(allow_read_only).app
7882

7983
cache.make_copies = True
8084
# We explicitly don't want a blob_version cache here because it will cause

0 commit comments

Comments
 (0)