Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Improve and unify ingestion server logging, simplify docker CMDs (#2639)

Madison Swain-Bowdendd49aeaec156
diff --git a/docker-compose.yml b/docker-compose.yml
index e11c6b2b0..6bff3f6e4 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -240,7 +240,6 @@ services:
args: # Automatically inferred from env vars, unless specified
- INGESTION_PY_VERSION
image: openverse-ingestion_server
- command: gunicorn -c ./gunicorn.conf.py
ports:
- "50281:8001"
depends_on:
@@ -266,7 +265,7 @@ services:
args: # Automatically inferred from env vars, unless specified
- INGESTION_PY_VERSION
image: openverse-ingestion_server
- command: gunicorn -c ./gunicorn_worker.conf.py
+ command: gunicorn indexer_worker:api --bind 0.0.0.0:8002
expose:
- "8002"
depends_on:
diff --git a/ingestion_server/Dockerfile b/ingestion_server/Dockerfile
index 2b0e95b90..f3b670639 100644
--- a/ingestion_server/Dockerfile
+++ b/ingestion_server/Dockerfile
@@ -78,4 +78,4 @@ COPY --chown=ingestionu . /ingestion_server/
# - 8002: Gunicorn server for `indexer_worker` Falcon app
EXPOSE 8001 8002
-# CMD is set from Docker Compose
+CMD ["gunicorn", "--bind", "0.0.0.0:8001", "api:api"]
diff --git a/ingestion_server/docker-compose.yml b/ingestion_server/docker-compose.yml
deleted file mode 100644
index 8bd64d2cc..000000000
--- a/ingestion_server/docker-compose.yml
+++ /dev/null
@@ -1,15 +0,0 @@
-version: "2.4"
-services:
- ingestion_server:
- # Allow the image tag to be set to a specific version, default to latest
- image: ghcr.io/wordpress/openverse-ingestion_server:${IMAGE_TAG:-latest}
- ports:
- - "8001:8001"
- env_file:
- - .env
- dns:
- # Related to DNS management on the production box.
- # 172.16.0.0–172.31.255.255 is a reserved IP range by the (IANA) for
- # private/internal networking. This specific IP is the DNS resolution address
- # for a default AWS Virtual Private Cloud.
- - 172.31.0.2
diff --git a/ingestion_server/gunicorn.conf.py b/ingestion_server/gunicorn.conf.py
index bc15b4447..842c29b2b 100644
--- a/ingestion_server/gunicorn.conf.py
+++ b/ingestion_server/gunicorn.conf.py
@@ -1,7 +1,44 @@
-bind = ["0.0.0.0:8001"]
capture_output = True
+accesslog = "-"
+errorlog = "-"
chdir = "./ingestion_server/"
timeout = 120
reload = True
+logconfig_dict = {
+ # NOTE: Most of this is inherited from the default configuration
+ # https://github.com/benoitc/gunicorn/blob/cc2e3835784542e65886cd27f64d444309fbaad0/gunicorn/glogging.py#L48-L86
+ "version": 1,
+ "disable_existing_loggers": False,
+ "formatters": {
+ "generic": {
+ "format": "[%(asctime)s - %(name)s - %(lineno)3d][%(levelname)s] %(message)s", # noqa: E501
+ },
+ },
+ "root": {"level": "INFO", "handlers": ["console"]},
+ "loggers": {
+ "gunicorn.error": {
+ "level": "DEBUG",
+ "handlers": ["console"],
+ "propagate": False, # Prevents default handler from also logging this
+ "qualname": "gunicorn.error",
+ },
+ "gunicorn.access": {
+ "level": "INFO",
+ "handlers": ["console"],
+ "propagate": False, # Prevents default handler from also logging this
+ "qualname": "gunicorn.access",
+ },
+ "": {
+ "level": "INFO",
+ "handlers": ["console"],
+ },
+ },
+ "handlers": {
+ "console": {
+ "class": "logging.StreamHandler",
+ "formatter": "generic",
+ "stream": "ext://sys.stdout",
+ },
+ },
+}
loglevel = "debug"
-wsgi_app = "api:api"
diff --git a/ingestion_server/gunicorn_worker.conf.py b/ingestion_server/gunicorn_worker.conf.py
deleted file mode 100644
index df032c58e..000000000
--- a/ingestion_server/gunicorn_worker.conf.py
+++ /dev/null
@@ -1,9 +0,0 @@
-bind = ["0.0.0.0:8002"]
-capture_output = True
-chdir = "./ingestion_server/"
-timeout = 120
-reload = True
-loglevel = "debug"
-wsgi_app = "indexer_worker:api"
-accesslog = "-"
-errorlog = "-"
diff --git a/ingestion_server/ingestion_server/api.py b/ingestion_server/ingestion_server/api.py
index c99f12f66..240a095b4 100644
--- a/ingestion_server/ingestion_server/api.py
+++ b/ingestion_server/ingestion_server/api.py
@@ -2,7 +2,6 @@
import logging
import os
-import sys
import time
import uuid
from multiprocessing import Process, Value
@@ -323,20 +322,9 @@ class StateResource:
clear_state()
-def create_api(log=True):
+def create_api():
"""Create an instance of the Falcon API server."""
- if log:
- root = logging.getLogger()
- root.setLevel(logging.DEBUG)
- handler = logging.StreamHandler(sys.stdout)
- handler.setLevel(logging.INFO)
- formatter = logging.Formatter(
- "%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s"
- )
- handler.setFormatter(formatter)
- root.addHandler(handler)
-
_api = falcon.App()
task_tracker = TaskTracker()
diff --git a/ingestion_server/ingestion_server/indexer_worker.py b/ingestion_server/ingestion_server/indexer_worker.py
index d6631b01b..3b280ffa4 100644
--- a/ingestion_server/ingestion_server/indexer_worker.py
+++ b/ingestion_server/ingestion_server/indexer_worker.py
@@ -6,7 +6,6 @@ data has been indexed, notify Ingestion Server and stop the instance.
"""
import logging as log
-import sys
from multiprocessing import Process
import boto3
@@ -111,15 +110,6 @@ def _self_destruct():
ec2_client.stop_instances(InstanceIds=[instance_id])
-root = log.getLogger()
-root.setLevel(log.DEBUG)
-handler = log.StreamHandler(sys.stdout)
-handler.setLevel(log.INFO)
-formatter = log.Formatter(
- "%(asctime)s %(levelname)s %(filename)s:%(lineno)d - %(message)s"
-)
-handler.setFormatter(formatter)
-root.addHandler(handler)
api = falcon.App()
api.add_route("/indexing_task", IndexingJobResource())
api.add_route("/healthcheck", HealthcheckResource())