Skip to content

Commit fe82e0e

Browse files
author
Bernard Szabo
committed
feat: parameterize landing page and resources
1 parent d7a3c78 commit fe82e0e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

tubular/scripts/dd_synthetic_tests.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,25 @@ def _trigger_batch_tests(self):
127127
"DD-API-KEY": self.api_key,
128128
"DD-APPLICATION-KEY": self.app_key
129129
}
130-
test_public_ids = self.tests_by_public_id.keys()
131-
json_request_body = {"tests": [{"public_id": public_id} for public_id in test_public_ids]}
130+
x = "(\w+)\.edx.org|1.stage.edx.org"
131+
json_request_body = {"tests": [{"public_id": test.public_id,
132+
"startUrl" : test.url,
133+
"resourceUrlSubstitutionRegexes": self._map_environment_resources(test.env)}
134+
for test in self.tests_by_public_id.values()]}
132135
logging.info(f'Trigger request body: {json_request_body}')
133136
response = requests.post(url, headers=headers, json=json_request_body)
134137
if response.status_code != 200:
135138
raise Exception(f"Datadog API error. Status = {response.status_code}")
136139
return response
137140

141+
def _map_environment_resources(self, env):
142+
if not env or env == 'prod':
143+
return r"(\.*)|\1" # No change
144+
elif env == 'stage':
145+
return r'"(\.+)\.edx.org|\1.stage.edx.org"'
146+
else:
147+
raise Exception(f'Unknown {env} environment')
148+
138149
def _record_batch_id(self, response_body):
139150
'''
140151
Datadog generates a single batch ID associated with the request for all the requested tests. This is distinct
@@ -253,7 +264,7 @@ def run_synthetic_tests(enable_automated_rollbacks, timeout, tests):
253264
dd_client.timeout_secs = timeout
254265

255266
tests_as_dicts = json.loads(tests)
256-
tests_to_report_on = [SyntheticTest(d["name"], d["public_id"]) for d in tests_as_dicts]
267+
tests_to_report_on = [SyntheticTest(d["name"], d["public_id"], d["env"], d["startUrl"]) for d in tests_as_dicts]
257268
dd_client.trigger_synthetic_tests(tests_to_report_on)
258269
dd_client.gate_on_deployment_testing_enable_switch() # Exits summarily if test results are to be ignored
259270
for test in tests_to_report_on:

0 commit comments

Comments
 (0)