Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Setup extended Complement Testing #14202

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8a28ba9
Add templating and comments for missing stream writers to configure_w…
realtyem Oct 16, 2022
52628ef
Add warning comment about non-functional stream writers.
realtyem Oct 16, 2022
2f7fedb
Add stream_writer map and instance_map handling to add_sharding_to_sh…
realtyem Oct 16, 2022
adb34bc
Remove unnecessary gating for running add_sharding_to_shared_config().
realtyem Oct 16, 2022
92a1345
Changelog
realtyem Oct 16, 2022
1c23863
Copy tests.yml to complement.yml for use as a template.
realtyem Oct 16, 2022
6f61aa6
Strip out or comment out things that aren't going to be used or that …
realtyem Oct 16, 2022
995b069
Correct 'needs' lines so flow works correctly.
realtyem Oct 16, 2022
3aa6c96
Need #14153 from this point, adjust names cuz pretty.
realtyem Oct 16, 2022
7d11c58
Make adjustments that are in line with requirements from PR #14153.
realtyem Oct 16, 2022
c21f9e5
Add some comments on using a schedule with example cron values.
realtyem Oct 17, 2022
a2c763c
Changelog
realtyem Oct 17, 2022
7795aa2
Add jobs calculations to calculate_jobs.py.
realtyem Oct 17, 2022
b08a69e
Mutate Defaults test into singles test.
realtyem Oct 17, 2022
28a9005
[REVERT THIS] Enable on push for testing.
realtyem Oct 17, 2022
9c53796
Revert "[REVERT THIS] Enable on push for testing."
realtyem Oct 17, 2022
f0b37ea
Duplicate Singles test for the other groupings.
realtyem Oct 17, 2022
bcb9092
Adjust to use new 'set_output' helper function for passing test matrix
realtyem Oct 21, 2022
6366e9e
Merge branch 'develop' into setup-extended-complement
realtyem Oct 21, 2022
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
70 changes: 70 additions & 0 deletions .ci/scripts/calculate_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,73 @@ def set_output(key: str, value: str):

test_matrix = json.dumps(sytest_tests)
set_output("sytest_test_matrix", test_matrix)


# Calculate a comprehensive list of workers by type to hunt for specific problems with them.
# Won't need to include if it's a 'worker' setup, because obviously it is. Postgres is implied
# because it's necessary for worker at this time.

complement_single_worker_tests = [
{
"worker_types": workers,
}
for workers in (
"account_data",
"appservice",
"background_worker",
"event_creator",
"event_persister",
"federation_inbound",
"federation_reader",
"federation_sender",
"frontend_proxy",
"media_repository",
"presence",
"pusher",
"receipts",
"synchrotron",
"to_device",
"typing",
"user_dir",
)
]

complement_sharding_worker_tests = [
{"worker_types": "event_persister, event_persister, event_persister"},
{"worker_types": "federation_sender, federation_sender, federation_sender"},
{"worker_types": "pusher, pusher, pusher"},
{"worker_types": "synchrotron, synchrotron, synchrotron"},
]

complement_stream_writers_worker_tests = [
{
"worker_types": "account_data, event_persister, presence, receipts, to_device, typing"
}
]

complement_fullset_worker_tests = [
{
"worker_types": "account_data, appservice, background_worker, event_creator, event_persister, event_persister, federation_inbound, federation_reader, federation_sender, federation_sender, frontend_proxy, media_repository, pusher, pusher, synchrotron, to_device, typing, user_dir"
}
]

print("::group::Calculated Complement jobs")
print(
json.dumps(
complement_single_worker_tests
+ complement_sharding_worker_tests
+ complement_stream_writers_worker_tests
+ complement_fullset_worker_tests,
indent=4,
)
)
print("::endgroup::")

