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

Add checks config fields and get_checks API #668

Merged
merged 33 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1ef5861
Add checks config fields and get_checks API
benhoyt Dec 1, 2021
e76ec56
Fix existing tests
benhoyt Dec 1, 2021
08ec4ff
Add tests for checks additions; fix a couple of issues
benhoyt Dec 2, 2021
38b365c
Make default for restart (int) 0 instead of None
benhoyt Dec 2, 2021
30722eb
Merge branch 'main' into auto-restart-and-checks
benhoyt Dec 6, 2021
f77f445
Merge branch 'main' into auto-restart-and-checks
benhoyt Dec 12, 2021
ef170f0
Type annotation tweaks from sed-i
benhoyt Dec 14, 2021
6c22f7c
Merge branch 'main' into auto-restart-and-checks
pengale Dec 17, 2021
9ea0764
Merge branch 'main' into auto-restart-and-checks
benhoyt Jan 5, 2022
879718f
Merge remote-tracking branch 'origin/auto-restart-and-checks' into au…
benhoyt Jan 5, 2022
ec60a5b
Update per changes to https://github.com/canonical/pebble/pull/86
benhoyt Feb 15, 2022
752dcee
Merge branch 'main' into auto-restart-and-checks
benhoyt Feb 15, 2022
cbfe6a0
Add real Pebble test for /v1/checks and /v1/health
benhoyt Feb 15, 2022
90792db
Fix lint issues
benhoyt Feb 15, 2022
b355ee0
Comment out real test_checks till that's merged in Pebble
benhoyt Feb 15, 2022
30c12ac
Oops, quiet linter again
benhoyt Feb 15, 2022
c1e9988
Re-enable commented-out "real Pebble" test
benhoyt Feb 21, 2022
a0e40ae
Merge branch 'main' into auto-restart-and-checks
benhoyt Feb 21, 2022
01287e0
Oops, add --http flag back to pebble run in "real Pebble" tests
benhoyt Feb 21, 2022
b454cce
Fix test_checks_and_health on Python 3.5 (json.load can't take bytes)
benhoyt Feb 21, 2022
15d96a8
Temp fix for canonical/grafana-k8s-operator build issue
benhoyt Feb 22, 2022
59ef681
Revert "Temp fix for canonical/grafana-k8s-operator build issue"
benhoyt Feb 23, 2022
6c8c557
Merge branch 'main' into auto-restart-and-checks
benhoyt Feb 23, 2022
d7900ea
Merge branch 'main' into auto-restart-and-checks
jnsgruk Mar 5, 2022
48fa314
expose the departing unit on RelationDeparted events (#712)
rwcarlsen Mar 5, 2022
8fc08db
Add better docstring to CheckInfo
benhoyt Mar 8, 2022
926e728
Comment test_checks_and_health
benhoyt Mar 8, 2022
42e92ce
Add link to layer spec to Plan and Layer docstrings
benhoyt Mar 8, 2022
2f75e04
Merge branch 'main' into auto-restart-and-checks
benhoyt Mar 8, 2022
68903f4
Comment tweaks/fixes
benhoyt Mar 8, 2022
8e689d4
Add missing model.Container.get_checks and .get_check methods
benhoyt Mar 8, 2022
d7dbd9f
Merge branch 'main' into auto-restart-and-checks
benhoyt Mar 10, 2022
c12ff4a
Merge branch 'main' into auto-restart-and-checks
jnsgruk Mar 25, 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
2 changes: 1 addition & 1 deletion .github/workflows/framework-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
- name: Start Pebble
run: |
umask 0
$HOME/go/bin/pebble run --create-dirs &
$HOME/go/bin/pebble run --create-dirs --http=:4000 &
env:
PEBBLE: /tmp/pebble

Expand Down
54 changes: 52 additions & 2 deletions ops/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ def get_services(self, *service_names: str) -> 'ServiceInfoMapping':
def get_service(self, service_name: str) -> 'pebble.ServiceInfo':
"""Get status information for a single named service.

Raises model error if service_name is not found.
Raises :class:`ModelError` if service_name is not found.
"""
services = self.get_services(service_name)
if not services:
Expand All @@ -1213,6 +1213,33 @@ def get_service(self, service_name: str) -> 'pebble.ServiceInfo':
raise RuntimeError('expected 1 service, got {}'.format(len(services)))
return services[service_name]

def get_checks(
self,
*check_names: str,
level: 'pebble.CheckLevel' = None) -> 'CheckInfoMapping':
"""Fetch and return a mapping of check information indexed by check name.

Args:
check_names: Optional check names to query for. If no check names
are specified, return checks with any name.
level: Optional check level to query for. If not specified, fetch
checks with any level.
"""
checks = self._pebble.get_checks(names=check_names or None, level=level)
return CheckInfoMapping(checks)

def get_check(self, check_name: str) -> 'pebble.CheckInfo':
"""Get check information for a single named check.

Raises :class:`ModelError` if check_name is not found.
"""
checks = self.get_checks(check_name)
if not checks:
raise ModelError('check {!r} not found'.format(check_name))
if len(checks) > 1:
raise RuntimeError('expected 1 check, got {}'.format(len(checks)))
return checks[check_name]

def pull(self, path: str, *, encoding: str = 'utf-8') -> typing.Union[typing.BinaryIO,
typing.TextIO]:
"""Read a file's content from the remote system.
Expand Down Expand Up @@ -1402,7 +1429,7 @@ def __repr__(self):


class ServiceInfoMapping(Mapping):
"""Map of service names to pebble.ServiceInfo objects.
"""Map of service names to :class:`ops.pebble.ServiceInfo` objects.

This is done as a mapping object rather than a plain dictionary so that we
can extend it later, and so it's not mutable.
Expand All @@ -1424,6 +1451,29 @@ def __repr__(self):
return repr(self._services)


class CheckInfoMapping(Mapping):
"""Map of check names to :class:`ops.pebble.CheckInfo` objects.

This is done as a mapping object rather than a plain dictionary so that we
can extend it later, and so it's not mutable.
"""

def __init__(self, checks: typing.Iterable['pebble.CheckInfo']):
self._checks = {c.name: c for c in checks}

def __getitem__(self, key: str):
return self._checks[key]

def __iter__(self):
return iter(self._checks)

def __len__(self):
return len(self._checks)

def __repr__(self):
return repr(self._checks)


class ModelError(Exception):
"""Base class for exceptions raised when interacting with the Model."""
pass
Expand Down
Loading