-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
hasher-matcher-actioner/reference_omm_configs/json_log_omm_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
""" | ||
A development version of an omm_config, with every field visible and commented. | ||
This is the configuration that is used by default for the developer instance | ||
which runs in the dev container by default. Every config field is present | ||
to make it easier to copy the file as a template for others. | ||
""" | ||
|
||
import logging | ||
from logging.config import dictConfig | ||
|
||
from OpenMediaMatch.storage.postgres.impl import DefaultOMMStore | ||
from OpenMediaMatch.utils.fetch_benchmarking import InfiniteRandomExchange | ||
from OpenMediaMatch.utils.formatters import CustomJsonFormatter | ||
from threatexchange.signal_type.pdq.signal import PdqSignal | ||
from threatexchange.signal_type.md5 import VideoMD5Signal | ||
from threatexchange.content_type.photo import PhotoContent | ||
from threatexchange.content_type.video import VideoContent | ||
from threatexchange.exchanges.impl.static_sample import StaticSampleSignalExchangeAPI | ||
from threatexchange.exchanges.impl.ncmec_api import NCMECSignalExchangeAPI | ||
from threatexchange.exchanges.impl.stop_ncii_api import StopNCIISignalExchangeAPI | ||
from threatexchange.exchanges.impl.fb_threatexchange_api import ( | ||
FBThreatExchangeSignalExchangeAPI, | ||
) | ||
|
||
# Database configuration | ||
DBUSER = "media_match" | ||
DBPASS = "hunter2" | ||
DBHOST = "db" | ||
DBNAME = "media_match" | ||
DATABASE_URI = f"postgresql+psycopg2://{DBUSER}:{DBPASS}@{DBHOST}/{DBNAME}" | ||
|
||
# Role configuration | ||
PRODUCTION = False | ||
ROLE_HASHER = True | ||
ROLE_MATCHER = True | ||
ROLE_CURATOR = True | ||
# APScheduler (background threads for development) | ||
TASK_FETCHER = True | ||
TASK_INDEXER = True | ||
TASK_INDEX_CACHE = True | ||
|
||
# Core functionality configuration | ||
STORAGE_IFACE_INSTANCE = DefaultOMMStore( | ||
signal_types=[PdqSignal, VideoMD5Signal], | ||
content_types=[PhotoContent, VideoContent], | ||
exchange_types=[ | ||
StaticSampleSignalExchangeAPI, | ||
InfiniteRandomExchange, # type: ignore | ||
FBThreatExchangeSignalExchangeAPI, # type: ignore | ||
NCMECSignalExchangeAPI, # type: ignore | ||
StopNCIISignalExchangeAPI, | ||
], | ||
) | ||
|
||
FLASK_LOGGING_CONFIG = dictConfig({ | ||
'version': 1, | ||
'formatters': { | ||
'default': { | ||
'format': '[%(asctime)s] %(levelname)s in %(module)s: %(message)s', | ||
}, | ||
'json': { | ||
"()": "OpenMediaMatch.utils.formatters.CustomJsonFormatter" | ||
} | ||
}, | ||
'handlers': {'wsgi': { | ||
'class': 'logging.StreamHandler', | ||
'stream': 'ext://flask.logging.wsgi_errors_stream', | ||
'formatter': 'json' | ||
}}, | ||
'root': { | ||
'level': 'INFO', | ||
'handlers': ['wsgi'] | ||
} | ||
}) | ||
|
||
# Debugging stuff | ||
# SQLALCHEMY_ENGINE_LOG_LEVEL = logging.INFO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
hasher-matcher-actioner/src/OpenMediaMatch/utils/formatters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pythonjsonlogger import jsonlogger | ||
|
||
class CustomJsonFormatter(jsonlogger.JsonFormatter): | ||
""" | ||
Outputs logs in a JSON format. | ||
""" | ||
|
||
def add_fields(self, log_record, record, message_dict): | ||
log_record["level"] = record.__dict__.get("levelname") | ||
log_record["timestamp"] = self.formatTime(record) | ||
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict) |