Rohan Agrawal | c5bdbbc | 2019-11-14 12:39:39 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2019 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Matt Jeanneret | 2e3cb8d | 2019-11-16 09:22:41 -0500 | [diff] [blame] | 16 | from http.server import SimpleHTTPRequestHandler |
Rohan Agrawal | c5bdbbc | 2019-11-14 12:39:39 +0000 | [diff] [blame] | 17 | from structlog import get_logger |
| 18 | |
| 19 | log = get_logger() |
| 20 | |
| 21 | class Probe(SimpleHTTPRequestHandler): |
| 22 | kafka_adapter_proxy_running = False |
| 23 | kafka_cluster_proxy_running = False |
| 24 | register_adapter_with_core = False |
| 25 | |
| 26 | def readiness_probe(self): |
| 27 | return Probe.kafka_adapter_proxy_running and Probe.kafka_cluster_proxy_running and Probe.register_adapter_with_core |
| 28 | |
| 29 | def liveness_probe(self): |
| 30 | return Probe.kafka_adapter_proxy_running and Probe.kafka_cluster_proxy_running and Probe.register_adapter_with_core |
| 31 | |
| 32 | def do_GET(self): |
| 33 | if self.path == '/readz': |
| 34 | self.ready_probe() |
| 35 | elif self.path == '/healthz': |
| 36 | self.health_probe() |
| 37 | |
| 38 | def ready_probe(self): |
| 39 | if self.readiness_probe(): |
| 40 | self.send_response(200) |
| 41 | self.end_headers() |
| 42 | else : |
| 43 | self.send_response(418) |
| 44 | self.end_headers() |
| 45 | |
| 46 | def health_probe(self): |
| 47 | if self.liveness_probe(): |
| 48 | self.send_response(200) |
| 49 | self.end_headers() |
| 50 | else : |
| 51 | self.send_response(418) |
| 52 | self.end_headers() |