teslamateapi
teslamateapi copied to clipboard
Feature: adding support for k8s health endpoints
Adds two new endpoints to application so that kubernetes can monitor it.
- GET
/api/healthz
- GET
/api/readyz
fix #190
@LelandSindt, if I recall you are running TeslaMateApi in a k8s cluster. Do you want to try if the implementation is working as it should? :)
@tobiasehlert I will have a look at the changes this weekend. Thank you.
Kudos, SonarCloud Quality Gate passed!
0 Bugs
0 Vulnerabilities
0 Security Hotspots
0 Code Smells
No Coverage information
0.0% Duplication
Initial test.. the endpoints are returning 404.. :thinking:
2022/07/16 20:15:02.683439 [info] TeslaMateApi running in release mode.image
2022/07/16 20:15:02.689837 [info] initAuthToken - environment variable API_TOKEN is set and good.
2022/07/16 20:15:02.689892 [info] getAllowList COMMANDS from environment variables set, allow_list.json will be ignored.
2022/07/16 20:15:02.694050 [warning] TeslaMateAPICarsStatusV1 unexpected topic format (teslamate/cars/1/speed) - ignoring message: too many operands
[GIN] 2022/07/16 - 20:15:05 | 404 | 83.337µs | 10.42.0.1 | GET "/healthz"
[GIN] 2022/07/16 - 20:15:05 | 404 | 34.973µs | 10.42.0.1 | GET "/readyz"
[GIN] 2022/07/16 - 20:15:08 | 404 | 44.007µs | 10.42.0.1 | GET "/healthz"
[GIN] 2022/07/16 - 20:15:08 | 404 | 31.935µs | 10.42.0.1 | GET "/readyz"
[GIN] 2022/07/16 - 20:15:11 | 404 | 59.791µs | 10.42.0.1 | GET "/healthz"
[GIN] 2022/07/16 - 20:15:11 | 404 | 55.227µs | 10.42.0.1 | GET "/readyz"
[GIN] 2022/07/16 - 20:15:11 | 404 | 36.639µs | 10.42.0.1 | GET "/readyz"
my config is here... https://github.com/wizardlyEinstein/teslamate/commit/c526bb2f4f21ba92d4634867226b7c179bf3a271
I will continue to review as time allows.
Initial test.. the endpoints are returning 404.. :thinking:
@LelandSindt, i changed the endpoints to be located under /api/xxx at a later commit to the feature branch. It's not available in edge yet either, so try the separate tag for it :-)
https://github.com/wizardlyEinstein/teslamate/commit/a422e1dd9332964939d43b050c7d309f92148c3e
much better..
2022/07/16 20:31:37.260361 [info] webserver - (/api/readyz) executed successfully.
[GIN] 2022/07/16 - 20:31:37 | 200 | 74.082µs | 10.42.0.1 | GET "/api/readyz"
[GIN] 2022/07/16 - 20:31:39 | 200 | 40.775µs | 10.42.0.1 | GET "/api/healthz"
sudo kubectl describe pod --namespace teslamate teslamateapi-78666f87f4-nwxsv
Name: teslamateapi-78666f87f4-nwxsv
Namespace: teslamate
Priority: 0
....
Containers:
teslamatepai:
Container ID: containerd://9fea903f837271ce77ab43bb038efa38042bc1a4bf9eef44a2954ffbab763218
Image: tobiasehlert/teslamateapi:feature-k8s-health-endpoints
Image ID: docker.io/tobiasehlert/teslamateapi@sha256:3ae07f0c74655e4fb96d3eb8dac88da815d5b4e0bd0016dc9ac0a7c6611bb298
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Sat, 16 Jul 2022 15:31:34 -0500
Ready: True
Restart Count: 0
Liveness: http-get http://:8080/api/healthz delay=3s timeout=1s period=3s #success=1 #failure=3
Readiness: http-get http://:8080/api/readyz delay=3s timeout=1s period=3s #success=1 #failure=3
Environment:
MQTT_HOST: mosquitto-mqtt.mosquitto.svc.cluster.local
DATABASE_HOST: postgresql.teslamate.svc.cluster.local
ENABLE_COMMANDS: true
COMMANDS_ALL: true
API_TOKEN: <set to the key 'API_TOKEN' in secret 'secrets-8dh4cm7f79'> Optional: false
DATABASE_USER: teslamate
DATABASE_PASS: <set to the key 'postgresql-password' in secret 'secrets-8dh4cm7f79'> Optional: false
DATABASE_NAME: teslamate
ENCRYPTION_KEY: <set to the key 'teslamate-key' in secret 'secrets-8dh4cm7f79'> Optional: false
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-gqjv8 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
going to have to think about how best to cause/test failure...
going to have to think about how best to cause/test failure...
@LelandSindt, should be possible to test by turning off mqtt and then starting TeslaMateApi. Or just configure TeslaMateApi to point to a non-existing mqtt, which would not set it to "ready".
sounds about right.. will test this evening...
When I stop mostquitto
teslamateapi
's behaviour does not change... :thinking:
You can use the following script to emulate kubernetes health checks...
while true; do curl -i 192.168.1.50:18080/api/v1/cars/1/status; echo; curl -i 192.168.1.50:18080/api/healthz; echo; curl -i 192.168.1.50:18080/api/readyz; sleep 1; clear; done
All three curl
calls return 200 OK
independent of the state of mostquitto