Skip to content

Commit e60d6d0

Browse files
authored
[ENG-9699] expiring usage events (#11760)
* expire usage events after 90 days * chore: renames from djelme
1 parent aaa3543 commit e60d6d0

10 files changed

Lines changed: 27 additions & 15 deletions

File tree

api/base/settings/defaults.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,7 @@
337337
},
338338
},
339339
}
340-
# Store yearly indices for time-series metrics
341-
ELASTICSEARCH_METRICS_DATE_FORMAT = '%Y'
340+
OSF_USAGEEVENT_EXPIRATION_DAYS = 90
342341

343342
WAFFLE_CACHE_NAME = 'waffle_cache'
344343
STORAGE_USAGE_CACHE_NAME = 'storage_usage'

osf/metrics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ for field definitions with comments mapping fields to concepts in the COUNTER sp
1515

1616
each periodic report is a subclass of `osf.metrics.monthly_reports.BaseMonthlyReport`
1717
or `osf.metrics.daily_reports.BaseDailyReport` (themselves subclasses of
18-
`elasticsearch_metrics.imps.elastic8.CyclicRecord`) and has a "reporter"
18+
`elasticsearch_metrics.imps.elastic8.CyclicReport`) and has a "reporter"
1919
(see `osf.metrics.reporters`) that is invoked periodically to report.
2020

2121
## api

osf/metrics/daily_reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
###
2323
# base class
2424

25-
class BaseDailyReport(djelme.CyclicRecord):
25+
class BaseDailyReport(djelme.CyclicReport):
2626
CYCLE_TIMEDEPTH = DAILY
2727

2828
class Meta:

osf/metrics/events.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import functools
44
from urllib.parse import urlsplit
55

6+
from django.conf import settings as django_settings
7+
from django.core.management import call_command
68
import elasticsearch8.dsl as esdsl
79
from elasticsearch_metrics import MONTHLY
810
import elasticsearch_metrics.imps.elastic8 as djelme
911

12+
from framework.celery_tasks import app as celery_app
1013
from osf.metadata.osfmap_utils import osfid_from_iri
1114
from osf.metrics.utils import (
1215
get_database_iri,
@@ -23,6 +26,11 @@
2326
)
2427

2528

29+
@celery_app.task()
30+
def delete_expired_djelme_indexes():
31+
call_command('djelme_indexes', '--delete-expired', '--really-really')
32+
33+
2634
###
2735
# inner objects for events
2836

@@ -94,6 +102,7 @@ class OsfCountedUsageEvent(djelme.CountedUsageRecord):
94102

95103
class Meta:
96104
timeseries_index_timedepth = MONTHLY
105+
timeseries_index_expiration = datetime.timedelta(days=django_settings.OSF_USAGEEVENT_EXPIRATION_DAYS)
97106

98107
class ActionLabel(enum.Enum):
99108
SEARCH = 'search' # counter:Search

osf/metrics/monthly_reports.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
###
2424
# base class
2525

26-
class BaseMonthlyReport(djelme.CyclicRecord):
26+
class BaseMonthlyReport(djelme.CyclicReport):
2727
CYCLE_TIMEDEPTH = MONTHLY
2828

2929
class Meta:

osf/metrics/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from hashlib import sha256
77
from typing import ClassVar
88

9-
from elasticsearch_metrics.util.timeparts import format_timeparts
9+
from elasticsearch_metrics.util.timeparts import serialize_timeparts
1010

1111
from osf.metadata.osfmap_utils import (
1212
osfmap_type,
@@ -22,7 +22,7 @@ def cycle_coverage_date(given_date: datetime.date) -> str:
2222
>>> cycle_coverage_date(datetime.datetime(7654, 3, 2, 1))
2323
'7654.3.2'
2424
"""
25-
return format_timeparts(given_date, 3)
25+
return serialize_timeparts((given_date.year, given_date.month, given_date.day), 3)
2626

2727

2828
def cycle_coverage_yearmonth(given_ym: YearMonth | datetime.date) -> str:
@@ -32,7 +32,7 @@ def cycle_coverage_yearmonth(given_ym: YearMonth | datetime.date) -> str:
3232
>>> cycle_coverage_yearmonth(datetime.date(1234, 5, 6))
3333
'1234.5'
3434
"""
35-
return format_timeparts((given_ym.year, given_ym.month), 2)
35+
return serialize_timeparts((given_ym.year, given_ym.month), 2)
3636

3737

3838
def stable_key(*key_parts):

osf_tests/metrics/reporters/_testutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from elasticsearch_metrics.imps.elastic8 import CyclicRecord
1+
from elasticsearch_metrics.imps.elastic8 import CyclicReport
22

33
from osf.metrics.reporters._base import MonthlyReporter
44

55

6-
def list_monthly_reports(reporter: MonthlyReporter) -> list[CyclicRecord]:
6+
def list_monthly_reports(reporter: MonthlyReporter) -> list[CyclicReport]:
77
_each_reports_list = (
88
reporter.report(**_kwargs)
99
for _kwargs in reporter.iter_report_kwargs()

poetry.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ datacite = "1.1.3"
8989
rdflib = "7.0.0"
9090
colorlog = "6.8.2"
9191
# Metrics
92-
django-elasticsearch-metrics = {git ="https://github.com/CenterForOpenScience/django-elasticsearch-metrics.git", rev = "46890bb61d35459e9793eba92d9ae54d4ce9c6af"}
92+
django-elasticsearch-metrics = {git ="https://github.com/CenterForOpenScience/django-elasticsearch-metrics.git", rev = "22cea2531783d3f06da3f4407624aae0bbb50c02"}
9393
# Impact Metrics CSV Export
9494
djangorestframework-csv = "3.0.2"
9595
gevent = "24.2.1"

website/settings/defaults.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,10 @@ class CeleryConfig:
728728
'schedule': crontab(minute=0, hour=5), # Daily 12 a.m
729729
'kwargs': {'dry_run': False},
730730
},
731+
'delete_expired_djelme_indexes': {
732+
'task': 'osf.metrics.events.delete_expired_djelme_indexes',
733+
'schedule': crontab(minute=30, hour=7, day_of_month=5), # Fifth day of month 2:30 a.m. EST
734+
},
731735
}
732736

733737

0 commit comments

Comments
 (0)