Elffuss BraidHub

kikocis/EDC public

main · 4.4 KiBRenderedRawPermalink
1# Connector Observability API
2
3This API exposes information about this runtime's health status by accessing the internal `HealthCheckService`. In order
4to use it add the following line to your `build.gradle[.kts]`:
5
6```kotlin
7implementation(project(":extensions:common:api:api-observability"))
8// or using maven artifacts in downstream projects:
9implementation("org.eclipse.edc:api-observability:${EDC_VERSION}")
10```
11
12All endpoints described here have the same simple API:
13
14- they support the `GET` method without query params
15- if the health check is successful, i.e. _all_ systems are healthy, HTTP 200 is returned with the `HealthStatus` object
16 in the response body
17- if one of the systems is unhealthy, an HTTP 503 is returned with the `HealthStatus` object in the response body
18
19## Endpoint description
20
21### `GET /check/health`
22
23returns information about the system status. This is primarily intended to be used
24in [`HEALTHCHECK` instructions in Docker files](https://docs.docker.com/engine/reference/builder/#healthcheck). Here,
25this endpoint will return HTTP 200 indicating that the system is healthy as soon as the connector has finished starting.
26Therefore, the `/check/health` and `/check/startup` endpoints will have the same behaviour.
27
28### `GET /check/liveness`
29
30From the [Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes):
31> indicates whether the container is running.
32
33We can assume, that in the event that the connector crashes, all REST endpoints become unavailable.
34
35### `GET /check/readiness`
36
37From the [Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes):
38> Indicates whether the container is ready to respond to requests.
39
40Thus, the readiness endpoint must return a value indicating success _only after_ all extensions that contribute an API
41have started successfully. Note, that other subsystems like the catalog crawlers might not yet be completed at that
42point, but technically the connector is "ready to respond to requests", even if they might not produce the desired - or
43even a sensible - outcome. Catalog queries may produce an empty or incomplete result until crawlers have completed.
44
45### `GET /check/startup`
46
47From the [Kubernetes docs](https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#container-probes):
48> Indicates whether the application within the container is started
49
50This is very similar to the `/check/readiness` endpoint, but a connector may be able to respond to requests as soon as
51all extensions contributing APIs (e.g. REST controllers) have been registered, thus being `ready`, whereas the startup
52is only completed after _all_ extensions have started. This can only be determined by the runtime. Again, parallel
53subsystems like crawlers will **not** affect system startup state.
54
55## Usage in Dockerfiles
56
57Docker supports [health check](https://docs.docker.com/engine/reference/builder/#healthcheck) commands. In order to use
58the Observability API for that, simply add this line to your `Dockerfile`:
59
60```dockerfile
61# health status is determined by the availability of the /health endpoint
62HEALTHCHECK --interval=5s --timeout=5s --retries=10 CMD curl --fail -X GET http://localhost:8181/api/check/health || exit 1
63
64# ENTRYPOINT left out for clarity
65```
66
67Adjust the interval, timeout and retries to your convenience. Depending on your base image, you might not need to
68install `curl`. However, if it is not present at container runtime, the `HEALTHCHECK` will always fail and the container
69will eventually become `unhealthy`.
70
71## Usage in Kubernetes files
72
73Regardless of how you deploy the connector to K8S (perhaps a `deployment`), you can add the following section to your
74container definition:
75
76```kubernetes helm
77# ...
78 spec:
79 containers:
80 - name: yourContainerName
81 imagePullPolicy: IfNotPresent
82 image: yourRepo/YourImageName
83 ports:
84 - name: http
85 containerPort: 8181
86
87 readinessProbe:
88 initialDelaySeconds: 1
89 periodSeconds: 5
90 httpGet:
91 port: http
92 path: /api/check/readiness
93
94 livenessProbe:
95 initialDelaySeconds: 3
96 periodSeconds: 5
97 httpGet:
98 port: http
99 path: /api/check/liveness
100
101 startupProbe:
102 initialDelaySeconds: 1
103 periodSeconds: 3
104 httpGet:
105 port: http
106 path: /api/startup
107```