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

Charm Review #1

Open
wants to merge 357 commits into
base: empty
Choose a base branch
from
Open

Charm Review #1

wants to merge 357 commits into from

Conversation

weiiwang01
Copy link
Owner

No description provided.

nsklikas and others added 28 commits September 28, 2023 13:19
Update dashboards and alert rules
docs: IAM-410 add charmhub doc link
…actions

chore(deps): update actions/checkout digest to b4ffde6
Enabling the auto-merge option in the create-pull-request action tried
to squash the commits, which is not allowe dby our repo config.
…-query

fix(loki-rule): improve error handling in json parsing
- Change the _on_relation_changed_event to ensure that all units receive the hook. Currently only leader units on the consuming charm will receive the event which is not correct as non-leader units also need the info.
from dataclasses import asdict, dataclass, field
from typing import Dict, List, Mapping, Optional

import jsonschema
Copy link
Owner Author

Choose a reason for hiding this comment

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

Probably a good idea to add jsonschema to PYDEPS so that charmcraft will automatically install it for user charms. See https://discourse.charmhub.io/t/python-dependencies-in-charm-libraries/8599

Comment on lines +12 to +15
parts:
charm:
charm-binary-python-packages:
- jsonschema
Copy link
Owner Author

Choose a reason for hiding this comment

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

I tested with the latest version of charmcraft, and it can build jsonschema from the source without any problems, so this can probably be removed.

@classmethod
def from_dict(cls, dic: Dict) -> "OauthProviderConfig":
"""Generate OauthProviderConfig instance from dict."""
return cls(**{k: v for k, v in dic.items() if k in inspect.signature(cls).parameters})
Copy link
Owner Author

Choose a reason for hiding this comment

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

Perhaps the dataclasses.fields function will be simpler than inspect.signature?


def restore(self, snapshot: Dict) -> None:
"""Restore event."""
self.client_id = snapshot["client_id"]
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
self.client_id = snapshot["client_id"]
super().restore(snapshot)
self.client_id = snapshot["client_id"]

Probably should call the overridden restore function.

and "client_secret_id" in relation.data[relation.app]
)

def get_provider_info(self, relation_id: Optional[int] = None) -> OauthProviderConfig:
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
def get_provider_info(self, relation_id: Optional[int] = None) -> OauthProviderConfig:
def get_provider_info(self, relation_id: Optional[int] = None) -> Optional[OauthProviderConfig]:

small nit

Comment on lines +260 to +263
"version": {
"override": "replace",
"exec": {"command": "hydra version"},
},
Copy link
Owner Author

Choose a reason for hiding this comment

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

Is this necessary, since it only checks whether the container has the hydra executable and not whether the hydra service is running?

Comment on lines +283 to +287
try:
self._container.get_service(self._container_name)
except (ModelError, RuntimeError):
return False
return True
Copy link
Owner Author

Choose a reason for hiding this comment

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

Suggested change
try:
self._container.get_service(self._container_name)
except (ModelError, RuntimeError):
return False
return True
return self._container.can_connect() and self._container_name in self._container.get_services()

So we don't need to capture the RuntimeError which may caused by some unknown problems.

Comment on lines +352 to +363
def _get_database_relation_info(self) -> dict:
if not self.database.relations:
return None

relation_id = self.database.relations[0].id
relation_data = self.database.fetch_relation_data()[relation_id]
return {
"username": relation_data.get("username"),
"password": relation_data.get("password"),
"endpoints": relation_data.get("endpoints"),
"database_name": self._db_name,
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

It would probably be better to check if the relation data contains the username, password, and endpoints fields, as the PostgreSQL charm may take some time to react and provision the database. During that time, the relation exists, but the relation data will be empty. Also, the endpoints field is a comma-separated list of all possible endpoints (e.g., 10.0.0.1:5432,10.0.0.2:5432). Does Hydra support multiple host components within the URI?

Comment on lines +625 to +627
def _on_database_relation_departed(self, event: RelationDepartedEvent) -> None:
"""Event Handler for database relation departed event."""
self.unit.status = BlockedStatus("Missing required relation with postgresql")
Copy link
Owner Author

Choose a reason for hiding this comment

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

As mentioned before, I think maybe relation-broken might be a better choice here as if the database scale down an unit, it will trigger the relation-departed event.

Comment on lines +291 to +297
if not self._container.can_connect():
return False

try:
service = self._container.get_service(self._container_name)
except (ModelError, RuntimeError):
return False
Copy link
Owner Author

Choose a reason for hiding this comment

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

Same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet