This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/data/logs_model/__init__.py
Kenny Lee Sin Cheong 035541c6f2 Implement logs model using Elasticsearch
- Implement logs model using Elasticsearch with tests
- Implement transition model using both elasticsearch and database model
- Add LOGS_MODEL configuration to choose which to use.

Co-authored-by: Sida Chen <sidchen@redhat.com>
Co-authored-by: Kenny Lee Sin Cheong <kenny.lee@redhat.com>
2019-02-12 16:33:42 -05:00

41 lines
1.3 KiB
Python

import os
import logging
from data.logs_model.table_logs_model import TableLogsModel
from data.logs_model.document_logs_model import DocumentLogsModel
from data.logs_model.table_document_transition_logs_model import TableDocumentTransitionLogsModel
from data.logs_model.elastic_logs import AWSElasticsearchLogs
from data.logs_model.interface import ActionLogsDataInterface
logger = logging.getLogger(__name__)
_LOG_MODELS = {
'database': TableLogsModel,
'transition': TableDocumentTransitionLogsModel,
'elasticsearch': DocumentLogsModel,
}
class LogsModelProxy(object):
def __init__(self):
self._model = None
def initialize(self, model):
self._model = model
logger.info('===============================')
logger.info('Using logs model `%s`', self._model)
logger.info('===============================')
def __getattr__(self, attr):
if not self._model:
raise AttributeError("LogsModelProxy is not initialized")
return getattr(self._model, attr)
logs_model = LogsModelProxy()
def configure(config_object):
logger.debug('Configuring Log Model')
model = config_object.get('LOGS_MODEL', ('database', {}))
model_name = model[0]
params = {} if len(model) == 1 else model[1]
logs_model.initialize(_LOG_MODELS[model_name](**params))