Skip to content
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

Merged
merged 1 commit into from
May 27, 2021

Conversation

jma
Copy link
Contributor

@jma jma commented May 22, 2021

  • 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: Find a better operation log implementation #1725.

Co-Authored-By: Johnny Mariéthoz Johnny.Mariethoz@rero.ch

Why are you opening this PR?

  • Which task/US does it implement?
  • Which issue does it fix?

Dependencies

My PR depends on the following rero-ils-ui's PR(s):

  • rero/rero-ils-ui#

How to test?

  • What command should I have to run to test your PR?
  • What should I test through the UI?

Code review check list

  • Commit message template compliance.
  • Commit message without typos.
  • File names.
  • Functions names.
  • Functions docstrings.
  • Unnecessary commited files?
  • Cypress tests successful?

@jma jma force-pushed the maj-record-es branch 4 times, most recently from b381c66 to 9ab6b1e Compare May 23, 2021 08:02
@jma jma changed the title in progress operation logs: use an elasticsearch only resource May 23, 2021
@jma jma force-pushed the maj-record-es branch 2 times, most recently from d7e0bd5 to 1b60fce Compare May 24, 2021 08:04
@jma jma requested review from lauren-d and sebdeleze May 24, 2021 08:06
@jma jma marked this pull request as ready for review May 24, 2021 08:06
Copy link

@iGormilhit iGormilhit left a 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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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.

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
: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

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."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Elasticsearch Templates path."""
"""Elasticsearch templates path."""

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# RERO ILS
# Copyright (C) 2021 RERO
# Copyright (C) 2020 RERO

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."""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Operation logs Record extensions."""
"""Operation log record extensions."""

def test_operation_logs_rest(client, loan_pending_martigny,
librarian_martigny,
json_header):
"""Test record retrieval."""

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.

@iGormilhit iGormilhit added the f: activity-logs Everything around logging user or system activities label May 25, 2021
@jma jma force-pushed the maj-record-es branch 2 times, most recently from f10c903 to e804e37 Compare May 26, 2021 06:49
doc_types = None
fields = ('*', )
facets = {}
LONG_INDEX_NAME = 'operation_logs-operation_log-v0.0.1'

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')

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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):

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='

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.

@@ -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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Fetch an Organisation record's identifier.
"""Fetch a record's identifier.

class OperationLogsIndexer(IlsRecordsIndexer):
"""Operation log indexing class."""
@classmethod
def bulk(cls, data):

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):

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')

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):

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?

Copy link
Contributor

@lauren-d lauren-d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no more comment

@jma jma force-pushed the maj-record-es branch 2 times, most recently from 4ffc736 to b869885 Compare May 26, 2021 09:07
@jma jma requested a review from iGormilhit May 26, 2021 09:47
@jma jma force-pushed the maj-record-es branch 3 times, most recently from 8c88771 to 5661fdc Compare May 26, 2021 13:24
@jma jma changed the title operation logs: use an elasticsearch only resource operation logs: use an Elasticsearch only resource May 26, 2021
* 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>
@jma jma force-pushed the maj-record-es branch from 5661fdc to afc478d Compare May 27, 2021 05:15
@jma jma merged commit df3a6c0 into rero:maj-US1913-log-loan-history May 27, 2021
@jma jma deleted the maj-record-es branch January 13, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: activity-logs Everything around logging user or system activities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants