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

Use consul-template if-statement to check if the listenstore is up #1980

Merged
merged 1 commit into from May 9, 2022

Conversation

alastair
Copy link
Collaborator

@alastair alastair commented May 3, 2022

We want a consul setting that we can use to shut down the listenstore
when we need to do maintenance.
We initially used a python if statement here, expecting to be able to
render the config file as

if False:
    SQLALCHEMY_TIMESCALE_URI = """postgresql:// ..."""
else:
    SQLALCHEMY_TIMESCALE_URI = ""

However this doesn't work when the service disappears from consul (for
example if we shut down the server). The config file ends up as

if False:
    SQLALCHEMY_TIMESCALE_URI = "SERVICEDOESNOTEXIST_timescale-listenbrainz"
else:
    SQLALCHEMY_TIMESCALE_URI = ""

and our startup script (run-lb-command) fails because it finds the sentinel
SERVICEDOESNOTEXIST in the config and refuses to continue.

Instead, use a consul-template {{if}} to render this config depending on
the listenstore_up config item.

This usage duplicates the (printf / env ()) syntax used in our KEY
template as it's not possible to call a template inside an if statement
or a variable declaration

This requires an update to the consul settings for LB to switch to using a json boolean (true/false) instead of a string with a python True/False at the same time that we deploy this.

We want a consul setting that we can use to shut down the listenstore
when we need to do maintenance.
We initially used a python if statement here, expecting to be able to
render the config file as

if False:
    SQLALCHEMY_TIMESCALE_URI = """postgresql:// ..."""
else:
    SQLALCHEMY_TIMESCALE_URI = ""

However this doesn't work when the service disappears from consul (for
example if we shut down the server). The config file ends up as

if False:
    SQLALCHEMY_TIMESCALE_URI = "SERVICEDOESNOTEXIST_timescale-listenbrainz"
else:
    SQLALCHEMY_TIMESCALE_URI = ""

and our startup script (run-lb-command) fails because it finds the sentinel
SERVICEDOESNOTEXIST in the config and refuses to continue.

Instead, use a consul-template {{if}} to render this config depending on
the listenstore_up config item.

This usage duplicates the (printf / env ()) syntax used in our KEY
template as it's not possible to call a template inside an if statement
or a variable declaration
@alastair alastair requested a review from amCap1712 May 3, 2022 14:41
Copy link
Member

@amCap1712 amCap1712 left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@amCap1712 amCap1712 merged commit 9426e28 into master May 9, 2022
@amCap1712 amCap1712 deleted the consul-config-listenstore branch May 9, 2022 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants