Skip to content

Commit

Permalink
[CHORE] Remove calls to jsonbin (hedyorg#4200)
Browse files Browse the repository at this point in the history
In the beginning of Hedy, we logged to jsonbin for simplicity, but we have since professionalized and now also log to s3. We can stop to also log to jsonbin (we did both because I was scared of losing logs and then we never removed jsonbin)
  • Loading branch information
Felienne authored Mar 31, 2023
1 parent 42e65f0 commit 9085321
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 132 deletions.
6 changes: 2 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from logging_config import LOGGING_CONFIG
from utils import dump_yaml_rt, is_debug_mode, load_yaml_rt, timems, version, strip_accents
from website import (ab_proxying, achievements, admin, auth_pages, aws_helpers,
cdn, classes, database, for_teachers, jsonbin, parsons,
cdn, classes, database, for_teachers, s3_logger, parsons,
profile, programs, querylog, quiz, statistics,
translating)
from website.auth import (current_user, is_admin, is_teacher,
Expand Down Expand Up @@ -328,9 +328,7 @@ def before_request_https():

Compress(app)
Commonmark(app)
parse_logger = jsonbin.MultiParseLogger(
jsonbin.JsonBinLogger.from_env_vars(),
jsonbin.S3ParseLogger.from_env_vars())
parse_logger = s3_logger.S3ParseLogger.from_env_vars()
querylog.LOG_QUEUE.set_transmitter(
aws_helpers.s3_querylog_transmitter_from_env())

Expand Down
4 changes: 2 additions & 2 deletions gunicorn.conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
def worker_exit(server, worker):
# When the worker is being exited (perhaps because of a timeout),
# give the query_log handler a chance to flush to disk.
from website import querylog, jsonbin
from website import querylog, s3_logger
querylog.emergency_shutdown()
jsonbin.emergency_shutdown()
s3_logger.emergency_shutdown()


def post_fork(server, worker):
Expand Down
126 changes: 0 additions & 126 deletions website/jsonbin.py

This file was deleted.

38 changes: 38 additions & 0 deletions website/s3_logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import logging

from . import aws_helpers, log_queue

logger = logging.getLogger(__name__)


class NullLogger:
"""A logger that doesn't actually do anything."""

def log(self, obj):
pass


class S3ParseLogger:
"""A logger that logs to S3.
"""

@staticmethod
def from_env_vars():
transmitter = aws_helpers.s3_parselog_transmitter_from_env()
if not transmitter:
return NullLogger()

S3_LOG_QUEUE.set_transmitter(transmitter)
return S3ParseLogger()

def log(self, obj):
S3_LOG_QUEUE.add(obj)


S3_LOG_QUEUE = log_queue.LogQueue("parse", batch_window_s=300)
S3_LOG_QUEUE.try_load_emergency_saves()


def emergency_shutdown():
"""The process is being killed. Do whatever needs to be done to save the logs."""
S3_LOG_QUEUE.emergency_save_to_disk()

0 comments on commit 9085321

Please sign in to comment.