Zack Williams | 9731cdc | 2019-11-22 15:42:30 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 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 | # |
| 16 | from SimpleHTTPServer import SimpleHTTPRequestHandler |
| 17 | from structlog import get_logger |
| 18 | log = get_logger() |
| 19 | |
| 20 | class Probe(SimpleHTTPRequestHandler): |
| 21 | |
| 22 | connection_manager = None |
| 23 | |
| 24 | def do_GET(self): |
| 25 | |
| 26 | if self.path == '/healthz': |
| 27 | self.health_probe() |
| 28 | |
| 29 | elif self.path == '/readz': |
| 30 | self.ready_probe() |
| 31 | |
| 32 | def health_probe(self): |
| 33 | |
| 34 | if Probe.connection_manager is None or Probe.connection_manager.liveness_probe(): |
| 35 | self.send_response(200) |
| 36 | self.end_headers() |
| 37 | else : |
| 38 | self.send_response(418) |
| 39 | self.end_headers() |
| 40 | |
| 41 | def ready_probe(self): |
| 42 | |
| 43 | if Probe.connection_manager is not None and Probe.connection_manager.readiness_probe(): |
| 44 | self.send_response(200) |
| 45 | self.end_headers() |
| 46 | else : |
| 47 | self.send_response(418) |
| 48 | self.end_headers() |