You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-47
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,9 @@
1
1
# mq-lease-service
2
-
> A priority mutex with stabilisation window and TTLs, designed to work with the Github MergeQueue accessing a shared resource.
2
+
> Add a funnel for shared resources on the Github Merge Queue.
3
+
4
+
If you want to use the github merge-queue feature and have a shared resource that can only be accessed by one process at a time (e.g. deploying a staging environment and running tests), this service/action is for you.
5
+
It allows actions running as part of a merge group to get a mutex/lease on a shared resource, ensuring that only one action can access the resource at a time. Here, it takes in the priority of the action based on the number of commits ahead of the base branch and ensures that the highest priority action gets the lease.
6
+
After releasign the mutex/lease (and by the nature of the merge queue combining commits), a positive outcome is propagated forward to action runs with a lower priority, or, on a failure, the lease is released and the next action with the highest priority gets the lease.
3
7
4
8
## Contributing
5
9
@@ -23,6 +27,53 @@ make run-server # to run the server
23
27
24
28
## Components
25
29
30
+
### Github Action
31
+
The Github Action component of this repo interacts with the LeaseProvider and determines the priority of each run based on the commits ahead of the base.
32
+
It has two stages:
33
+
1. Acquiring a lease
34
+
2. Releasing a lease when (1) has been successful, reporting the Github action job status
35
+
36
+
An example workflow can look like this:
37
+
```yaml
38
+
on:
39
+
# Trigger on PRs; here we just skip
40
+
pull_request:
41
+
branches: [ main ]
42
+
# Trigger on the merge group event
43
+
merge_group:
44
+
branches: [ main ]
45
+
types: [ checks_requested ]
46
+
47
+
jobs:
48
+
access-shared-resource:
49
+
runs-on: ubuntu-latest
50
+
if: ${{ github.event_name == 'merge_group' }}
51
+
steps:
52
+
- name: Checkout Plugin Repository
53
+
uses: actions/checkout@v3
54
+
- name: acquire lease
55
+
id: acquire_lease
56
+
uses: ankorstore/mq-lease-service@main
57
+
with:
58
+
endpoint: https://your.lease.service.com
59
+
# auth: "" Optional: Authorization header value
60
+
61
+
- name: sleep
62
+
# Only perform github actions when this run acquired the lease
if: always() # always run this step to ensure we don't leave the lease-service in a dirty state
71
+
with:
72
+
endpoint: https://your.lease.service.com
73
+
release_with_status: ${{ job.status }}
74
+
# auth: "" Optional: Authorization header value
75
+
```
76
+
26
77
### LeaseProvider
27
78
The LeaseProvider is a server that provides the ability to manage distributed leases among multiple github action runs, letting the highest priority run _win_ the lease. This process is helpful when there are multiple runs running that need access to a shared resource. It allows them to agree on the _winner_ of a race for the resource, and subsequently provide the _winner_ with a lease until it is released.
28
79
Depending on the release status (success/failure), the lease is completed and confirmation is awaited or the request from the failing lease is discarded and the process restarts.
@@ -31,7 +82,7 @@ It exposes the following endpoints:
31
82
- GET `/healthz` Kubernetes health endpoint
32
83
- GET `/readyz` Kubernetes readiness endpoint
33
84
- GET `/metrics` Prometheus metric endpoint
34
-
- POST `/:owner/:repo/:baseRef/aquire` for aquiring a lease (poll until status is acquired or completed)
85
+
- POST `/:owner/:repo/:baseRef/acquire` for aquiring a lease (poll until status is acquired or completed)
35
86
- POST `/:owner/:repo/:baseRef/release` for releasing a lease (the winnder informs the LeaseProvider with the end result)
36
87
37
88
The payload and response (_LeaseRequest_) is encoded as JSON and follows this scheme:
@@ -46,7 +97,7 @@ The payload and response (_LeaseRequest_) is encoded as JSON and follows this sc
46
97
Configuration options:
47
98
-`--port` (8080)
48
99
-`--stabilisation-window` (5m) - time to wait before giving out a lease without all expected PRs being in the merge queue
49
-
-`--ttl` (30s) - time to wait before considering an aquire interest being stale
100
+
-`--ttl` (30s) - time to wait before considering an acquire interest being stale
50
101
-`--expected-build-count` (4) - number of parallel builds to be expected for a given merge group
51
102
52
103
#### STM of status transformations
@@ -183,47 +234,3 @@ sequenceDiagram
183
234
```
184
235
185
236
186
-
187
-
### GithubAction
188
-
The GithubAction component of this repo interacts with the LeaseProvider and determines the priority of each run based on the commits ahead of the base.
189
-
It has two stages:
190
-
1. Acquiring a lease
191
-
2. Releasing a lease when (1) has been successful, reporting the Github action job status
192
-
193
-
An example workflow can look like this:
194
-
```yaml
195
-
on:
196
-
# Trigger on PRs; here we just skip
197
-
pull_request:
198
-
branches: [ main ]
199
-
# Trigger on the merge group event
200
-
merge_group:
201
-
branches: [ main ]
202
-
types: [ checks_requested ]
203
-
204
-
jobs:
205
-
access-shared-resource:
206
-
runs-on: ubuntu-latest
207
-
if: ${{ github.event_name == 'merge_group' }}
208
-
steps:
209
-
- name: Checkout Plugin Repository
210
-
uses: actions/checkout@v3
211
-
- name: Aquire lease
212
-
id: acquire_lease
213
-
uses: ankorstore/mq-lease-service@main
214
-
with:
215
-
# Endpoint to connect to
216
-
endpoint: https://your.lease.service.com
217
-
# **IMPORTANT** the job-status always has to be defined like this
218
-
job_status: ${{ job.status }}
219
-
# Optional: timeout_seconds (how long to wait before something is considered going wrong)
220
-
# timeout_seconds: 7200
221
-
# Optional: interval_seconds (the polling interval)
222
-
# timeout_seconds: 15
223
-
- name: sleep
224
-
# Only perform github actions when this run acquired the lease
0 commit comments