Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
674f963
wip: es8 djelme records (migration targets)
aaxelb Mar 25, 2026
2e73161
add new metrics
bodintsov Mar 31, 2026
4b4a478
fix flake8
bodintsov Apr 6, 2026
d3b48e4
add tests, use new version of djelme, consolidate into OsfCountedUsag…
bodintsov Apr 8, 2026
e4bec9d
add imports to init, flake8
bodintsov Apr 9, 2026
ee515ef
fix test, imports, flake8
bodintsov Apr 9, 2026
ca60b58
add security, flake8, fixes, add to test-build.yml
bodintsov Apr 10, 2026
080daf6
test-build update
bodintsov Apr 10, 2026
fde32a4
test-build fix url
bodintsov Apr 10, 2026
e6da70b
test-build fix naming
bodintsov Apr 10, 2026
2b8a81c
update test
bodintsov Apr 11, 2026
6167778
add wait
bodintsov Apr 13, 2026
eb0a5d9
remove wait
bodintsov Apr 13, 2026
78ed96f
cleanup
bodintsov Apr 14, 2026
70cf5e2
add wait, downgrade djelme, flake8
bodintsov Apr 14, 2026
3e35fee
add elastic8
bodintsov Apr 14, 2026
a236342
fix test
bodintsov Apr 14, 2026
00b055b
timedepth constants
aaxelb Apr 14, 2026
dddc94e
tidy gh actions with yaml anchors, health checks
aaxelb Apr 14, 2026
46a934f
simplify local elasticsearch8 config
aaxelb Apr 14, 2026
49f9259
bump djelme to get fixes
aaxelb Apr 14, 2026
29839b9
tests passing with djelme es8
aaxelb Apr 14, 2026
619cac7
fix(test): patch check_index_template
aaxelb Apr 14, 2026
8cec095
uncomment autouse fixture
aaxelb Apr 14, 2026
c24430f
remove unnecessary loop
aaxelb Apr 14, 2026
cd32827
plac8 flake8
aaxelb Apr 14, 2026
db938be
remove unused local env vars
aaxelb Apr 14, 2026
52a2bc9
better use waffle switch ELASTICSEARCH_METRICS
aaxelb Apr 14, 2026
82de65b
mock check mock save
aaxelb Apr 14, 2026
b33280d
remove the override
bodintsov Apr 15, 2026
1cef7d3
fix failing test
bodintsov Apr 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .docker-compose.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ API_DOMAIN=http://localhost:8000/
ELASTIC_URI=192.168.168.167:9200
ELASTIC6_URI=192.168.168.167:9201
ELASTIC8_URI=http://192.168.168.167:9202
ELASTIC8_USERNAME=elastic
OSF_DB_HOST=192.168.168.167
DB_HOST=192.168.168.167
REDIS_HOST=redis://192.168.168.167:6379
Expand Down
103 changes: 27 additions & 76 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,19 @@ jobs:
permissions:
checks: write
services:
postgres:
elasticsearch8: &ES8_SERVICE
image: elasticsearch:8.19.14
ports:
- 9202:9200
env:
discovery.type: single-node
xpack.security.enabled: false
options: >-
--health-cmd "curl -sf http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=30s"
--health-interval 10s
--health-timeout 30s
--health-retries 5
postgres: &POSTGRES_SERVICE
image: postgres
env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
Expand All @@ -54,6 +66,8 @@ jobs:
- uses: ./.github/actions/start-build
- name: Run tests
run: poetry run python3 -m invoke test-ci-addons --junit
env:
ELASTIC8_URI: http://localhost:9202
- name: Upload report
if: (success() || failure()) # run this step even if previous step failed
uses: ./.github/actions/gen-report
Expand All @@ -64,18 +78,7 @@ jobs:
permissions:
checks: write
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
postgres: *POSTGRES_SERVICE
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
Expand All @@ -91,25 +94,17 @@ jobs:
permissions:
checks: write
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
elasticsearch8: *ES8_SERVICE
postgres: *POSTGRES_SERVICE
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
- name: NVM & yarn install
run: poetry run python3 -m invoke assets --dev
- name: Run test
run: poetry run python3 -m invoke test-ci-api1-and-js --junit
env:
ELASTIC8_URI: http://localhost:9202
- name: Upload report
if: (success() || failure()) # run this step even if previous step failed
uses: ./.github/actions/gen-report
Expand All @@ -120,23 +115,15 @@ jobs:
permissions:
checks: write
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
elasticsearch8: *ES8_SERVICE
postgres: *POSTGRES_SERVICE
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
- name: Run tests
run: poetry run python3 -m invoke test-ci-api2 --junit
env:
ELASTIC8_URI: http://localhost:9202
- name: Upload report
if: (success() || failure()) # run this step even if previous step failed
uses: ./.github/actions/gen-report
Expand All @@ -147,19 +134,7 @@ jobs:
checks: write
needs: build-cache
services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
postgres: *POSTGRES_SERVICE
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
Expand All @@ -175,19 +150,7 @@ jobs:
checks: write
needs: build-cache
services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
postgres: *POSTGRES_SERVICE
mailhog:
image: mailhog/mailhog
ports:
Expand All @@ -208,19 +171,7 @@ jobs:
checks: write
needs: build-cache
services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: ${{ env.OSF_DB_PASSWORD }}
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
postgres: *POSTGRES_SERVICE
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/start-build
Expand Down
7 changes: 6 additions & 1 deletion api/base/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@
HASHIDS_SALT = 'pinkhimalayan'

