Skip to content

Commit af0dfae

Browse files
authored
Merge pull request #11644 from bodintsov/feature/add-djelme
[ENG-9702] Feature/OSF to use latest djelme
2 parents 231bf1b + 5ea0ed1 commit af0dfae

28 files changed

Lines changed: 169 additions & 156 deletions

.docker-compose.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ INTERNAL_DOMAIN=http://192.168.168.167:5000/
77
API_DOMAIN=http://localhost:8000/
88
ELASTIC_URI=192.168.168.167:9200
99
ELASTIC6_URI=192.168.168.167:9201
10+
ELASTIC8_URI=http://192.168.168.167:9202
1011
OSF_DB_HOST=192.168.168.167
1112
DB_HOST=192.168.168.167
1213
REDIS_HOST=redis://192.168.168.167:6379

addons/base/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import waffle
1515
from django.db import transaction
1616
from django.contrib.contenttypes.models import ContentType
17-
from elasticsearch import exceptions as es_exceptions
17+
from elasticsearch6 import exceptions as es_exceptions
1818
from rest_framework import status as http_status
1919

2020
from api.caching.tasks import update_storage_usage_with_size

api/base/elasticsearch_dsl_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import typing
55

6-
import elasticsearch_dsl as edsl
6+
import elasticsearch6_dsl as edsl
77
from rest_framework import generics, exceptions as drf_exceptions
88
from rest_framework.settings import api_settings as drf_settings
99
from api.base.settings.defaults import REPORT_FILENAME_FORMAT
@@ -23,7 +23,7 @@
2323

2424

