blob: 1d2358e941681014ea05f6d4f3d67af8bdcd9f98 [file] [log] [blame]
Thomas Lee S9f0da512019-09-27 21:09:25 +05301#
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#
16from SimpleHTTPServer import SimpleHTTPRequestHandler
17from structlog import get_logger
Thomas Lee S9f0da512019-09-27 21:09:25 +053018log = get_logger()
19
20class Probe(SimpleHTTPRequestHandler):
21
David Bainbridge006dc842019-11-22 02:05:32 +000022 connection_manager = None
23
Thomas Lee S9f0da512019-09-27 21:09:25 +053024 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
David Bainbridge006dc842019-11-22 02:05:32 +000034 if Probe.connection_manager is None or Probe.connection_manager.liveness_probe():
Thomas Lee S9f0da512019-09-27 21:09:25 +053035 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
David Bainbridge006dc842019-11-22 02:05:32 +000043 if Probe.connection_manager is not None and Probe.connection_manager.readiness_probe():
Thomas Lee S9f0da512019-09-27 21:09:25 +053044 self.send_response(200)
45 self.end_headers()
46 else :
47 self.send_response(418)
48 self.end_headers()