-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
operation logs: use an Elasticsearch only resource #1937
Conversation
b381c66
to
9ab6b1e
Compare
d7e0bd5
to
1b60fce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit message:
- s/cli/CLI.
- s/elasticsearch/Elasticsearch/.
- s/db/DB/.
|
||
def operation_log_id_fetcher(record_uuid, data): | ||
"""Fetch a Organisation record's identifiers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Fetch a Organisation record's identifiers. | |
"""Fetch an Organisation record's identifier. |
:param record_pid: record pid. | ||
@classmethod | ||
def create(cls, data, id_=None, index_refresh='false', **kwargs): | ||
r"""Create a new record instance and store it in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it database or ES index?
"""Bulk index records. | ||
@classmethod | ||
def get_record(cls, id_): | ||
"""Retrieve the record by id. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Retrieve the record by id. | |
"""Retrieve the record by ID. |
def dump_operation_logs(outfile): | ||
"""Dumps operation log records in a given file. | ||
|
||
:param outfile: Json operation log output file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:param outfile: Json operation log output file. | |
:param outfile: JSON operation log output file. |
@@ -1,7 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
# | |||
# RERO ILS | |||
# Copyright (C) 2021 RERO | |||
# Copyright (C) 2019 RERO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2019?
@@ -15,6 +15,11 @@ | |||
# You should have received a copy of the GNU Affero General Public License | |||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
|||
"""Elasticsearch mappings.""" | |||
"""Operation logs records elasticsarch templates.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Operation logs records elasticsarch templates.""" | |
"""Elasticsearch templates for Operation log records.""" |
from __future__ import absolute_import, print_function | ||
|
||
def list_es_templates(): | ||
"""Elasticsearch Templates path.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Elasticsearch Templates path.""" | |
"""Elasticsearch templates path.""" |
@@ -1,7 +1,7 @@ | |||
# -*- coding: utf-8 -*- | |||
# | |||
# RERO ILS | |||
# Copyright (C) 2021 RERO | |||
# Copyright (C) 2020 RERO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2020 ? 🙂
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
"""Operation logs Record extensions.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Operation logs Record extensions.""" | |
"""Operation log record extensions.""" |
def test_operation_logs_rest(client, loan_pending_martigny, | ||
librarian_martigny, | ||
json_header): | ||
"""Test record retrieval.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same docstring as in L27 of the same file.
f10c903
to
e804e37
Compare
doc_types = None | ||
fields = ('*', ) | ||
facets = {} | ||
LONG_INDEX_NAME = 'operation_logs-operation_log-v0.0.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really used somewhere?
OperationLog(operation_log_data).dumps() | ||
tmp = deepcopy(operation_log_data) | ||
tmp['date'] = '2020-01-21T09:51:52.879533+00:00' | ||
OperationLog.create(tmp, index_refresh='wait_for') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learned something (wait_for
)
**kwargs | ||
) | ||
|
||
# TODO: enable this whe a invenio-records is updated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# TODO: enable this whe a invenio-records is updated. | |
# TODO: enable this when a invenio-records is updated. |
'holdings': 'hold' | ||
} | ||
|
||
def pre_dump(self, record, dumper=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done in the listener, or listener logic put here?
@@ -1638,6 +1637,7 @@ def _(x): | |||
}, | |||
record_class='rero_ils.modules.operation_logs.api:OperationLog', | |||
list_route='/operation_logs/', | |||
# TODO: create a converter for es id, not used for the moment. | |||
item_route='/operation_logs/<pid(oplg, record_class=' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I not used, it's better to remove.
rero_ils/modules/fetchers.py
Outdated
@@ -27,7 +27,7 @@ | |||
|
|||
|
|||
def id_fetcher(record_uuid, data, provider, pid_key='pid'): | |||
"""Fetch a Organisation record's identifiers. | |||
"""Fetch an Organisation record's identifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""Fetch an Organisation record's identifier. | |
"""Fetch a record's identifier. |
class OperationLogsIndexer(IlsRecordsIndexer): | ||
"""Operation log indexing class.""" | ||
@classmethod | ||
def bulk(cls, data): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bulk_index
is a better name
return cls(source.get('_source', {})) | ||
|
||
@classmethod | ||
def get_indices(cls): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like that can be used https://www.elastic.co/guide/en/elasticsearch/reference/7.12/cat-indices.html instead of a search ?
|
||
:param outfile: JSON operation log output file. | ||
""" | ||
enabled_logs = current_app.config.get('RERO_ILS_ENABLE_OPERATION_LOG') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems not be used.
@click.command('dump_operation_logs') | ||
@click.argument('outfile', type=click.File('w')) | ||
@with_appcontext | ||
def dump_operation_logs(outfile): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be useful to produce only a dump for a specific year?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more comment
4ffc736
to
b869885
Compare
8c88771
to
5661fdc
Compare
* Renames virtua command CLI name. * Fixes monitor view to compute Elasticsearch and DB count diff when the index does not exists. * Creates an operation logs Elasticsearch record class. It creates one index per year. * Denies to all to read one record. * Adds a CLI to dumps the operation logs in a JSON file for backup. * Closes: rero#1725. Co-Authored-By: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
index does not exists.
index per year.
Co-Authored-By: Johnny Mariéthoz Johnny.Mariethoz@rero.ch
Why are you opening this PR?
Dependencies
My PR depends on the following
rero-ils-ui
's PR(s):How to test?
Code review check list