2525
class ElasticsearchListView(FilterMixin, JSONAPIBaseView, generics.ListAPIView, abc.ABC):
26-
'''abstract view class using `elasticsearch_dsl.Search` as a queryset-analogue
26+
'''abstract view class using `elasticsearch6_dsl.Search` as a queryset-analogue
2727
2828
builds a `Search` based on `self.get_default_search()` and the request's
2929
query parameters for filtering, sorting, and pagination -- fetches only
@@ -36,7 +36,7 @@ class ElasticsearchListView(FilterMixin, JSONAPIBaseView, generics.ListAPIView,
3636

3737
@abc.abstractmethod
3838
def get_default_search(self) -> edsl.Search | None:
39-
'''the base `elasticsearch_dsl.Search` for this list, based on url path
39+
'''the base `elasticsearch6_dsl.Search` for this list, based on url path
4040
4141
(common jsonapi query parameters will be considered automatically)
4242
'''
@@ -95,7 +95,7 @@ def finalize_response(self, request, response, *args, **kwargs):
9595
# (filtering handled in-view to reuse logic from FilterMixin)
9696
filter_backends = ()
9797

98-
# note: because elasticsearch_dsl.Search supports slicing and gives results when iterated on,
98+
# note: because elasticsearch6_dsl.Search supports slicing and gives results when iterated on,
9999
# it works fine with default pagination
100100

101101
# override rest_framework.generics.GenericAPIView

api/base/settings/defaults.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,18 @@
316316
HASHIDS_SALT = 'pinkhimalayan'
317317

318318
# django-elasticsearch-metrics
319-
ELASTICSEARCH_DSL = {
320-
'default': {
321-
'hosts': osf_settings.ELASTIC6_URI,
322-
'retry_on_timeout': True,
319+
DJELME_AUTOSETUP = True
320+
DJELME_BACKENDS = {
321+
'osfmetrics_es6': {
322+
'elasticsearch_metrics.imps.elastic6': {
323+
'hosts': osf_settings.ELASTIC6_URI,
324+
'retry_on_timeout': True,
325+
},
326+
},
327+
'osfmetrics_es8': {
328+
'elasticsearch_metrics.imps.elastic8': {
329+
'hosts': osf_settings.ELASTIC8_URI,
330+
},
323331
},
324332
}
325333
# Store yearly indices for time-series metrics

api/metrics/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from django.http import JsonResponse, HttpResponse, Http404
77
from django.utils import timezone
88

9-
from elasticsearch.exceptions import NotFoundError, RequestError
10-
from elasticsearch_dsl.connections import get_connection
9+
from elasticsearch6.exceptions import NotFoundError, RequestError
10+
from elasticsearch6_dsl.connections import get_connection
1111

1212
from framework.auth.oauth_scopes import CoreScopes
1313

api_tests/institutions/views/test_institution_department_list.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def populate_counts(self, user, user2, user3, user4, admin, institution):
4444
department_name='Old Department',
4545
public_project_count=1,
4646
private_project_count=1,
47-
).save(refresh=True)
47+
).save()
4848

4949
_this_month = YearMonth.from_date(datetime.date.today())
5050

@@ -56,7 +56,7 @@ def populate_counts(self, user, user2, user3, user4, admin, institution):
5656
department_name='New Department',
5757
public_project_count=1,
5858
private_project_count=1,
59-
).save(refresh=True)
59+
).save()
6060

6161
# A second user entered the department
6262
InstitutionalUserReport(
@@ -66,7 +66,7 @@ def populate_counts(self, user, user2, user3, user4, admin, institution):
6666
department_name='New Department',
6767
public_project_count=1,
6868
private_project_count=1,
69-
).save(refresh=True)
69+
).save()
7070

7171
# A new department with a single user to test sorting
7272
InstitutionalUserReport(
@@ -76,7 +76,7 @@ def populate_counts(self, user, user2, user3, user4, admin, institution):
7676
department_name='Smaller Department',
7777
public_project_count=1,
7878
private_project_count=1,
79-
).save(refresh=True)
79+
).save()
8080

8181
# A user with no department
8282
InstitutionalUserReport(
@@ -85,7 +85,7 @@ def populate_counts(self, user, user2, user3, user4, admin, institution):
8585
institution_id=institution._id,
8686
public_project_count=1,
8787
private_project_count=1,
88-
).save(refresh=True)
88+
).save()
8989

9090
@pytest.fixture()
9191
def admin(self, institution):
@@ -113,6 +113,7 @@ def test_auth(self, app, url, user, admin):
113113
assert resp.json['data'] == []
114114

115115
def test_get(self, app, url, admin, institution, populate_counts):
116+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
116117
resp = app.get(url, auth=admin.auth)
117118

118119
assert resp.json['data'] == [{

api_tests/institutions/views/test_institution_summary_metrics.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def test_get_empty(self, app, url, institutional_admin):
8484
assert resp.json['meta'] == {'version': '2.0'}
8585

8686
def test_get_report(self, app, url, institutional_admin, institution, reports, unshown_reports):
87+
InstitutionMonthlySummaryReport._get_connection().indices.refresh(InstitutionMonthlySummaryReport._template_pattern)
8788
resp = app.get(url, auth=institutional_admin.auth)
8889
assert resp.status_code == 200
8990

@@ -149,6 +150,7 @@ def test_get_report_with_multiple_months_and_institutions(
149150
monthly_logged_in_user_count=270,
150151
monthly_active_user_count=260,
151152
)
153+
InstitutionMonthlySummaryReport._get_connection().indices.refresh(InstitutionMonthlySummaryReport._template_pattern)
152154

153155
resp = app.get(url, auth=institutional_admin.auth)
154156
assert resp.status_code == 200
@@ -189,6 +191,7 @@ def test_get_with_valid_report_dates(self, app, url, institution, institutional_
189191
institution,
190192
user_count=4133,
191193
)
194+
InstitutionMonthlySummaryReport._get_connection().indices.refresh(InstitutionMonthlySummaryReport._template_pattern)
192195

193196
resp = app.get(f'{url}?report_yearmonth=2024-08', auth=institutional_admin.auth)
194197
assert resp.status_code == 200
@@ -213,6 +216,7 @@ def test_get_with_invalid_report_date(self, app, url, institution, institutional
213216
institution,
214217
user_count=999,
215218
)
219+
InstitutionMonthlySummaryReport._get_connection().indices.refresh(InstitutionMonthlySummaryReport._template_pattern)
216220

217221
# Request with an invalid report_date format
218222
resp = app.get(f'{url}?report_yearmonth=invalid-date', auth=institutional_admin.auth)
@@ -233,6 +237,7 @@ def test_get_without_report_date_uses_most_recent(self, app, url, institution, i
233237
institution,
234238
user_count=999,
235239
)
240+
InstitutionMonthlySummaryReport._get_connection().indices.refresh(InstitutionMonthlySummaryReport._template_pattern)
236241

237242
resp = app.get(url, auth=institutional_admin.auth)
238243
assert resp.status_code == 200
@@ -247,5 +252,5 @@ def _summary_report_factory(yearmonth, institution, **kwargs):
247252
institution_id=institution._id,
248253
**kwargs,
249254
)
250-
report.save(refresh=True)
255+
report.save()
251256
return report

api_tests/institutions/views/test_institution_user_metric_list.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_get_empty(self, app, url, institutional_admin):
8989
assert _resp.json['data'] == []
9090

9191
def test_get_reports(self, app, url, institutional_admin, institution, reports, unshown_reports):
92+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
9293
_resp = app.get(url, auth=institutional_admin.auth)
9394
assert _resp.status_code == 200
9495
assert len(_resp.json['data']) == len(reports)
@@ -100,6 +101,7 @@ def test_get_reports(self, app, url, institutional_admin, institution, reports,
100101
assert len(response_object['attributes']['contacts']) == 0
101102

102103
def test_filter_reports(self, app, url, institutional_admin, institution, reports, unshown_reports):
104+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
103105
for _query, _expected_user_ids in (
104106
({'filter[department]': 'nunavum'}, set()),
105107
({'filter[department]': 'incidentally'}, set()),
@@ -135,6 +137,7 @@ def test_filter_reports(self, app, url, institutional_admin, institution, report
135137
assert set(_user_ids(_resp)) == _expected_user_ids
136138

137139
def test_sort_reports(self, app, url, institutional_admin, institution, reports, unshown_reports):
140+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
138141
for _query, _expected_user_id_list in (
139142
({'sort': 'storage_byte_count'}, ['u_sparse', 'u_orc', 'u_blargl', 'u_orcomma']),
140143
({'sort': '-storage_byte_count'}, ['u_orcomma', 'u_blargl', 'u_orc', 'u_sparse']),
@@ -144,6 +147,7 @@ def test_sort_reports(self, app, url, institutional_admin, institution, reports,
144147
assert list(_user_ids(_resp)) == _expected_user_id_list
145148

146149
def test_paginate_reports(self, app, url, institutional_admin, institution, reports, unshown_reports):
150+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
147151
for _query, _expected_user_id_list in (
148152
({'sort': 'storage_byte_count', 'page[size]': 2}, ['u_sparse', 'u_orc']),
149153
({'sort': 'storage_byte_count', 'page[size]': 2, 'page': 2}, ['u_blargl', 'u_orcomma']),
@@ -178,6 +182,7 @@ def test_get_report_formats_csv_tsv(self, app, url, institutional_admin, institu
178182
month_last_active='2018-02',
179183
month_last_login='2018-02',
180184
)
185+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
181186

182187
resp = app.get(f'{url}?format={format_type}', auth=institutional_admin.auth)
183188
assert resp.status_code == 200
@@ -281,6 +286,7 @@ def test_csv_tsv_ignores_pagination(self, app, url, institutional_admin, institu
281286
str(736662999298 + i),
282287
f'Jalen Hurts #{i}',
283288
])
289+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
284290

285291
# Make request for CSV format with page[size]=10
286292
resp = app.get(f'{url}?format={format_type}', auth=institutional_admin.auth)
@@ -346,6 +352,7 @@ def test_get_report_format_table_json(self, app, url, institutional_admin, insti
346352
month_last_active='2018-02',
347353
month_last_login='2018-02',
348354
)
355+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
349356

350357
resp = app.get(f'{url}?format=json_report', auth=institutional_admin.auth)
351358
assert resp.status_code == 200
@@ -411,6 +418,7 @@ def test_correct_number_of_contact_messages(self, app, url, institutional_admin,
411418
department_name='a department, or so, that happens, incidentally, to have commas',
412419
storage_byte_count=736662999298,
413420
)
421+
InstitutionalUserReport._get_connection().indices.refresh(InstitutionalUserReport._template_pattern)
414422

415423
receiver = user1
416424
with capture_notifications():
@@ -477,5 +485,5 @@ def _report_factory(yearmonth, institution, **kwargs):
477485
institution_id=institution._id,
478486
**kwargs,
479487
)
480-
_report.save(refresh=True)
488+
_report.save()
481489
return _report

api_tests/metrics/test_composite_query.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import time
21
import pytest
32
from datetime import datetime
43
from osf_tests.factories import (
@@ -75,7 +74,7 @@ def test_elasticsearch_agg_query(self, app, user, base_url, preprint):
7574
path=preprint.primary_file.path,
7675
timestamp=datetime(year=2020, month=2, day=1)
7776
)
78-
time.sleep(1) # gives ES some time to update
77+
PreprintDownload._get_connection().indices.refresh(PreprintDownload._template_pattern)
7978

8079
resp = app.post_json_api(post_url, payload, auth=user.auth)
8180
assert resp.status_code == 200

api_tests/metrics/test_preprint_metrics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from django.utils import timezone
1010
from waffle.testutils import override_switch
11-
from elasticsearch.exceptions import RequestError
11+
from elasticsearch6.exceptions import RequestError
1212

1313
from osf import features
1414
from api.base.settings import API_PRIVATE_BASE as API_BASE

0 commit comments

Comments
 (0)