Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NGINX configuration to work with horizontal scaling #268

Merged
merged 12 commits into from
Apr 2, 2024

Conversation

amandahla
Copy link
Collaborator

@amandahla amandahla commented Mar 27, 2024

Note: Integration test will be done in further story.

Overview

In Synapse, the main unit and workers handle different endpoints. This PR prepares NGINX to handle it while scaling by using template files that the charm will update with the proper main unit address.

Also, this PR changes Mjolnir to be enabled only in the main unit and redirecting abuse reports properly to it.

Flow

  • Synapse NGINX Pebble ready event is emitted.
  • The charm will call pebble.replan_nginx() with the main unit address.
  • The replan_nginx will copy the files main_location.conf.template and abuse_report_location.conf.template to their original places and run the command sed to replace the string "main-unit" to the main unit address received.
  • Synapse NGINX Pebble layer is replanned.

If the main unit is changed, the relation-changed event is emitted. The same process will happen there.

Why all this?

Any unit can correctly forward requests for the main unit if this is the case. Especially considering that only the main unit will run Mjolnir.
Otherwise, the unit itself will handle the request.

Rationale

Redirect requests as expected while horizontal scaling Synapse.

Juju Events Changes

NGINX pebble ready event.
_on_relation_changed event.

Module Changes

Library Changes

Checklist

Charmhub doc will be updated once horizontal scaling is in place.

@amandahla amandahla requested a review from a team as a code owner March 27, 2024 18:57
@amandahla amandahla changed the base branch from main to feat/horizontal-scaling March 27, 2024 18:58
Copy link
Contributor

@merkata merkata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, left some comments

nginx_rock/etc/main_location.conf.template Show resolved Hide resolved
nginx_rock/etc/nginx.conf Show resolved Hide resolved
src/charm.py Outdated
"/etc/nginx/main_location.conf.template",
"/etc/nginx/main_location.conf",
],
).wait()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a new one, I think previously we used some internal _exec function (that wraps container.exec) and I'm seeing a wait() for the first time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this is an experiment ;-)
I thought about not catching the error if something happens here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/charm.py Outdated Show resolved Hide resolved
@amandahla amandahla marked this pull request as draft March 27, 2024 21:39
@amandahla amandahla marked this pull request as ready for review March 28, 2024 19:01

harness.begin_with_initial_hooks()
harness.charm.on.config_changed.emit()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not using the harness fixture so calling "begin_with_initial_hooks" would generate: "ops.pebble.APIError: execution handler not found, please register one using Harness.handle_exec"

So I changed to only call the config changed event.

Copy link
Contributor

github-actions bot commented Apr 1, 2024

Test coverage for 96c1b67

Name                            Stmts   Miss Branch BrPart  Cover   Missing
---------------------------------------------------------------------------
src/actions/__init__.py             3      0      0      0   100%
src/actions/register_user.py       22      0      2      0   100%
src/actions/reset_instance.py      21      0      2      0   100%
src/admin_access_token.py          10      0      0      0   100%
src/backup.py                     196      5     28      2    97%   403-404, 473-474, 530->532, 533
src/backup_observer.py            133     16     14      0    89%   130-133, 138-141, 177-180, 209-212
src/charm.py                      288     10     68      7    95%   140->142, 145, 257-258, 285, 292-293, 370->exit, 388-391, 453-454
src/charm_state.py                 94      0     12      0   100%
src/charm_types.py                 27      0      8      0   100%
src/database_client.py             53      1     10      3    94%   35, 47->exit, 69->exit
src/database_observer.py           50      3      6      1    93%   71-73, 89->91
src/exceptions.py                   4      0      0      0   100%
src/irc_bridge.py                  65      9     12      3    82%   75, 77-78, 105-106, 155-165
src/mjolnir.py                     88     12     26      3    83%   60-68, 79, 82->84, 176-177
src/observability.py               10      0      0      0   100%
src/pebble.py                     194     21     28      7    87%   167->exit, 178-182, 201-202, 219-220, 253-254, 256-257, 268, 270, 272, 274, 305-306, 325-326, 345-346
src/redis_observer.py              53      5      6      1    90%   67-70, 90-91
src/saml_observer.py               45      1      8      0    98%   63
src/smtp_observer.py               70      4     16      2    93%   74-78, 81, 100->105
src/synapse/__init__.py             4      0      0      0   100%
src/synapse/admin.py               20      9      2      0    50%   40-41, 63-74
src/synapse/api.py                176      3     24      3    97%   176, 229, 402
src/synapse/workload.py           283     35     57      8    86%   297-298, 310-320, 377->379, 394->exit, 398-399, 419-420, 460-461, 497-498, 511-519, 589, 627, 674->677, 701-702, 720, 728->730, 730->732, 737-738, 755, 764-765
src/user.py                        24      0      4      0   100%
---------------------------------------------------------------------------
TOTAL                            1933    134    333     40    92%

Static code analysis report

Working... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:01
Run started:2024-04-01 21:35:20.883453

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 10113
  Total lines skipped (#nosec): 4
  Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 0

Run metrics:
  Total issues (by severity):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
  Total issues (by confidence):
  	Undefined: 0
  	Low: 0
  	Medium: 0
  	High: 0
Files skipped (0):

Copy link
Contributor

@yanksyoon yanksyoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, minor nitpicky comments regarding file structure! Thank you!

src/synapse/workload.py Show resolved Hide resolved
templates/worker.yaml Show resolved Hide resolved
tests/unit/conftest.py Show resolved Hide resolved
@amandahla amandahla merged commit 429bb70 into feat/horizontal-scaling Apr 2, 2024
24 checks passed
@amandahla amandahla deleted the ISD-1579-nginx branch April 2, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants