Skip to content

Commit

Permalink
events: Set a month as the default index for the events
Browse files Browse the repository at this point in the history
  • Loading branch information
psaiz authored and ntarocco committed Oct 3, 2023
1 parent db57fc3 commit 9e712e4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion invenio_stats/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand All @@ -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


Expand Down
5 changes: 1 addition & 4 deletions tests/test_prefixing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions tests/test_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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

0 comments on commit 9e712e4

Please sign in to comment.