fix(healthcheck): new flag implemented as a file for health checking in POL (it only... 93/9093/2 v7.0 v7.1.2 v7.1.3 v7.1.4 v7.1.5
authorbravof <fbravo@whitestack.com>
Thu, 11 Jun 2020 22:50:32 +0000 (18:50 -0400)
committerpalsus <subhankar.pal@altran.com>
Tue, 16 Jun 2020 13:38:40 +0000 (15:38 +0200)
Change-Id: I7fac1e4f219526b9ac7a4e28f1be1b456d365b5d
Signed-off-by: bravof <fbravo@whitestack.com>
(cherry picked from commit 946821f0dcc61f0bf0fe6d78bc2dc7db2636296c)

docker/Dockerfile
osm_policy_module/cmd/policy_module_agent.py
osm_policy_module/cmd/policy_module_healthcheck.py
osm_policy_module/core/agent.py

index a3cb316..7045b0f 100644 (file)
@@ -20,9 +20,9 @@
 # contact: bdiaz@whitestack.com or glavado@whitestack.com
 ##
 
-FROM ubuntu:16.04
+FROM ubuntu:20.04
 
-LABEL authors="Benjamín Díaz"
+LABEL authors="Benjamín Díaz, Fabián Bravo"
 
 RUN apt-get --yes update \
  && apt-get --yes install python3 python3-pip libmysqlclient-dev git mysql-client \
@@ -47,7 +47,7 @@ ENV OSMPOL_SQL_DATABASE_URI sqlite:///policy_module.db
 
 ENV OSMPOL_GLOBAL_LOGLEVEL INFO
 
-HEALTHCHECK --interval=5s --timeout=2s --retries=12 \
+HEALTHCHECK --interval=10s --timeout=5s --retries=10 --start-period=30s \
   CMD osm-pol-healthcheck || exit 1
 
 CMD /bin/bash /policy_module/docker/scripts/start.sh
\ No newline at end of file
index af2f602..e6c0681 100644 (file)
@@ -25,6 +25,7 @@ import argparse
 import asyncio
 import logging
 import sys
+import os
 
 from osm_policy_module.core.agent import PolicyModuleAgent
 from osm_policy_module.core.config import Config
@@ -32,6 +33,10 @@ from osm_policy_module.core.database import DatabaseManager
 
 
 def main():
+    # Cleanup old temp health file
+    if os.path.exists('/tmp/osm_pol_agent_health_flag'):
+        os.remove('/tmp/osm_pol_agent_health_flag')
+
     parser = argparse.ArgumentParser(prog='osm-policy-agent')
     parser.add_argument('--config-file', nargs='?', help='POL configuration file')
     args = parser.parse_args()
index f184afd..de85ad0 100644 (file)
@@ -23,6 +23,7 @@ import argparse
 import logging
 import subprocess
 import sys
+import os
 
 log = logging.getLogger(__name__)
 
@@ -52,7 +53,12 @@ def _processes_running():
         if not _contains_process(processes_running, p):
             log.error("Process %s not running!" % p)
             return False
-    return True
+
+    # Check if process is running properly (listening to kafka bus)
+    if os.path.exists('/tmp/osm_pol_agent_health_flag'):
+        return True
+    else:
+        return False
 
 
 if __name__ == '__main__':
index 34b852a..3f87d16 100644 (file)
@@ -23,6 +23,8 @@
 ##
 import asyncio
 import logging
+from pathlib import Path
+import os
 
 import peewee
 
@@ -52,14 +54,18 @@ class PolicyModuleAgent:
         self.loop.run_until_complete(self.start())
 
     async def start(self):
+        Path('/tmp/osm_pol_agent_health_flag').touch()
         topics = [
             "ns",
             "alarm_response"
         ]
         await self.msg_bus.aioread(topics, self._process_msg)
         log.critical("Exiting...")
+        if os.path.exists('/tmp/osm_pol_agent_health_flag'):
+            os.remove('/tmp/osm_pol_agent_health_flag')
 
     async def _process_msg(self, topic, key, msg):
+        Path('/tmp/osm_pol_agent_health_flag').touch()
         log.debug("_process_msg topic=%s key=%s msg=%s", topic, key, msg)
         try:
             if key in ALLOWED_KAFKA_KEYS: