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 docs and wrap pebble.ExecError with custom error #653

Open
wants to merge 3 commits into
base: 2/main
Choose a base branch
from

Conversation

Thanhphan1147
Copy link
Collaborator

@Thanhphan1147 Thanhphan1147 commented Jan 14, 2025

This PR adds missing commits from #620

  • Add missing custom exception wrapping pebble.ExecError for mas-cli commands
  • Update docs about mjolnir

Checklist

  • The charm style guide was applied
  • The contributing guide was applied
  • The changes are compliant with ISD054 - Manging Charm Complexity
  • The documentation is generated using src-docs
  • The documentation for charmhub is updated.
  • The PR is tagged with appropriate label (urgent, trivial, complex)
  • The changelog is updated with changes that affect the users of the charm.

process.wait()
except ops.pebble.ExecError as exc:
logger.exception("Error syncing MAS config with the database.")
raise MASConfigSyncError("Error validating MAS configuration.") from exc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will this exception be catched somewhere? Otherwise I think the unit will go into error state (and currently synapse does not go into error state, but into blocked state I think)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My reasoning is that if this command fails then there's something wrong with the postgresql database which should put the charm into an error state as there's usually no specific action for the operator to take

Copy link
Collaborator

Choose a reason for hiding this comment

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

The issue with getting into error state is that it is problematic.

For example, as you are not using the latest version of the redis library, if you get into error state and the redis url changes (because for example the redis pod was recreated), the charm will not get notified, and you may not get out of that issue (as has happened in the discourse charm). Updating the redis library will fix that, but other issues may arise, as not being able to upgrade the charm in that state...

process.wait()
except ops.pebble.ExecError as exc:
logger.exception("Error syncing MAS config with the database.")
raise MASConfigSyncError("Error validating MAS configuration.") from exc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the exception description be the same as the logger.exception?

@@ -116,7 +139,7 @@ def register_user(
process = container.exec(command=command, working_dir=MAS_WORKING_DIR)
process.wait_output()
except ops.pebble.ExecError as exc:
logger.error("Error registering new user: %s", exc.stderr)
logger.exception("Error registering new user.")
raise MASRegisterUserFailedError("Error validating MAS configuration.") from exc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here regarding expcetion description and logger.exception

Copy link
Contributor

Test coverage for 24e3c7e

Name                                    Stmts   Miss Branch BrPart  Cover   Missing
-----------------------------------------------------------------------------------
src/auth/__init__.py                        0      0      0      0   100%
src/auth/mas.py                            78      6      2      1    91%   82-84, 101-103, 136->138
src/backup.py                             175      5     20      2    96%   353-354, 423-424, 481->483, 484
src/backup_observer.py                    134     16     12      0    89%   132-135, 140-143, 179-182, 211-214
src/charm.py                              272     18     64     10    92%   141->143, 146, 271, 275-276, 282-283, 304-305, 329, 336, 411-415, 418-419, 447-449, 469
src/charm_types.py                         30      0      0      0   100%
src/database_client.py                     57      1      8      4    92%   35, 47->exit, 69->exit, 88->98
src/database_observer.py                   49      4      2      0    92%   61-64
src/exceptions.py                           3      0      0      0   100%
src/matrix_auth_observer.py                69      7     10      2    89%   66, 146, 160-164
src/media_observer.py                      45      4      2      1    89%   60-62, 81
src/observability.py                       14      0      0      0   100%
src/pebble.py                             194     23     44     11    86%   157->exit, 168-172, 216-217, 237-238, 256-259, 320->325, 330-331, 343-344, 346-347, 378, 380, 382, 384, 386, 417
src/redis_observer.py                      39      3      4      0    93%   63-66
src/s3_parameters.py                       22      0      4      0   100%
src/smtp_observer.py                       61      1     14      2    96%   89, 108->113
src/state/__init__.py                       0      0      0      0   100%
src/state/charm_state.py                  127      9     32      7    90%   164, 168, 189, 214, 220, 226, 230-231, 314
src/state/mas.py                           78      8      6      3    87%   152, 158-159, 183-185, 200, 220
src/state/validation.py                    36      3      2      0    92%   108-110
src/synapse/__init__.py                     3      0      0      0   100%
src/synapse/api.py                        129      6     18      4    93%   111-112, 161, 172, 174, 314
src/synapse/workload.py                   118      4     24      0    94%   365-368
src/synapse/workload_configuration.py     149     26     34     12    79%   90->exit, 94-95, 143-144, 173, 193-194, 226-227, 260, 269-270, 285, 290-291, 312-313, 332->337, 338, 356->358, 368-369, 397, 405->407, 407->409, 414-415, 435->442, 445, 465-466
src/user.py                                23      0      2      0   100%
-----------------------------------------------------------------------------------
TOTAL                                    1905    144    304     59    91%

Static code analysis report

Working... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00
Run started:2025-01-15 13:11:43.079494

Test results:
  No issues identified.

Code scanned:
  Total lines of code: 9723
  Total lines skipped (#nosec): 3
  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):

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.

3 participants