test_matrix = json.dumps(complement_single_worker_tests)
set_output("complement_singles_test_matrix", test_matrix)
test_matrix = json.dumps(complement_sharding_worker_tests)
set_output("complement_sharding_test_matrix", test_matrix)
test_matrix = json.dumps(complement_stream_writers_worker_tests)
set_output("complement_stream_writers_test_matrix", test_matrix)
test_matrix = json.dumps(complement_fullset_worker_tests)
set_output("complement_fullset_test_matrix", test_matrix)
161 changes: 161 additions & 0 deletions .github/workflows/complement.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
name: Complement Tests

on:
# push:
# branches: ["develop", "release-*"]
# pull_request:
# schedule:
# eg. runs everyday at 4am - 0 4 * * *
# eg. runs every sundat at 4am - 0 4 * * 0

# Note: this will only work if this test exists on default branch, which is 'develop'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
calculate-test-jobs:
name: "Calculate Test Jobs"
if: ${{ !cancelled() && !failure() }} # Allow previous steps to be skipped, but not fail
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- id: get-matrix
run: .ci/scripts/calculate_jobs.py
outputs:
complement_singles_test_matrix: ${{ steps.get-matrix.outputs.complement_singles_test_matrix }}
complement_sharding_test_matrix: ${{ steps.get-matrix.outputs.complement_sharding_test_matrix }}
complement_stream_writers_test_matrix: ${{ steps.get-matrix.outputs.complement_stream_writers_test_matrix }}

singles:
name: Singles
if: "${{ !failure() && !cancelled() }}"
needs: calculate-test-jobs
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
job: ${{ fromJson(needs.calculate-test-jobs.outputs.complement_singles_test_matrix) }}

steps:
- name: Run actions/checkout@v3 for synapse
uses: actions/checkout@v3
with:
path: synapse

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.58.1
override: true
- uses: Swatinem/rust-cache@v2

- name: Prepare Complement's Prerequisites
run: synapse/.ci/scripts/setup_complement_prerequisites.sh

- name: Run Complement Tests
shell: bash
env:
POSTGRES: "true"
WORKERS: "true"
SYNAPSE_WORKER_TYPES: ${{ matrix.job.worker_types }}
run: |
set -o pipefail
COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt


sharding:
name: Sharding
if: "${{ !failure() && !cancelled() }}"
needs: calculate-test-jobs
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
job: ${{ fromJson(needs.calculate-test-jobs.outputs.complement_sharding_test_matrix) }}

steps:
- name: Run actions/checkout@v3 for synapse
uses: actions/checkout@v3
with:
path: synapse

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.58.1
override: true
- uses: Swatinem/rust-cache@v2

- name: Prepare Complement's Prerequisites
run: synapse/.ci/scripts/setup_complement_prerequisites.sh

- name: Run Complement Tests
shell: bash
env:
POSTGRES: "true"
WORKERS: "true"
SYNAPSE_WORKER_TYPES: ${{ matrix.job.worker_types }}
run: |
set -o pipefail
COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt


stream_writers:
name: All Stream Writers
if: "${{ !failure() && !cancelled() }}"
needs: calculate-test-jobs
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
job: ${{ fromJson(needs.calculate-test-jobs.outputs.complement_stream_writers_test_matrix) }}

steps:
- name: Run actions/checkout@v3 for synapse
uses: actions/checkout@v3
with:
path: synapse

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.58.1
override: true
- uses: Swatinem/rust-cache@v2

- name: Prepare Complement's Prerequisites
run: synapse/.ci/scripts/setup_complement_prerequisites.sh

- name: Run Complement Tests
shell: bash
env:
POSTGRES: "true"
WORKERS: "true"
SYNAPSE_WORKER_TYPES: ${{ matrix.job.worker_types }}
run: |
set -o pipefail
COMPLEMENT_DIR=`pwd`/complement synapse/scripts-dev/complement.sh -json 2>&1 | synapse/.ci/scripts/gotestfmt


# a job which marks all the other jobs as complete, thus allowing PRs to be merged.
tests-done:
name: Tests Done
if: ${{ always() }}
needs:
- singles
- sharding
- stream_writers
runs-on: ubuntu-latest
steps:
- uses: matrix-org/done-action@v2
with:
needs: ${{ toJSON(needs) }}

