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

[batch] Add feature switches #13262

Merged
merged 4 commits into from
Jul 21, 2023
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
46 changes: 45 additions & 1 deletion batch/batch/driver/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
from hailtop import aiotools, httpx
from hailtop.config import get_deploy_config
from hailtop.hail_logging import AccessLogger
from hailtop.utils import AsyncWorkerPool, Notice, dump_all_stacktraces, flatten, periodically_call, time_msecs
from hailtop.utils import (
AsyncWorkerPool,
Notice,
dump_all_stacktraces,
flatten,
periodically_call,
time_msecs,
)
from web_common import render_template, set_message, setup_aiohttp_jinja2, setup_common_static_routes

from ..batch import cancel_batch_in_db
Expand Down Expand Up @@ -459,6 +466,7 @@ async def get_index(request, userdata):
'total_provisioned_cores_mcpu': inst_coll_manager.global_total_provisioned_cores_mcpu,
'live_free_cores_mcpu': inst_coll_manager.global_current_version_live_free_cores_mcpu,
'frozen': app['frozen'],
'feature_flags': app['feature_flags'],
}
return await render_template('batch-driver', request, userdata, 'index.html', page_context)

Expand Down Expand Up @@ -552,6 +560,27 @@ def validate_int(session, name, value, predicate, description):
return validate(session, name, i, predicate, description)


@routes.post('/configure-feature-flags')
@check_csrf_token
@auth.web_authenticated_developers_only()
async def configure_feature_flags(request, userdata): # pylint: disable=unused-argument
app = request.app
db: Database = app['db']
post = await request.post()

compact_billing_tables = 'compact_billing_tables' in post

await db.execute_update(
'''
UPDATE feature_flags SET compact_billing_tables = %s;
''',
(compact_billing_tables,),
)

row = await db.select_and_fetchone('SELECT * FROM feature_flags')
app['feature_flags'] = row


@routes.post('/config-update/pool/{pool}')
@check_csrf_token
@auth.web_authenticated_developers_only()
Expand Down Expand Up @@ -1335,6 +1364,16 @@ async def monitor_system(app):
monitor_instances(app)


async def compact_agg_billing_project_users_table(app):
if not app['feature_flags']['compact_billing_tables']:
return


async def compact_agg_billing_project_users_by_date_table(app):
if not app['feature_flags']['compact_billing_tables']:
return


async def scheduling_cancelling_bump(app):
log.info('scheduling cancelling bump loop')
app['scheduler_state_changed'].notify()
Expand Down Expand Up @@ -1412,6 +1451,9 @@ async def on_startup(app):
app['batch_headers'] = {'Authorization': f'Bearer {row["internal_token"]}'}
app['frozen'] = row['frozen']

row = await db.select_and_fetchone('SELECT * FROM feature_flags')
app['feature_flags'] = row

await refresh_globals_from_db(app, db)

app['scheduler_state_changed'] = Notice()
Expand All @@ -1437,6 +1479,8 @@ async def on_startup(app):
task_manager.ensure_future(periodically_call(60, scheduling_cancelling_bump, app))
task_manager.ensure_future(periodically_call(15, monitor_system, app))
task_manager.ensure_future(periodically_call(5, refresh_globals_from_db, app, db))
task_manager.ensure_future(periodically_call(60, compact_agg_billing_project_users_table, app))
task_manager.ensure_future(periodically_call(60, compact_agg_billing_project_users_by_date_table, app))


async def on_cleanup(app):
Expand Down
13 changes: 13 additions & 0 deletions batch/batch/driver/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ <h1>Globals</h1>
{% endif %}
</div>

<h1>Feature Switches</h1>
danking marked this conversation as resolved.
Show resolved Hide resolved
<div>
<form action="{{ base_path }}/configure-feature-flags" method="POST">
<input type="hidden" name="_csrf" value="{{ csrf_token }}">
<input type="checkbox"
id="compact_billing_tables"
name="compact_billing_tables"
{% if feature_flags['compact_billing_tables'] %}checked{% endif %}
value="true" />
<button>Update</button>
</form>
</div>

<h1>Instance Collections</h1>

<h2>Pools</h2>
Expand Down
5 changes: 5 additions & 0 deletions batch/sql/add-feature-flags.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE IF NOT EXISTS `feature_flags` (
`compact_billing_tables` BOOLEAN NOT NULL
) ENGINE = InnoDB;

INSERT INTO `feature_flags` (compact_billing_tables) VALUES (0);
3 changes: 2 additions & 1 deletion batch/sql/delete-batch-tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ DROP TABLE IF EXISTS `pools`;
DROP TABLE IF EXISTS `inst_colls`;
DROP TABLE IF EXISTS `latest_product_versions`;
DROP TABLE IF EXISTS `resources`;
DROP TABLE IF EXISTS `regions`
DROP TABLE IF EXISTS `regions`;
DROP TABLE IF EXISTS `feature_flags`;
4 changes: 4 additions & 0 deletions batch/sql/estimated-current.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ CREATE TABLE IF NOT EXISTS `globals` (
`frozen` BOOLEAN NOT NULL DEFAULT FALSE
) ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `feature_flags` (
`compact_billing_tables` BOOLEAN NOT NULL
) ENGINE = InnoDB;

CREATE TABLE IF NOT EXISTS `resources` (
`resource` VARCHAR(100) NOT NULL,
`rate` DOUBLE NOT NULL,
Expand Down
3 changes: 3 additions & 0 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2282,6 +2282,9 @@ steps:
- name: add-list-batches-index
script: /io/sql/add-list-batches-index.sql
online: true
- name: add-feature-flags
script: /io/sql/add-feature-flags.sql
online: true
inputs:
- from: /repo/batch/sql
to: /io/sql
Expand Down