From 9e712e45979ba14bfae3f55698539127bdfc7e4d Mon Sep 17 00:00:00 2001 From: Pablo Saiz Date: Mon, 2 Oct 2023 15:41:06 +0200 Subject: [PATCH] events: Set a month as the default index for the events --- invenio_stats/processors.py | 2 +- tests/test_cli.py | 16 ++++++++-------- tests/test_prefixing.py | 5 +---- tests/test_processors.py | 17 +++++++---------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/invenio_stats/processors.py b/invenio_stats/processors.py index 4f119a1..6312082 100644 --- a/invenio_stats/processors.py +++ b/invenio_stats/processors.py @@ -140,7 +140,7 @@ def __init__( self, queue, prefix="events", - suffix="%Y-%m-%d", + suffix="%Y-%m", client=None, preprocessors=None, double_click_window=10, diff --git a/tests/test_cli.py b/tests/test_cli.py index 7870838..0da70f6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -56,9 +56,9 @@ def test_events_process(search_clear, script_info, event_queues): current_search.flush_and_refresh(index="*") - assert search_obj.index("events-stats-file-download-2018-01-01").count() == 3 + assert search_obj.index("events-stats-file-download-2018-01").count() == 3 assert search_obj.index("events-stats-file-download").count() == 3 - assert not search_clear.indices.exists("events-stats-record-view-2018-01-01") + assert not search_clear.indices.exists("events-stats-record-view-2018-01") assert not search_clear.indices.exists_alias(name="events-stats-record-view") result = runner.invoke( @@ -67,9 +67,9 @@ def test_events_process(search_clear, script_info, event_queues): assert result.exit_code == 0 current_search.flush_and_refresh(index="*") - assert search_obj.index("events-stats-file-download-2018-01-01").count() == 3 + assert search_obj.index("events-stats-file-download-2018-01").count() == 3 assert search_obj.index("events-stats-file-download").count() == 3 - assert search_obj.index("events-stats-record-view-2018-01-01").count() == 3 + assert search_obj.index("events-stats-record-view-2018-01").count() == 3 assert search_obj.index("events-stats-record-view").count() == 3 # Create some more events @@ -84,11 +84,11 @@ def test_events_process(search_clear, script_info, event_queues): assert result.exit_code == 0 current_search.flush_and_refresh(index="*") - assert search_obj.index("events-stats-file-download-2018-01-01").count() == 3 - assert search_obj.index("events-stats-file-download-2018-02-01").count() == 1 + assert search_obj.index("events-stats-file-download-2018-01").count() == 3 + assert search_obj.index("events-stats-file-download-2018-02").count() == 1 assert search_obj.index("events-stats-file-download").count() == 4 - assert search_obj.index("events-stats-record-view-2018-01-01").count() == 3 - assert search_obj.index("events-stats-record-view-2018-02-01").count() == 1 + assert search_obj.index("events-stats-record-view-2018-01").count() == 3 + assert search_obj.index("events-stats-record-view-2018-02").count() == 1 assert search_obj.index("events-stats-record-view").count() == 4 diff --git a/tests/test_prefixing.py b/tests/test_prefixing.py index 5cd6e7c..3523f09 100644 --- a/tests/test_prefixing.py +++ b/tests/test_prefixing.py @@ -46,10 +46,7 @@ def test_index_prefix( index_prefix = config_with_index_prefix["SEARCH_INDEX_PREFIX"] index_name = index_prefix + "events-stats-file-download" - assert search_clear.indices.exists(index_name + "-2018-01-01") - assert search_clear.indices.exists(index_name + "-2018-01-02") - assert search_clear.indices.exists(index_name + "-2018-01-03") - assert search_clear.indices.exists(index_name + "-2018-01-04") + assert search_clear.indices.exists(index_name + "-2018-01") assert search_clear.indices.exists_alias(name=index_name) # 3) aggregate events diff --git a/tests/test_processors.py b/tests/test_processors.py index af4dbb6..bf0ead8 100644 --- a/tests/test_processors.py +++ b/tests/test_processors.py @@ -315,7 +315,7 @@ def bulk(client, generator, *args, **kwargs): { "_id": _id, "_op_type": "index", - "_index": "events-stats-file-download-2017-01-01", + "_index": "events-stats-file-download-2017-01", "_source": event, } ) @@ -372,7 +372,7 @@ def test_double_clicks(app, mock_event_queue, search_clear): process_events(["file-download"]) current_search.flush_and_refresh(index="*") res = search_clear.search( - index="events-stats-file-download-2000-06-01", + index="events-stats-file-download-2000-06", ) assert res["hits"]["total"]["value"] == 2 @@ -404,10 +404,10 @@ def _raises_on_second_call(doc): current_search.flush_and_refresh(index="*") assert get_queue_size("stats-file-download") == 4 - assert not search_clear.indices.exists("events-stats-file-download-2018-01-01") - assert not search_clear.indices.exists("events-stats-file-download-2018-01-02") - assert not search_clear.indices.exists("events-stats-file-download-2018-01-03") - assert not search_clear.indices.exists("events-stats-file-download-2018-01-04") + assert not search_clear.indices.exists("events-stats-file-download-2018-01") + assert not search_clear.indices.exists("events-stats-file-download-2018-01") + assert not search_clear.indices.exists("events-stats-file-download-2018-01") + assert not search_clear.indices.exists("events-stats-file-download-2018-01") assert not search_clear.indices.exists_alias(name="events-stats-file-download") with caplog.at_level(logging.ERROR): @@ -422,7 +422,4 @@ def _raises_on_second_call(doc): current_search.flush_and_refresh(index="*") assert get_queue_size("stats-file-download") == 0 assert search_obj.index("events-stats-file-download").count() == 3 - assert search_obj.index("events-stats-file-download-2018-01-01").count() == 1 - assert not search_clear.indices.exists("events-stats-file-download-2018-01-02") - assert search_obj.index("events-stats-file-download-2018-01-03").count() == 1 - assert search_obj.index("events-stats-file-download-2018-01-04").count() == 1 + assert search_obj.index("events-stats-file-download-2018-01").count() == 3