Skip to content

Commit b06f6eb

Browse files
authored
Merge pull request #11699 from aaxelb/9706-metrics-migration
[ENG-9706] migrate_osfmetrics_6to8
2 parents 6c45a66 + c186373 commit b06f6eb

13 files changed

Lines changed: 1016 additions & 35 deletions

File tree

api/base/settings/defaults.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,16 @@
325325
},
326326
'osfmetrics_es8': {
327327
'elasticsearch_metrics.imps.elastic8': {
328+
# passthru kwargs to elasticsearch8 connection constructor
328329
'hosts': osf_settings.ELASTIC8_URI,
329330
'ca_certs': osf_settings.ELASTIC8_CERT_PATH,
330331
'basic_auth': (
331332
(osf_settings.ELASTIC8_USERNAME, osf_settings.ELASTIC8_SECRET)
332333
if osf_settings.ELASTIC8_SECRET is not None
333334
else None
334335
),
336+
# djelme-specific kwargs
337+
'djelme_default_index_name_prefix': osf_settings.SHARE_PROVIDER_PREPEND,
335338
},
336339
},
337340
}

conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def pytest_configure(config):
4343
'transitions.core',
4444
'MARKDOWN',
4545
'elasticsearch',
46+
'elastic_transport',
47+
'elasticsearch_metrics',
4648
]
4749
for logger_name in SILENT_LOGGERS:
4850
logging.getLogger(logger_name).setLevel(logging.CRITICAL)

docker-compose.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,17 @@ services:
7272
# Temporary: Remove when we've upgraded to ES6
7373
elasticsearch6:
7474
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.1
75+
environment:
76+
- ES_JAVA_OPTS=-Xms512m -Xmx512m # reduce memory usage
7577
ports:
7678
- 9201:9200
7779
volumes:
7880
- elasticsearch6_data_vol:/usr/share/elasticsearch/data
81+
healthcheck:
82+
start_period: 15s
83+
test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'
84+
interval: 10s
85+
retries: 30
7986
stdin_open: true
8087

8188
elasticsearch8:
@@ -91,10 +98,9 @@ services:
9198
- elasticsearch8_data_vol:/usr/share/elasticsearch/data
9299
healthcheck:
93100
start_period: 15s
94-
test: ["CMD", "curl", "-sf", "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=30s"]
101+
test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'
95102
interval: 10s
96-
timeout: 30s
97-
retries: 5
103+
retries: 30
98104
stdin_open: true
99105

100106
postgres:

framework/celery_tasks/routers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def match_by_module(task_path):
1111
return CeleryConfig.task_med_queue
1212
if task_subpath in CeleryConfig.high_pri_modules:
1313
return CeleryConfig.task_high_queue
14+
if task_subpath in CeleryConfig.background_migration_modules:
15+
return CeleryConfig.task_background_migration_queue
1416
if task_subpath in CeleryConfig.remote_computing_modules:
1517
return CeleryConfig.task_remote_computing_queue
1618
if task_subpath in CeleryConfig.account_status_changes_modules:

osf/management/commands/fake_metrics_reports.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
UserSummaryReport,
99
PreprintSummaryReport,
1010
)
11+
from osf.metrics.reports import PublicItemUsageReport
12+
from osf.metrics.utils import YearMonth
1113
from osf.models import PreprintProvider
1214

1315

@@ -53,10 +55,27 @@ def fake_preprint_counts(days_back):
5355
).save()
5456

5557

58+
def fake_usage_reports(osfid: str, count: int):
59+
_ym = YearMonth.from_date(date.today()).prior()
60+
for _months in range(count):
61+
PublicItemUsageReport.record(
62+
item_osfid=osfid,
63+
report_yearmonth=_ym,
64+
view_count=(_vc := randint(0, 500)),
65+
view_session_count=randint(0, _vc),
66+
download_count=(_dc := randint(0, 300)),
67+
download_session_count=randint(0, _dc),
68+
)
69+
_ym = _ym.prior()
70+
71+
5672
class Command(BaseCommand):
5773
def handle(self, *args, **kwargs):
5874
if not settings.DEBUG:
5975
raise NotImplementedError('fake_reports requires DEBUG mode')
6076
fake_user_counts(1000)
6177
fake_preprint_counts(1000)
78+
fake_usage_reports('blarg', 100)
79+
fake_usage_reports('blerg', 50)
80+
fake_usage_reports('bleg', 50)
6281
# TODO: more reports

0 commit comments

Comments
 (0)