Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 143ad47

Browse files
authored
build: add analytics api to devstack (#495)
Some settings to inherit env vars from devstack. Running make commands with tox is now optional.
1 parent 974f67f commit 143ad47

7 files changed

Lines changed: 74 additions & 43 deletions

File tree

.travis.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@ install:
1212
- pip install -r requirements/travis.txt
1313
script:
1414
- docker exec -t -e TRAVIS=1 analytics_api_testing bash -c " cd /edx/app/analytics_api/analytics_api/
15-
&& make $TARGETS "
15+
&& export TOXENV=django32 && make test.requirements tox.requirements $TARGETS "
1616
matrix:
1717
include:
1818
- python: '3.8'
19-
env: TESTNAME=quality-python-3.8 TARGETS="PYTHON_ENV=py38 quality"
19+
env: TESTNAME=quality-python-3.8 TARGETS="quality"
2020
- python: '3.8'
21-
env: TESTNAME=test-python-3.8 TARGETS="PYTHON_ENV=py38 main.test"
22-
- python: '3.8'
23-
env: TESTNAME=test-python-3.8-django-3.0 TARGETS="PYTHON_ENV=py38 DJANGO_VERSION=django32
24-
main.test"
21+
env: TESTNAME=test-python-3.8 TARGETS="main.test"
2522
after_success:
2623
- docker exec analytics_api_testing /edx/app/analytics_api/analytics_api/.travis/run_coverage.sh
2724
- codecov --disable pycov

Makefile

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
ROOT = $(shell echo "$$PWD")
22
COVERAGE_DIR = $(ROOT)/build/coverage
3-
PACKAGES = analyticsdataserver analytics_data_api
43
DATABASES = default analytics
5-
PYTHON_ENV=py38
6-
DJANGO_VERSION=django32
74
.DEFAULT_GOAL := help
85

6+
TOX=''
7+
8+
ifdef TOXENV
9+
TOX := tox -- #to isolate each tox environment if TOXENV is defined
10+
endif
11+
912
help: ## display this help message
1013
@echo "Please use \`make <target>' where <target> is one of"
1114
@perl -nle'print $& if m{^[\.a-zA-Z_-]+:.*?## .*$$}' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-25s\033[0m %s\n", $$1, $$2}'
@@ -28,7 +31,7 @@ test.requirements: requirements ## install base and test requirements
2831
pip3 install -q -r requirements/test.txt
2932

3033
tox.requirements: ## install tox requirements
31-
pip3 install -q -r requirements/tox.txt
34+
pip3 install -q -r requirements/tox.txt
3235

3336
develop: test.requirements ## install test and dev requirements
3437
pip3 install -q -r requirements/dev.txt
@@ -58,16 +61,21 @@ upgrade:
5861
mv requirements/test.tmp requirements/test.txt
5962

6063

61-
clean: tox.requirements ## install tox requirements and run tox clean. Delete *.pyc files
62-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-clean
64+
clean:
65+
$(TOX)coverage erase
6366
find . -name '*.pyc' -delete
6467

65-
main.test: tox.requirements clean
66-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-tests
68+
main.test: clean
6769
export COVERAGE_DIR=$(COVERAGE_DIR) && \
68-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-coverage
70+
$(TOX)pytest --cov-report html --cov-report xml
6971

72+
test:
73+
74+
ifeq ($(DJANGO_SETTINGS_MODULE),analyticsdataserver.settings.devstack)
75+
test: main.test
76+
else
7077
test: test.run_elasticsearch main.test test.stop_elasticsearch
78+
endif
7179

7280
diff.report: test.requirements ## Show the diff in quality and coverage
7381
diff-cover $(COVERAGE_DIR)/coverage.xml --html-report $(COVERAGE_DIR)/diff_cover.html
@@ -79,19 +87,19 @@ view.diff.report: ## Show the diff in quality and coverage using xdg
7987
xdg-open file:///$(COVERAGE_DIR)/diff_quality_pycodestyle.html
8088
xdg-open file:///$(COVERAGE_DIR)/diff_quality_pylint.html
8189

82-
run_check_isort: tox.requirements ## Run tox check_isort. (Installs tox requirements.)
83-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-check_isort
90+
run_check_isort:
91+
$(TOX)isort --check-only --recursive --diff analytics_data_api/ analyticsdataserver/
8492

85-
run_pycodestyle: tox.requirements ## Run tox pycodestyle. (Installs tox requirements.)
86-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-pycodestyle
93+
run_pycodestyle:
94+
$(TOX)pycodestyle --config=.pycodestyle analytics_data_api analyticsdataserver
8795

88-
run_pylint: tox.requirements ## Run tox pylint. (Installs tox requirements.)
89-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-pylint
96+
run_pylint:
97+
$(TOX)pylint -j 0 --rcfile=pylintrc analytics_data_api analyticsdataserver
9098

91-
run_isort: tox.requirements ## Run tox isort. (Installs tox requirements.)
92-
tox -e $(PYTHON_ENV)-$(DJANGO_VERSION)-isort
99+
run_isort:
100+
$(TOX)isort --recursive analytics_data_api/ analyticsdataserver/
93101

94-
quality: tox.requirements run_pylint run_check_isort run_pycodestyle ## run_pylint, run_check_isort, run_pycodestyle (Installs tox requirements.)
102+
quality: run_pylint run_check_isort run_pycodestyle ## run_pylint, run_check_isort, run_pycodestyle (Installs tox requirements.)
95103

96104
validate: test.requirements test quality ## Runs make test and make quality. (Installs test requirements.)
97105

@@ -108,6 +116,9 @@ loaddata: migrate ## Runs migrations and generates fake data
108116
python manage.py loaddata problem_response_answer_distribution --database=analytics
109117
python manage.py generate_fake_course_data
110118

119+
create_indices: ## Create ElasticSearch indices
120+
python manage.py create_elasticsearch_learners_indices
121+
111122
demo: clean requirements loaddata ## Runs make clean, requirements, and loaddata, sets api key to edx
112123
python manage.py set_api_key edx edx
113124

@@ -134,6 +145,5 @@ travis_docker_push: travis_docker_tag travis_docker_auth ## push to docker hub
134145
docker push 'openedx/analytics-data-api:latest-newrelic'
135146
docker push "openedx/analytics-data-api:$$TRAVIS_COMMIT-newrelic"
136147

137-
docs:
138-
pip install -r requirements/tox.txt
148+
docs: tox.requirements
139149
tox -e docs

README.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@ unless otherwise noted.
1515

1616
Please see ``LICENSE.txt`` for details.
1717

18-
Getting Started
19-
---------------
18+
Getting Started With Devstack
19+
-----------------------------
20+
The best way to run this service is with edX Devstack: https://github.com/edx/devstack.
21+
22+
See the [Devstack README](https://github.com/edx/devstack/blob/master/README.rst) for information on how to install and run the analytics data api.
23+
24+
25+
Getting Started Standalone
26+
--------------------------
2027
#. Create a virtual environment and activate it.
2128

2229
#. Install the requirements:
@@ -74,6 +81,15 @@ Development with edx-enterprise-data
7481
If you need to make changes to ``edx-enterprise-data`` and have them reflected when you run the ``edx-analytics-data-api`` server,
7582
you can follow these steps. If you do not intend to make changes to ``edx-enterprise-data``, you can skip this section.
7683

84+
Devstack Development
85+
~~~~~~~~~~~~~~~~~~~~
86+
#. Clone the `edx-enterprise-data <https://github.com/edx/edx-enterprise-data>`_ repo into the ``src`` folder alongside your devstack
87+
workspace on the host system.
88+
#. The modified ``edx-enterprise-data`` repository will now be available to devstack containers at ``/edx/src/edx-enterprise-data``.
89+
#. Inside the ``edx-data-analytics-api`` container run `pip install `-e /edx/src/edx-enterprise-data``
90+
91+
Standalone Development
92+
~~~~~~~~~~~~~~~~~~~~~~
7793
#. Recommended: Install this repo into a subfolder of your working directory. Within that subfolder create an ``src`` folder.
7894
#. Clone the `edx-enterprise-data <https://github.com/edx/edx-enterprise-data>`_ repo into the ``src`` folder.
7995
#. ``cd`` into your ``edx-data-analytics-api`` folder and activate your virtualenv.

analyticsdataserver/settings/devstack.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""Devstack settings."""
22

3-
from analyticsdataserver.settings.local import *
3+
import os
44

5-
ALLOWED_HOSTS += ['edx.devstack.analyticsapi']
5+
from analyticsdataserver.settings.local import *
66

7+
########## DATABASE CONFIGURATION
78
DATABASES = {
89
'default': {
910
'ENGINE': 'django.db.backends.mysql',
@@ -23,5 +24,20 @@
2324
}
2425
}
2526

26-
ELASTICSEARCH_LEARNERS_HOST = "edx.devstack.elasticsearch"
27+
DB_OVERRIDES = dict(
28+
USER=os.environ.get('DB_USER', DATABASES['default']['USER']),
29+
PASSWORD=os.environ.get('DB_PASSWORD', DATABASES['default']['PASSWORD']),
30+
HOST=os.environ.get('DB_HOST', DATABASES['default']['HOST']),
31+
PORT=os.environ.get('DB_PORT', DATABASES['default']['PORT']),
32+
)
33+
34+
for override, value in DB_OVERRIDES.items():
35+
DATABASES['default'][override] = value
36+
DATABASES['analytics'][override] = value
37+
########## END DATABASE CONFIGURATION
38+
39+
ELASTICSEARCH_LEARNERS_HOST = os.environ.get('ELASTICSEARCH_LEARNERS_HOST', 'edx.devstack.elasticsearch')
40+
41+
ALLOWED_HOSTS += ['edx.devstack.analyticsapi']
42+
2743
LMS_BASE_URL = "http://edx.devstack.lms:18000/"

pytest.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[pytest]
2-
DJANGO_SETTINGS_MODULE = analyticsdataserver.settings.test
3-
addopts = --cov analytics_data_api --cov-report term-missing --cov-config=.coveragerc --no-cov-on-fail -p no:randomly
2+
addopts = --ds=analyticsdataserver.settings.test --cov analytics_data_api --cov-report term-missing --cov-config=.coveragerc --no-cov-on-fail -p no:randomly

requirements/pip_tools.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ click==8.0.1
88
# via pip-tools
99
pep517==0.11.0
1010
# via pip-tools
11-
pip-tools==6.3.0
11+
pip-tools==6.4.0
1212
# via -r requirements/pip_tools.in
1313
six==1.16.0
1414
# via -r requirements/pip_tools.in

tox.ini

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
skipsdist = True
3-
envlist = py38-django{22,32}-{check_isort,pycodestyle,pylint,isort,tests}
3+
envlist = py38-django{22,32}
44

55
[testenv]
66
passenv =
@@ -15,14 +15,7 @@ deps =
1515
django32: Django>=3.2,<3.3
1616
-r requirements/test.txt
1717
commands =
18-
check_isort: isort --check-only --recursive --diff analytics_data_api/ analyticsdataserver/
19-
isort: isort --recursive analytics_data_api/ analyticsdataserver/
20-
clean: coverage erase
21-
pycodestyle: pycodestyle --config=.pycodestyle analytics_data_api analyticsdataserver
22-
pylint: pylint -j 0 --rcfile=pylintrc analytics_data_api analyticsdataserver
23-
tests: python -Wd -m pytest {posargs}
24-
coverage: coverage html
25-
coverage: coverage xml
18+
{posargs:pytest}
2619

2720
[testenv:docs]
2821
deps =

0 commit comments

Comments
 (0)