# skippable:
1 change: 1 addition & 0 deletions changelog.d/14197.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add all Stream Writer worker types to configure_workers_and_start.py.
1 change: 1 addition & 0 deletions changelog.d/14202.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Extend Complement testing to include various worker type combinations.
75 changes: 69 additions & 6 deletions docker/configure_workers_and_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@

MAIN_PROCESS_HTTP_LISTENER_PORT = 8080


# Workers with exposed endpoints needs either "client", "federation", or "media" listener_resources
# Watching /_matrix/client needs a "client" listener
# Watching /_matrix/federation needs a "federation" listener
# Watching /_matrix/media and related needs a "media" listener
# Stream Writers require "client" and "replication" listeners because they
# have to attach by instance_map to the master process and have client endpoints.
# BIG WARNING: typing and receipts stream writers are not working correctly at this time.
WORKERS_CONFIG: Dict[str, Dict[str, Any]] = {
"pusher": {
"app": "synapse.app.pusher",
Expand Down Expand Up @@ -209,6 +215,49 @@
% (MAIN_PROCESS_HTTP_LISTENER_PORT,)
),
},
"account_data": {
"app": "synapse.app.generic_worker",
"listener_resources": ["client", "replication"],
"endpoint_patterns": [
"^/_matrix/client/(r0|v3|unstable)/.*/tags",
"^/_matrix/client/(r0|v3|unstable)/.*/account_data",
],
"shared_extra_conf": {},
"worker_extra_conf": "",
},
"presence": {
"app": "synapse.app.generic_worker",
"listener_resources": ["client", "replication"],
"endpoint_patterns": ["^/_matrix/client/(api/v1|r0|v3|unstable)/presence/"],
"shared_extra_conf": {},
"worker_extra_conf": "",
},
"receipts": {
"app": "synapse.app.generic_worker",
"listener_resources": ["client", "replication"],
"endpoint_patterns": [
"^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt",
"^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers",
],
"shared_extra_conf": {},
"worker_extra_conf": "",
},
"to_device": {
"app": "synapse.app.generic_worker",
"listener_resources": ["client", "replication"],
"endpoint_patterns": ["^/_matrix/client/(r0|v3|unstable)/sendToDevice/"],
"shared_extra_conf": {},
"worker_extra_conf": "",
},
"typing": {
"app": "synapse.app.generic_worker",
"listener_resources": ["client", "replication"],
"endpoint_patterns": [
"^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/typing"
],
"shared_extra_conf": {},
"worker_extra_conf": "",
},
}

# Templates for sections that may be inserted multiple times in config files
Expand Down Expand Up @@ -309,6 +358,20 @@ def add_sharding_to_shared_config(
"port": worker_port,
}

elif worker_type in ["account_data", "presence", "receipts", "to_device", "typing"]:
# Update the list of stream writers
# It's convienent that the name of the worker type is the same as the event stream
shared_config.setdefault("stream_writers", {}).setdefault(
worker_type, []
).append(worker_name)

# Map of stream writer instance names to host/ports combos
# For now, all stream writers need http replication ports
instance_map[worker_name] = {
"host": "localhost",
"port": worker_port,
}

elif worker_type == "media_repository":
# The first configured media worker will run the media background jobs
shared_config.setdefault("media_instance_running_background_jobs", worker_name)
Expand Down Expand Up @@ -441,11 +504,11 @@ def generate_worker_files(

# Check if more than one instance of this worker type has been specified
worker_type_total_count = worker_types.count(worker_type)
if worker_type_total_count > 1:
# Update the shared config with sharding-related options if necessary
add_sharding_to_shared_config(
shared_config, worker_type, worker_name, worker_port
)

# Update the shared config with sharding-related options if necessary
add_sharding_to_shared_config(
shared_config, worker_type, worker_name, worker_port
)

# Enable the worker in supervisord
worker_descriptors.append(worker_config)
Expand Down