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

Allow for Database options to be set via config #222

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
17 changes: 17 additions & 0 deletions codecov/settings_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
import os
from urllib.parse import urlparse

Expand Down Expand Up @@ -105,6 +106,8 @@
DATABASE_HOST = get_config("services", "database", "host", default="postgres")
DATABASE_PORT = get_config("services", "database", "port", default=5432)

DATABASE_OPTIONS = get_config("services", "database", "options", default="{}")

DATABASE_READ_REPLICA_ENABLED = get_config(
"setup", "database", "read_replica_enabled", default=False
)
Expand Down Expand Up @@ -132,6 +135,8 @@
)
DATABASE_READ_PORT = get_config("services", "database_read", "port", default=5432)

DATABASE_READ_OPTIONS = get_config("services", "database_read", "options", default="{}")

TIMESERIES_ENABLED = get_config("setup", "timeseries", "enabled", default=False)
TIMESERIES_REAL_TIME_AGGREGATES = get_config(
"setup", "timeseries", "real_time_aggregates", default=False
Expand Down Expand Up @@ -162,6 +167,10 @@
"services", "timeseries_database", "port", default=5432
)

TIMESERIES_DATABASE_OPTIONS = get_config(
"services", "timeseries_database", "options", default="{}"
)

TIMESERIES_DATABASE_READ_REPLICA_ENABLED = get_config(
"setup", "timeseries", "read_replica_enabled", default=False
)
Expand Down Expand Up @@ -191,6 +200,10 @@
"services", "timeseries_database_read", "port", default=5432
)

TIMESERIES_DATABASE_READ_OPTIONS = get_config(
"services", "timeseries_database_read", "options", default="{}"
)

# this is the time in seconds django decides to keep the connection open after the request
# the default is 0 seconds, meaning django closes the connection after every request
# https://docs.djangoproject.com/en/3.1/ref/settings/#conn-max-age
Expand All @@ -205,6 +218,7 @@
"HOST": DATABASE_HOST,
"PORT": DATABASE_PORT,
"CONN_MAX_AGE": CONN_MAX_AGE,
"OPTIONS": ast.literal_eval(DATABASE_OPTIONS),
}
}

Expand All @@ -217,6 +231,7 @@
"HOST": DATABASE_READ_HOST,
"PORT": DATABASE_READ_PORT,
"CONN_MAX_AGE": CONN_MAX_AGE,
"OPTIONS": ast.literal_eval(DATABASE_READ_OPTIONS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a json.loads instead here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure - would then be a more restricted format, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

In what sense? Were you hoping to pass in Python literals that can't be encoded as JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were you hoping to pass in Python literals that can't be encoded as JSON?

Not really. I think I can life with JSON just fine.

}

if TIMESERIES_ENABLED:
Expand All @@ -228,6 +243,7 @@
"HOST": TIMESERIES_DATABASE_HOST,
"PORT": TIMESERIES_DATABASE_PORT,
"CONN_MAX_AGE": CONN_MAX_AGE,
"OPTIONS": ast.literal_eval(TIMESERIES_DATABASE_OPTIONS),
}

if TIMESERIES_DATABASE_READ_REPLICA_ENABLED:
Expand All @@ -239,6 +255,7 @@
"HOST": TIMESERIES_DATABASE_READ_HOST,
"PORT": TIMESERIES_DATABASE_READ_PORT,
"CONN_MAX_AGE": CONN_MAX_AGE,
"OPTIONS": ast.literal_eval(TIMESERIES_DATABASE_READ_OPTIONS),
}

DATABASE_ROUTERS = ["codecov.db.DatabaseRouter"]
Expand Down