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

Log errors during start-up and fix the default logging config #122

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/122.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log errors during start-up.
2 changes: 2 additions & 0 deletions sygnal.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ log:
handlers: ["stderr"]
level: "INFO"

disable_existing_loggers: false


access:
# Specify whether or not to trust the IP address in the `X-Forwarded-For`
Expand Down
36 changes: 26 additions & 10 deletions sygnal/sygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
import yaml
from opentracing.scope_managers.asyncio import AsyncioScopeManager
from twisted.enterprise.adbapi import ConnectionPool
from twisted.internet import asyncioreactor
from twisted.internet import asyncioreactor, defer
from twisted.internet.defer import ensureDeferred
from twisted.python import log as twisted_log
from twisted.python.failure import Failure

from sygnal.http import PushGatewayApiServer

Expand Down Expand Up @@ -130,10 +131,9 @@ def __init__(self, config, custom_reactor, tracer=opentracing.tracer):
)
raise
else:
logger.error(
raise RuntimeError(
"Unknown OpenTracing implementation: %s.", tracecfg["impl"]
)
sys.exit(1)

db_name = config["database"]["name"]

Expand Down Expand Up @@ -187,14 +187,14 @@ async def _make_pushkins_then_start(self, port, bind_addresses, pushgateway_api)
try:
self.pushkins[app_id] = await self._make_pushkin(app_id, app_cfg)
except Exception:
logger.exception(
raise RuntimeError(
"Failed to load and create pushkin for kind %s", app_cfg["type"]
)
sys.exit(1)

if len(self.pushkins) == 0:
logger.error("No app IDs are configured. Edit sygnal.yaml to define some.")
sys.exit(1)
raise RuntimeError(
"No app IDs are configured. Edit sygnal.yaml to define some."
)

logger.info("Configured with app IDs: %r", self.pushkins.keys())

Expand All @@ -210,9 +210,25 @@ def run(self):
bind_addresses = self.config["http"]["bind_addresses"]
pushgateway_api = PushGatewayApiServer(self)

ensureDeferred(
Copy link
Member Author

Choose a reason for hiding this comment

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

This in particular had me scratch my head since...it makes a Deferred but never does anything with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

iirc that schedules that coroutine on the Reactor (if I remember the Twisted words correctly).

self._make_pushkins_then_start(port, bind_addresses, pushgateway_api)
)
@defer.inlineCallbacks
def start():
try:
yield ensureDeferred(
self._make_pushkins_then_start(
port, bind_addresses, pushgateway_api
)
)
except Exception:
# Print the exception and bail out.
print("Error during startup:", file=sys.stderr)
babolivier marked this conversation as resolved.
Show resolved Hide resolved

# this gives better tracebacks than traceback.print_exc()
Failure().printTraceback(file=sys.stderr)
babolivier marked this conversation as resolved.
Show resolved Hide resolved

if self.reactor.running:
self.reactor.stop()

self.reactor.callWhenRunning(start)
self.reactor.run()


Expand Down