platform-plugin-aspects 0.3.1__tar.gz → 0.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/CHANGELOG.rst +17 -0
- {platform-plugin-aspects-0.3.1/platform_plugin_aspects.egg-info → platform-plugin-aspects-0.5.0}/PKG-INFO +19 -1
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/__init__.py +1 -1
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/extensions/filters.py +2 -2
- platform-plugin-aspects-0.5.0/platform_plugin_aspects/management/commands/load_test_tracking_events.py +313 -0
- platform-plugin-aspects-0.5.0/platform_plugin_aspects/management/commands/monitor_load_test_tracking.py +438 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/settings/common.py +6 -1
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/settings/production.py +2 -4
- platform-plugin-aspects-0.5.0/platform_plugin_aspects/static/css/superset.css +53 -0
- platform-plugin-aspects-0.5.0/platform_plugin_aspects/static/html/superset.html +37 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/static/js/embed_dashboard.js +6 -3
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/templates/instructor_dashboard/aspects.html +1 -1
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/utils.py +13 -13
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/xblock.py +11 -2
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0/platform_plugin_aspects.egg-info}/PKG-INFO +19 -1
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/SOURCES.txt +2 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/requires.txt +1 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/requirements/base.in +1 -0
- platform-plugin-aspects-0.3.1/platform_plugin_aspects/static/css/superset.css +0 -5
- platform-plugin-aspects-0.3.1/platform_plugin_aspects/static/html/superset.html +0 -25
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/LICENSE +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/MANIFEST.in +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/README.rst +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/apps.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/extensions/__init__.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/management/__init__.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/management/commands/__init__.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/management/commands/dump_data_to_clickhouse.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/settings/__init__.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/signals.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/__init__.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/base_sink.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/course_overview_sink.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/external_id_sink.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/serializers.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/user_profile_sink.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/sinks/user_retire_sink.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/static/html/superset_student.html +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/static/js/install_required.js +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/static/js/superset.js +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/tasks.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects/waffle.py +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/dependency_links.txt +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/entry_points.txt +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/not-zip-safe +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/platform_plugin_aspects.egg-info/top_level.txt +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/requirements/constraints.txt +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/setup.cfg +0 -0
- {platform-plugin-aspects-0.3.1 → platform-plugin-aspects-0.5.0}/setup.py +0 -0
|
@@ -16,6 +16,23 @@ Unreleased
|
|
|
16
16
|
|
|
17
17
|
*
|
|
18
18
|
|
|
19
|
+
0.5.0 - 2024-04-01
|
|
20
|
+
******************
|
|
21
|
+
|
|
22
|
+
Added
|
|
23
|
+
=====
|
|
24
|
+
|
|
25
|
+
* Load testing and test monitoring scripts.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
0.4.0 - 2024-03-18
|
|
29
|
+
******************
|
|
30
|
+
|
|
31
|
+
Added
|
|
32
|
+
=====
|
|
33
|
+
|
|
34
|
+
* Embed multiple Superset Dashboards.
|
|
35
|
+
|
|
19
36
|
0.3.1 - 2024-03-14
|
|
20
37
|
******************
|
|
21
38
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: platform-plugin-aspects
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Aspects plugins for edx-platform
|
|
5
5
|
Home-page: https://github.com/openedx/platform-plugin-aspects
|
|
6
6
|
Author: Open edX Project
|
|
@@ -27,6 +27,7 @@ Requires-Dist: edx-opaque-keys
|
|
|
27
27
|
Requires-Dist: edx-toggles
|
|
28
28
|
Requires-Dist: openedx-atlas
|
|
29
29
|
Requires-Dist: openedx-filters
|
|
30
|
+
Requires-Dist: redis
|
|
30
31
|
Requires-Dist: requests
|
|
31
32
|
Requires-Dist: superset-api-client
|
|
32
33
|
Requires-Dist: web_fragments
|
|
@@ -149,6 +150,23 @@ Unreleased
|
|
|
149
150
|
|
|
150
151
|
*
|
|
151
152
|
|
|
153
|
+
0.5.0 - 2024-04-01
|
|
154
|
+
******************
|
|
155
|
+
|
|
156
|
+
Added
|
|
157
|
+
=====
|
|
158
|
+
|
|
159
|
+
* Load testing and test monitoring scripts.
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
0.4.0 - 2024-03-18
|
|
163
|
+
******************
|
|
164
|
+
|
|
165
|
+
Added
|
|
166
|
+
=====
|
|
167
|
+
|
|
168
|
+
* Embed multiple Superset Dashboards.
|
|
169
|
+
|
|
152
170
|
0.3.1 - 2024-03-14
|
|
153
171
|
******************
|
|
154
172
|
|
|
@@ -35,7 +35,7 @@ class AddSupersetTab(PipelineStep):
|
|
|
35
35
|
_ (str): instructor dashboard template name.
|
|
36
36
|
"""
|
|
37
37
|
course = context["course"]
|
|
38
|
-
|
|
38
|
+
dashboards = settings.ASPECTS_INSTRUCTOR_DASHBOARDS
|
|
39
39
|
extra_filters_format = settings.SUPERSET_EXTRA_FILTERS_FORMAT
|
|
40
40
|
|
|
41
41
|
filters = ASPECTS_SECURITY_FILTERS_FORMAT + extra_filters_format
|
|
@@ -45,7 +45,7 @@ class AddSupersetTab(PipelineStep):
|
|
|
45
45
|
context = generate_superset_context(
|
|
46
46
|
context,
|
|
47
47
|
user,
|
|
48
|
-
|
|
48
|
+
dashboards=dashboards,
|
|
49
49
|
filters=filters,
|
|
50
50
|
)
|
|
51
51
|
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Generates tracking events by creating test users and fake activity.
|
|
3
|
+
|
|
4
|
+
This should never be run on a production server as it will generate a lot of
|
|
5
|
+
bad data. It is entirely for benchmarking purposes in load test environments.
|
|
6
|
+
It is also fragile due to reaching into the edx-platform testing internals.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import csv
|
|
10
|
+
import io
|
|
11
|
+
import json
|
|
12
|
+
import logging
|
|
13
|
+
import uuid
|
|
14
|
+
from datetime import datetime, timedelta
|
|
15
|
+
from random import choice
|
|
16
|
+
from textwrap import dedent
|
|
17
|
+
from time import sleep
|
|
18
|
+
from typing import Any, List
|
|
19
|
+
|
|
20
|
+
import requests
|
|
21
|
+
from django.conf import settings
|
|
22
|
+
from django.core.management.base import BaseCommand, CommandError
|
|
23
|
+
|
|
24
|
+
from platform_plugin_aspects.sinks.base_sink import ClickHouseAuth
|
|
25
|
+
|
|
26
|
+
# For testing we won't be able to import from edx-platform
|
|
27
|
+
try: # pragma: no cover
|
|
28
|
+
from cms.djangoapps.contentstore.views.course import create_new_course_in_store
|
|
29
|
+
from common.djangoapps.student.helpers import do_create_account
|
|
30
|
+
from common.djangoapps.student.models.course_enrollment import CourseEnrollment
|
|
31
|
+
from openedx.core.djangoapps.user_authn.views.registration_form import (
|
|
32
|
+
AccountCreationForm,
|
|
33
|
+
)
|
|
34
|
+
from xmodule.modulestore import ModuleStoreEnum
|
|
35
|
+
|
|
36
|
+
RUNNING_IN_PLATFORM = True
|
|
37
|
+
except ImportError:
|
|
38
|
+
create_new_course_in_store = None
|
|
39
|
+
do_create_account = None
|
|
40
|
+
CourseEnrollment = None
|
|
41
|
+
AccountCreationForm = None
|
|
42
|
+
ModuleStoreEnum = None
|
|
43
|
+
|
|
44
|
+
RUNNING_IN_PLATFORM = False
|
|
45
|
+
|
|
46
|
+
log = logging.getLogger("tracking_event_loadtest")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class LoadTest:
|
|
50
|
+
"""
|
|
51
|
+
Runs the load test and reports results to ClickHouse.
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
users = []
|
|
55
|
+
sent_event_count = 0
|
|
56
|
+
ch_runs_table = "load_test_runs"
|
|
57
|
+
|
|
58
|
+
def __init__(self, num_users: int, username_prefix: str, tags: List[str]):
|
|
59
|
+
self.num_users = num_users
|
|
60
|
+
self.username_prefix = username_prefix
|
|
61
|
+
self.tags = tags
|
|
62
|
+
self.run_id = str(uuid.uuid4())[:6]
|
|
63
|
+
|
|
64
|
+
self.course_shortname = str(uuid.uuid4())[:6]
|
|
65
|
+
|
|
66
|
+
self.ch_url = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["url"]
|
|
67
|
+
self.ch_auth = ClickHouseAuth(
|
|
68
|
+
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["username"],
|
|
69
|
+
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["password"],
|
|
70
|
+
)
|
|
71
|
+
self.ch_database = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG["database"]
|
|
72
|
+
self.ch_xapi_database = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG.get(
|
|
73
|
+
"xapi_database", "xapi"
|
|
74
|
+
)
|
|
75
|
+
self.ch_runs_table = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG.get(
|
|
76
|
+
"runs_table", "load_test_runs"
|
|
77
|
+
)
|
|
78
|
+
self.ch_timeout_secs = settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG[
|
|
79
|
+
"timeout_secs"
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
self.instructor = self.create_user(
|
|
83
|
+
username=f"instructor_{self.course_shortname}",
|
|
84
|
+
name="Instructor",
|
|
85
|
+
password="aspects",
|
|
86
|
+
email=f"instructor_{self.course_shortname}@openedx.invalid",
|
|
87
|
+
)
|
|
88
|
+
self.create_course()
|
|
89
|
+
self.record_start()
|
|
90
|
+
self.create_and_enroll_learners(num_users, username_prefix)
|
|
91
|
+
|
|
92
|
+
def create_course(self) -> None:
|
|
93
|
+
"""
|
|
94
|
+
Create a course using the CMS API.
|
|
95
|
+
"""
|
|
96
|
+
start_date = datetime.now() - timedelta(days=7)
|
|
97
|
+
fields = {
|
|
98
|
+
"start": start_date,
|
|
99
|
+
"display_name": f"Course {self.course_shortname}",
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
log.info(
|
|
103
|
+
f"""Creating course:
|
|
104
|
+
Instructor: {self.instructor.id}
|
|
105
|
+
Org: "OEX"
|
|
106
|
+
Number: "{self.course_shortname}"
|
|
107
|
+
Run: "2024-1"
|
|
108
|
+
Fields: {fields}
|
|
109
|
+
"""
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
self.course = create_new_course_in_store(
|
|
113
|
+
ModuleStoreEnum.Type.split,
|
|
114
|
+
self.instructor,
|
|
115
|
+
"OEX",
|
|
116
|
+
self.course_shortname,
|
|
117
|
+
"2024-1",
|
|
118
|
+
fields,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
log.info(f"Created course {self.course.id}")
|
|
122
|
+
|
|
123
|
+
def record_start(self) -> None:
|
|
124
|
+
"""
|
|
125
|
+
Send a start event to ClickHouse.
|
|
126
|
+
|
|
127
|
+
Start and end events are used by the monitor script to know when to
|
|
128
|
+
begin and end monitoring.
|
|
129
|
+
"""
|
|
130
|
+
self.record_to_clickhouse(
|
|
131
|
+
"start",
|
|
132
|
+
{
|
|
133
|
+
"tags": self.tags,
|
|
134
|
+
"course_id": str(self.course.id),
|
|
135
|
+
"num_users": self.num_users,
|
|
136
|
+
"username_prefix": self.username_prefix,
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
# Let the monitoring script connect, otherwise we can finish the test before it even
|
|
141
|
+
# knows we've started.
|
|
142
|
+
sleep(5)
|
|
143
|
+
|
|
144
|
+
def record_end(self) -> None:
|
|
145
|
+
"""
|
|
146
|
+
Send an end event to ClickHouse.
|
|
147
|
+
"""
|
|
148
|
+
self.record_to_clickhouse("end", {"sent_event_count": self.sent_event_count})
|
|
149
|
+
|
|
150
|
+
def record_to_clickhouse(self, event_type, extra) -> None:
|
|
151
|
+
"""
|
|
152
|
+
Send the run events to ClickHouse.
|
|
153
|
+
"""
|
|
154
|
+
insert = (
|
|
155
|
+
f"INSERT INTO {self.ch_runs_table} (run_id, event_type, extra) FORMAT CSV "
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
output = io.StringIO()
|
|
159
|
+
writer = csv.writer(output)
|
|
160
|
+
writer.writerow((self.run_id, event_type, json.dumps(extra)))
|
|
161
|
+
print(output.getvalue().encode("utf-8"))
|
|
162
|
+
|
|
163
|
+
response = requests.post(
|
|
164
|
+
url=self.ch_url,
|
|
165
|
+
auth=self.ch_auth,
|
|
166
|
+
params={"database": self.ch_database, "query": insert},
|
|
167
|
+
data=output.getvalue().encode("utf-8"),
|
|
168
|
+
timeout=self.ch_timeout_secs,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
response.raise_for_status()
|
|
172
|
+
|
|
173
|
+
def create_and_enroll_learners(self, num_users, username_prefix):
|
|
174
|
+
"""
|
|
175
|
+
Uses create test users and enroll them in our test course.
|
|
176
|
+
"""
|
|
177
|
+
log.info(f"Creating {num_users} users prefixed with {username_prefix}.")
|
|
178
|
+
|
|
179
|
+
for _ in range(num_users):
|
|
180
|
+
user_short_name = str(uuid.uuid4())[:6]
|
|
181
|
+
u = self.create_user(
|
|
182
|
+
username=f"{username_prefix}_{user_short_name}",
|
|
183
|
+
name=f"Learner {user_short_name}",
|
|
184
|
+
password="aspects",
|
|
185
|
+
email=f"{user_short_name}@openedx.invalid",
|
|
186
|
+
)
|
|
187
|
+
self.users.append(u)
|
|
188
|
+
e = CourseEnrollment.get_or_create_enrollment(
|
|
189
|
+
user=u, course_key=self.course.id
|
|
190
|
+
)
|
|
191
|
+
e.is_active = True
|
|
192
|
+
e.save()
|
|
193
|
+
|
|
194
|
+
def create_user(self, **user_data):
|
|
195
|
+
"""
|
|
196
|
+
Create, activate, and return a user using the edx-platform API.
|
|
197
|
+
"""
|
|
198
|
+
account_creation_form = AccountCreationForm(data=user_data, tos_required=False)
|
|
199
|
+
|
|
200
|
+
user, _, _ = do_create_account(account_creation_form)
|
|
201
|
+
user.is_active = True
|
|
202
|
+
user.save()
|
|
203
|
+
return user
|
|
204
|
+
|
|
205
|
+
def trigger_events(
|
|
206
|
+
self, num_events: int, sleep_time: float, run_until_killed: bool
|
|
207
|
+
) -> None:
|
|
208
|
+
"""
|
|
209
|
+
Trigger the appropriate number of events based on configuration.
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
if run_until_killed:
|
|
213
|
+
log.info(f"Creating events until killed with {sleep_time} sleep between!")
|
|
214
|
+
while True:
|
|
215
|
+
self.trigger_event_and_sleep(sleep_time)
|
|
216
|
+
else:
|
|
217
|
+
log.info(f"Creating {num_events} event with {sleep_time} sleep between!")
|
|
218
|
+
for _ in range(num_events):
|
|
219
|
+
self.trigger_event_and_sleep(sleep_time)
|
|
220
|
+
|
|
221
|
+
def trigger_event_and_sleep(self, sleep_time: float) -> None:
|
|
222
|
+
"""
|
|
223
|
+
Cause a tracking log to be emitted and sleep the specified amount of time.
|
|
224
|
+
"""
|
|
225
|
+
user = choice(self.users)
|
|
226
|
+
|
|
227
|
+
e = CourseEnrollment.get_or_create_enrollment(
|
|
228
|
+
user=user, course_key=self.course.id
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
if e.is_active:
|
|
232
|
+
e.unenroll(user, self.course.id)
|
|
233
|
+
else:
|
|
234
|
+
e.enroll(user, self.course.id) # pragma: no cover
|
|
235
|
+
|
|
236
|
+
self.sent_event_count += 1
|
|
237
|
+
sleep(sleep_time)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
class Command(BaseCommand):
|
|
241
|
+
"""
|
|
242
|
+
Create tracking log events for load testing purposes.
|
|
243
|
+
|
|
244
|
+
Example:
|
|
245
|
+
tutor local run lms ./manage.py lms load_test_tracking_events --sleep_time 0 --tags celery 1worker
|
|
246
|
+
"""
|
|
247
|
+
|
|
248
|
+
help = dedent(__doc__).strip()
|
|
249
|
+
|
|
250
|
+
def add_arguments(self, parser: Any) -> None:
|
|
251
|
+
parser.add_argument(
|
|
252
|
+
"--num_users",
|
|
253
|
+
type=int,
|
|
254
|
+
default=10,
|
|
255
|
+
help="The number of users to create. All events will be generated for these learners.",
|
|
256
|
+
)
|
|
257
|
+
parser.add_argument(
|
|
258
|
+
"--username_prefix",
|
|
259
|
+
type=str,
|
|
260
|
+
default="lt_",
|
|
261
|
+
help="Prefix for the generated user names.",
|
|
262
|
+
)
|
|
263
|
+
parser.add_argument(
|
|
264
|
+
"--num_events",
|
|
265
|
+
type=int,
|
|
266
|
+
default=10,
|
|
267
|
+
help="The number of events to generate. This is ignored if --run_until_killed is set.",
|
|
268
|
+
)
|
|
269
|
+
parser.add_argument(
|
|
270
|
+
"--run_until_killed",
|
|
271
|
+
action="store_true",
|
|
272
|
+
default=False,
|
|
273
|
+
help="If this is set, the process will run endlessly until killed.",
|
|
274
|
+
)
|
|
275
|
+
parser.add_argument(
|
|
276
|
+
"--sleep_time",
|
|
277
|
+
type=float,
|
|
278
|
+
default=0.75,
|
|
279
|
+
help="Fractional number of seconds to sleep between sending events.",
|
|
280
|
+
)
|
|
281
|
+
parser.add_argument(
|
|
282
|
+
"--tags",
|
|
283
|
+
nargs="*",
|
|
284
|
+
help="Tags to help define the run (ex: --tags celery 3workers k8s).",
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
def handle(self, *args, **options):
|
|
288
|
+
"""
|
|
289
|
+
Create users and trigger events for them as configured above.
|
|
290
|
+
"""
|
|
291
|
+
if not RUNNING_IN_PLATFORM: # pragma: no cover
|
|
292
|
+
raise CommandError("This command must be run in the Open edX LMS or CMS.")
|
|
293
|
+
|
|
294
|
+
start = datetime.now()
|
|
295
|
+
lt = LoadTest(options["num_users"], options["username_prefix"], options["tags"])
|
|
296
|
+
|
|
297
|
+
try:
|
|
298
|
+
lt.trigger_events(
|
|
299
|
+
options["num_events"],
|
|
300
|
+
options["sleep_time"],
|
|
301
|
+
options["run_until_killed"],
|
|
302
|
+
)
|
|
303
|
+
lt.record_end()
|
|
304
|
+
except KeyboardInterrupt:
|
|
305
|
+
log.warning("Killed by keyboard, finishing.")
|
|
306
|
+
lt.record_end()
|
|
307
|
+
|
|
308
|
+
end = datetime.now()
|
|
309
|
+
log.info(f"Sent {lt.sent_event_count} events in {end - start}.")
|
|
310
|
+
|
|
311
|
+
# Wait 5 seconds for Kafka to clear the queue otherwise not all events
|
|
312
|
+
# may be delivered.
|
|
313
|
+
sleep(5)
|