blob: ca58652ef67b6e1f847579312190942f3f1b1983 [file] [log] [blame]
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +00001#
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 Jeanneret2e3cb8d2019-11-16 09:22:41 -050016from http.server import SimpleHTTPRequestHandler
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +000017from structlog import get_logger
18
19log = get_logger()
20
21class Probe(SimpleHTTPRequestHandler):
Neha Sharma61446d32020-03-23 14:32:31 +000022 # Checks for Onu Adapter Readiness; all should be true
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +000023 kafka_cluster_proxy_running = False
Neha Sharma61446d32020-03-23 14:32:31 +000024 kafka_adapter_proxy_running = False
25 adapter_registered_with_core = False
26
27 # Only Kafka connectivity check defines Liveness
28 kafka_proxy_faulty = True
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +000029
30 def readiness_probe(self):
Neha Sharma61446d32020-03-23 14:32:31 +000031 return Probe.kafka_adapter_proxy_running and Probe.kafka_cluster_proxy_running and Probe.adapter_registered_with_core
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +000032
33 def liveness_probe(self):
Neha Sharma61446d32020-03-23 14:32:31 +000034 return not Probe.kafka_proxy_faulty
Rohan Agrawalc5bdbbc2019-11-14 12:39:39 +000035
36 def do_GET(self):
37 if self.path == '/readz':
38 self.ready_probe()
39 elif self.path == '/healthz':
40 self.health_probe()
41
42 def ready_probe(self):
43 if self.readiness_probe():
44 self.send_response(200)
45 self.end_headers()
46 else :
47 self.send_response(418)
48 self.end_headers()
49
50 def health_probe(self):
51 if self.liveness_probe():
52 self.send_response(200)
53 self.end_headers()
54 else :
55 self.send_response(418)
56 self.end_headers()