Skip to content

Commit

Permalink
feat: health check (#10)
Browse files Browse the repository at this point in the history
* feat: health check

* test: add tests

* chore: increment version

* chore: run src-docs

---------

Co-authored-by: Christopher Bartz <[email protected]>
  • Loading branch information
yanksyoon and cbartz authored Sep 12, 2024
1 parent 7198147 commit 7715306
Show file tree
Hide file tree
Showing 11 changed files with 326 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[project]
name = "github-runner-manager"
version = "0.1.2"
version = "0.1.3"
authors = [
{ name = "Canonical IS DevOps", email = "[email protected]" },
]
Expand Down
44 changes: 35 additions & 9 deletions src-docs/manager.cloud_runner_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ Represent state of the instance hosting the runner.

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L97"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `CloudInitStatus`
Represents the state of cloud-init script.

The cloud init script is used to launch ephemeral GitHub runners. If the script is being initialized, GitHub runner is listening for jobs or GitHub runner is running the job, the cloud-init script should report "running" status.

Refer to the official documentation on cloud-init status: https://cloudinit.readthedocs.io/en/latest/howto/status.html.



**Attributes:**

- <b>`NOT_STARTED`</b>: The cloud-init script has not yet been started.
- <b>`RUNNING`</b>: The cloud-init script is running.
- <b>`DONE`</b>: The cloud-init script has completed successfully.
- <b>`ERROR`</b>: There was an error while running the cloud-init script.
- <b>`DEGRADED`</b>: There was a non-critical issue while running the cloud-inits script.
- <b>`DISABLED`</b>: Cloud init was disabled by other system configurations.





---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L124"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `GitHubRunnerConfig`
Configuration for GitHub runner spawned.

Expand Down Expand Up @@ -81,7 +107,7 @@ __init__(github_path: GitHubOrg | GitHubRepo, labels: list[str]) → None

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L110"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L137"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `SupportServiceConfig`
Configuration for supporting services for runners.
Expand Down Expand Up @@ -118,7 +144,7 @@ __init__(

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L127"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L154"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `CloudRunnerInstance`
Information on the runner on the cloud.
Expand Down Expand Up @@ -155,7 +181,7 @@ __init__(

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L144"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L171"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `CloudRunnerManager`
Manage runner instance on cloud.
Expand All @@ -177,7 +203,7 @@ Get the name prefix of the self-hosted runners.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L200"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L227"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `cleanup`

Expand All @@ -197,7 +223,7 @@ Perform health check on runner and delete the runner if it fails.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L156"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L183"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `create_runner`

Expand All @@ -215,7 +241,7 @@ Create a self-hosted runner.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L181"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L208"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `delete_runner`

Expand All @@ -234,7 +260,7 @@ Delete self-hosted runner.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L190"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L217"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `flush_runners`

Expand All @@ -253,7 +279,7 @@ Stop all runners.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L164"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L191"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_runner`

Expand All @@ -271,7 +297,7 @@ Get a self-hosted runner by instance id.

---

<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L172"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/manager/cloud_runner_manager.py#L199"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_runners`

Expand Down
25 changes: 13 additions & 12 deletions src-docs/openstack_cloud.openstack_cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ Represents an OpenStack instance.

**Attributes:**

- <b>`addresses`</b>: IP addresses assigned to the server.
- <b>`created_at`</b>: The timestamp in which the instance was created at.
- <b>`instance_id`</b>: ID used by OpenstackCloud class to manage the instances. See docs on the OpenstackCloud.
- <b>`server_id`</b>: ID of server assigned by OpenStack.
- <b>`server_name`</b>: Name of the server on OpenStack.
- <b>`instance_id`</b>: ID used by OpenstackCloud class to manage the instances. See docs on the OpenstackCloud.
- <b>`addresses`</b>: IP addresses assigned to the server.
- <b>`status`</b>: Status of the server.

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L60"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L62"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand Down Expand Up @@ -53,14 +54,14 @@ Construct the object.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L126"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L128"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `OpenstackCloud`
Client to interact with OpenStack cloud.

The OpenStack server name is managed by this cloud. Caller refers to the instances via instance_id. If the caller needs the server name, e.g., for logging, it can be queried with get_server_name.

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L134"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L136"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand All @@ -83,7 +84,7 @@ Create the object.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L335"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L337"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `cleanup`

Expand All @@ -95,7 +96,7 @@ Cleanup unused key files and openstack keypairs.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L224"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L226"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `delete_instance`

Expand All @@ -113,7 +114,7 @@ Delete a openstack instance.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L204"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L206"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_instance`

Expand All @@ -136,7 +137,7 @@ Get OpenStack instance by instance ID.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L312"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L314"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_instances`

Expand All @@ -153,7 +154,7 @@ Get all OpenStack instances.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L345"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L347"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_server_name`

Expand All @@ -176,7 +177,7 @@ Get server name on OpenStack.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L259"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L261"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_ssh_connection`

Expand Down Expand Up @@ -206,7 +207,7 @@ Get SSH connection to an OpenStack instance.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L149"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_cloud.py#L151"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `launch_instance`

Expand Down
20 changes: 10 additions & 10 deletions src-docs/openstack_cloud.openstack_runner_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Manager for self-hosted runner on OpenStack.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L71"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L73"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `OpenStackCloudConfig`
Configuration for OpenStack cloud authorisation information.
Expand Down Expand Up @@ -47,7 +47,7 @@ __init__(clouds_config: dict[str, dict], cloud: str) → None

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L84"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L86"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `OpenStackServerConfig`
Configuration for OpenStack server.
Expand Down Expand Up @@ -78,7 +78,7 @@ __init__(image: str, flavor: str, network: str) → None

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L112"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L114"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>class</kbd> `OpenStackRunnerManager`
Manage self-hosted runner on OpenStack cloud.
Expand All @@ -89,7 +89,7 @@ Manage self-hosted runner on OpenStack cloud.

- <b>`name_prefix`</b>: The name prefix of the runners created.

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L120"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L122"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `__init__`

Expand Down Expand Up @@ -133,7 +133,7 @@ The prefix of runner names.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L320"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L322"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `cleanup`

Expand All @@ -156,7 +156,7 @@ Cleanup runner and resource on the cloud.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L170"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L172"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `create_runner`

Expand Down Expand Up @@ -186,7 +186,7 @@ Create a self-hosted runner.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L269"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L271"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `delete_runner`

Expand All @@ -210,7 +210,7 @@ Delete self-hosted runners.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L295"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L297"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `flush_runners`

Expand All @@ -233,7 +233,7 @@ Remove idle and/or busy runners.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L215"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L217"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_runner`

Expand All @@ -256,7 +256,7 @@ Get a self-hosted runner by instance id.

---

<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L237"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/github_runner_manager/openstack_cloud/openstack_runner_manager.py#L239"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>method</kbd> `get_runners`

Expand Down
27 changes: 27 additions & 0 deletions src/github_runner_manager/manager/cloud_runner_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,33 @@ def from_openstack_server_status( # pragma: no cover
return state


class CloudInitStatus(str, Enum):
"""Represents the state of cloud-init script.
The cloud init script is used to launch ephemeral GitHub runners. If the script is being
initialized, GitHub runner is listening for jobs or GitHub runner is running the job, the
cloud-init script should report "running" status.
Refer to the official documentation on cloud-init status:
https://cloudinit.readthedocs.io/en/latest/howto/status.html.
Attributes:
NOT_STARTED: The cloud-init script has not yet been started.
RUNNING: The cloud-init script is running.
DONE: The cloud-init script has completed successfully.
ERROR: There was an error while running the cloud-init script.
DEGRADED: There was a non-critical issue while running the cloud-inits script.
DISABLED: Cloud init was disabled by other system configurations.
"""

NOT_STARTED = "not started"
RUNNING = "running"
DONE = "done"
ERROR = "error"
DEGRADED = "degraded"
DISABLED = "disabled"


@dataclass
class GitHubRunnerConfig:
"""Configuration for GitHub runner spawned.
Expand Down
Loading

0 comments on commit 7715306

Please sign in to comment.