blob: 1d2358e941681014ea05f6d4f3d67af8bdcd9f98 [file] [log] [blame]
Zack Williams9731cdc2019-11-22 15:42:30 -07001#
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
18log = get_logger()
19
20class 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()