# django-elasticsearch-metrics
DJELME_AUTOSETUP = True
DJELME_BACKENDS = {
'osfmetrics_es6': {
'elasticsearch_metrics.imps.elastic6': {
Expand All @@ -327,6 +326,12 @@
'osfmetrics_es8': {
'elasticsearch_metrics.imps.elastic8': {
'hosts': osf_settings.ELASTIC8_URI,
'ca_certs': osf_settings.ELASTIC8_CERT_PATH,
'basic_auth': (
(osf_settings.ELASTIC8_USERNAME, osf_settings.ELASTIC8_SECRET)
if osf_settings.ELASTIC8_SECRET is not None
else None
),
},
},
}
Expand Down
5 changes: 3 additions & 2 deletions api_tests/metrics/test_counted_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ def assert_saved_with(mock_save, *, expected_doc_id=None, expected_attrs):

@pytest.fixture
def mock_save():
with mock.patch('elasticsearch6_dsl.Document.save', autospec=True) as mock_save:
yield mock_save
with mock.patch('elasticsearch_metrics.imps.elastic6.BaseMetric.check_index_template'):
with mock.patch('elasticsearch6_dsl.Document.save', autospec=True) as mock_save:
yield mock_save


@pytest.mark.django_db
Expand Down
12 changes: 0 additions & 12 deletions api_tests/metrics/test_registries_moderation_metrics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest
from waffle.testutils import override_switch

from osf import features
from osf_tests.factories import RegistrationFactory, AuthUserFactory
from osf.utils.workflows import RegistrationModerationStates, RegistrationModerationTriggers
from osf.metrics import RegistriesModerationMetrics
Expand All @@ -17,11 +15,6 @@ class TestRegistrationModerationMetrics:
def registration(self):
return RegistrationFactory()

@pytest.fixture(autouse=True)
def enable_elasticsearch_metrics(self):
with override_switch(features.ELASTICSEARCH_METRICS, active=True):
yield

@pytest.mark.es_metrics
def test_record_transitions(self, registration):
with capture_notifications():
Expand Down Expand Up @@ -50,11 +43,6 @@ class TestRegistrationModerationMetricsView:
def registration(self):
return RegistrationFactory()

@pytest.fixture(autouse=True)
def enable_elasticsearch_metrics(self):
with override_switch(features.ELASTICSEARCH_METRICS, active=True):
yield

@pytest.fixture
def user(self):
user = AuthUserFactory()
Expand Down
23 changes: 9 additions & 14 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@

from django.db import transaction
from elasticsearch6_dsl.connections import connections
from website import settings as osf_settings
from elasticsearch_metrics.tests._test_util import RealElasticTestCase
from elasticsearch_metrics.tests.util import djelme_test_backends
from faker import Factory
import pytest
import responses
import xml.etree.ElementTree as ET
from waffle.testutils import override_switch

from api_tests.share import _utils as shtrove_test_utils
from framework.celery_tasks import app as celery_app
from osf.external.spam import tasks as spam_tasks
from website import settings as website_settings
from osf.management.commands.populate_notification_types import populate_notification_types
from osf import features


def pytest_configure(config):
if not os.getenv('GITHUB_ACTIONS') == 'true':
Expand Down Expand Up @@ -146,19 +148,12 @@ def _es_metrics_marker(request):
yield
return

connections.create_connection(
alias='osfmetrics_es6',
hosts=osf_settings.ELASTIC6_URI,
)

class _Es6TestCase(RealElasticTestCase, autosetup_djelme_backends=True):
...
es6_test_case = _Es6TestCase()
es6_test_case.setUp()
try:
with (
override_switch(features.ELASTICSEARCH_METRICS, active=True),
djelme_test_backends(),
):
yield
finally:
es6_test_case.tearDown()


@pytest.fixture
def mock_share_responses():
Expand Down
13 changes: 10 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,22 @@ services:
stdin_open: true

elasticsearch8:
image: docker.elastic.co/elasticsearch/elasticsearch:8.19.11
platform: linux/arm64
image: elasticsearch:8.19.14
environment:
- xpack.security.enabled=false
- discovery.type=single-node
- xpack.security.enabled=false
- ES_JAVA_OPTS=-Xms512m -Xmx512m # reduce memory usage
- xpack.ml.enabled=false
ports:
- 9202:9200
volumes:
- elasticsearch8_data_vol:/usr/share/elasticsearch/data
healthcheck:
start_period: 15s
test: ["CMD", "curl", "-sf", "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=30s"]
interval: 10s
timeout: 30s
retries: 5
stdin_open: true

postgres:
Expand Down
3 changes: 3 additions & 0 deletions osf/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
StorageAddonUsage,
UserSummaryReport,
)
from . import es8_metrics


DAILY_REPORTS = (
DownloadCountReport,
Expand All @@ -36,4 +38,5 @@
'PreprintView',
'PreprintDownload',
'RegistriesModerationMetrics',
'es8_metrics',
)
Loading
Loading