Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 8af8a9b

Browse files
authored
Dockerfile-workers: give the master its own log config (#12466)
When we run a worker-mode synapse under docker, everything gets logged to stdout. Currently, output from the workers is tacked with a worker name, for example: ``` 2022-04-13 15:27:56,810 - worker:frontend_proxy1 - synapse.util.caches.lrucache - 154 - INFO - LruCache._expire_old_entries-0 - Dropped 0 items from caches ``` - note `worker:frontend_proxy1`. No such tag is applied to log lines from the master, which makes somewhat confusing reading. To fix this, we generate a dedicated log config file for the master in the same way that we do for the workers, and use that.
1 parent 8e2759f commit 8af8a9b

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

changelog.d/12466.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Dockerfile-workers: give the master its own log config.

docker/configure_workers_and_start.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import os
3030
import subprocess
3131
import sys
32-
from typing import Any, Dict, Set
32+
from typing import Any, Dict, Mapping, Set
3333

3434
import jinja2
3535
import yaml
@@ -341,7 +341,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
341341
# base shared worker jinja2 template.
342342
#
343343
# This config file will be passed to all workers, included Synapse's main process.
344-
shared_config = {"listeners": listeners}
344+
shared_config: Dict[str, Any] = {"listeners": listeners}
345345

346346
# The supervisord config. The contents of which will be inserted into the
347347
# base supervisord jinja2 template.
@@ -446,21 +446,7 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
446446

447447
# Write out the worker's logging config file
448448

449-
# Check whether we should write worker logs to disk, in addition to the console
450-
extra_log_template_args = {}
451-
if environ.get("SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK"):
452-
extra_log_template_args["LOG_FILE_PATH"] = "{dir}/logs/{name}.log".format(
453-
dir=data_dir, name=worker_name
454-
)
455-
456-
# Render and write the file
457-
log_config_filepath = "/conf/workers/{name}.log.config".format(name=worker_name)
458-
convert(
459-
"/conf/log.config",
460-
log_config_filepath,
461-
worker_name=worker_name,
462-
**extra_log_template_args,
463-
)
449+
log_config_filepath = generate_worker_log_config(environ, worker_name, data_dir)
464450

465451
# Then a worker config file
466452
convert(
@@ -496,6 +482,10 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
496482

497483
# Finally, we'll write out the config files.
498484

485+
# log config for the master process
486+
master_log_config = generate_worker_log_config(environ, "master", data_dir)
487+
shared_config["log_config"] = master_log_config
488+
499489
# Shared homeserver config
500490
convert(
501491
"/conf/shared.yaml.j2",
@@ -532,6 +522,30 @@ def generate_worker_files(environ, config_path: str, data_dir: str):
532522
os.mkdir(log_dir)
533523

534524

525+
def generate_worker_log_config(
526+
environ: Mapping[str, str], worker_name: str, data_dir: str
527+
) -> str:
528+
"""Generate a log.config file for the given worker.
529+
530+
Returns: the path to the generated file
531+
"""
532+
# Check whether we should write worker logs to disk, in addition to the console
533+
extra_log_template_args = {}
534+
if environ.get("SYNAPSE_WORKERS_WRITE_LOGS_TO_DISK"):
535+
extra_log_template_args["LOG_FILE_PATH"] = "{dir}/logs/{name}.log".format(
536+
dir=data_dir, name=worker_name
537+
)
538+
# Render and write the file
539+
log_config_filepath = "/conf/workers/{name}.log.config".format(name=worker_name)
540+
convert(
541+
"/conf/log.config",
542+
log_config_filepath,
543+
worker_name=worker_name,
544+
**extra_log_template_args,
545+
)
546+
return log_config_filepath
547+
548+
535549
def start_supervisord():
536550
"""Starts up supervisord which then starts and monitors all other necessary processes
537551

0 commit comments

Comments
 (0)