Disable assert statements in production build 39/7839/3
authorsantanude <santanu.de@xoriant.com>
Thu, 24 Feb 2022 15:09:42 +0000 (20:39 +0530)
committersantanude <santanu.de@xoriant.com>
Mon, 28 Feb 2022 07:16:23 +0000 (12:46 +0530)
A production version of the image should have the assert statements as a no-op, and should instead return an error code, instead of asserting and crashing the system.

SMO-47

Signed-off-by: santanude <santanu.de@xoriant.com>
Change-Id: Ia79d1cdf3e0adee756446d1c20a37ee8e2e0260d
Signed-off-by: santanude <santanu.de@xoriant.com>
collector/start.sh
dmaapadapter/adapter/code/app_config.py
dmaapadapter/adapter/code/dmaap_adapter.py
dmaapadapter/adapter/config/adapter.conf
dmaapadapter/start.sh
docker-compose.yaml
influxdb-connector/start.sh

index 9e1c6e2..49a4311 100755 (executable)
@@ -59,11 +59,23 @@ echo; echo $config_file
 cat $config_file
 
 if [ "$loglevel" != "" ]; then
-  python3 /opt/smo/evel-test-collector/code/collector/monitor.py \
-    --config /opt/smo/evel-test-collector/config/collector.conf \
-    --section default > /opt/smo/monitor.log 2>&1
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/evel-test-collector/code/collector/monitor.py \
+      --config /opt/smo/evel-test-collector/config/collector.conf \
+      --section default > /opt/smo/monitor.log 2>&1
+  else
+    python3 /opt/smo/evel-test-collector/code/collector/monitor.py \
+      --config /opt/smo/evel-test-collector/config/collector.conf \
+      --section default > /opt/smo/monitor.log 2>&1
+  fi
 else
-  python3 /opt/smo/evel-test-collector/code/collector/monitor.py \
-    --config /opt/smo/evel-test-collector/config/collector.conf \
-    --section default
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/evel-test-collector/code/collector/monitor.py \
+      --config /opt/smo/evel-test-collector/config/collector.conf \
+      --section default
+  else
+    python3 /opt/smo/evel-test-collector/code/collector/monitor.py \
+      --config /opt/smo/evel-test-collector/config/collector.conf \
+      --section default
+  fi
 fi
index f64ab0b..2064e32 100644 (file)
@@ -21,6 +21,7 @@ import logging.handlers
 class AppConfig:
     kafka_broker = ""
     logger = logging.getLogger()
+    enable_assert = ""
 
     def __init__(self):
         parser = ArgumentParser(description="",
@@ -45,6 +46,7 @@ class AppConfig:
         config.read(config_file)
 
         self.kafka_broker = config.get(config_section, 'kafka_broker', vars=overrides)
+        self.enable_assert = config.get(config_section, 'enable_assert', vars=overrides)
         log_file = config.get(config_section, 'log_file', vars=overrides)
         log_level = config.get(config_section, 'log_level', vars=overrides)
 
@@ -57,6 +59,9 @@ class AppConfig:
     def getKafkaBroker(self):
         return self.kafka_broker
 
+    def getAssertConfigValue(self):
+        return self.enable_assert
+
     def getLogger(self):
         return self.logger
 
index e3042e2..df8d2a4 100644 (file)
@@ -17,6 +17,7 @@ import flask
 from flask import request
 from consumer import EventConsumer, TopicConsumer
 from prepare_response import PrepareResponse
+from app_config import AppConfig
 
 app = flask.Flask(__name__)
 app.config["DEBUG"] = True
@@ -52,7 +53,7 @@ def listall_topics():
 
 @app.route(api_base_url + '/topics/<topic>', methods=['GET'])
 def topic_details(topic):
-    assert topic == request.view_args['topic']
+    topic == request.view_args['topic']
     prepareResponse = PrepareResponse()
     topicConsumer = TopicConsumer()
     topicConsumer.getTopicDetails(prepareResponse, topic)
@@ -64,9 +65,9 @@ def topic_details(topic):
 
 @app.route(api_base_url + '/events/<topic>/<consumergroup>/<consumerid>', methods=['GET'])
 def get_events(topic, consumergroup, consumerid):
-    assert topic == request.view_args['topic']
-    assert consumergroup == request.view_args['consumergroup']
-    assert consumerid == request.view_args['consumerid']
+    topic == request.view_args['topic']
+    consumergroup == request.view_args['consumergroup']
+    consumerid == request.view_args['consumerid']
     limit = ""
     timeout = ""
 
@@ -105,4 +106,9 @@ def getTimeout(timeout):
 
 
 if __name__ == '__main__':
-    app.run(debug=True, host='0.0.0.0')
+    appConfig = AppConfig()
+
+    if(appConfig.getAssertConfigValue() == 'False'):
+        app.run(debug=False, host='0.0.0.0')
+    else:
+        app.run(debug=True, host='0.0.0.0')
index 0f86b96..1fb7a43 100755 (executable)
@@ -6,4 +6,4 @@
 log_file = dmaap.log
 log_level =
 kafka_broker =
-
+enable_assert =
index 11d6f7f..1254e2e 100755 (executable)
@@ -22,6 +22,8 @@ sed -i -- "s/kafka_broker =/kafka_broker = $kafka_host:$kafka_port/g" \
   $config_file
 sed -i -- "s/log_level =/log_level = $log_level/g" \
   $config_file
+sed -i -- "s/enable_assert =/enable_assert = $enable_assert/g" \
+  $config_file
 
 
 echo; echo $config_file
@@ -29,11 +31,23 @@ cat $config_file
 
 
 if [ "$log_level" != "" ]; then
-  python3 /opt/smo/adapter/code/dmaap_adapter.py \
-    --config /opt/smo/adapter/config/adapter.conf \
-    --section default > /opt/smo/dmaap.log 2>&1
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/adapter/code/dmaap_adapter.py \
+      --config /opt/smo/adapter/config/adapter.conf \
+      --section default > /opt/smo/dmaap.log 2>&1
+  else
+    python3 /opt/smo/adapter/code/dmaap_adapter.py \
+      --config /opt/smo/adapter/config/adapter.conf \
+      --section default > /opt/smo/dmaap.log 2>&1
+  fi
 else
-  python3 /opt/smo/adapter/code/dmaap_adapter.py \
-    --config /opt/smo/adapter/config/adapter.conf \
-    --section default
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/adapter/code/dmaap_adapter.py \
+      --config /opt/smo/adapter/config/adapter.conf \
+      --section default
+   else
+     python3 /opt/smo/adapter/code/dmaap_adapter.py \
+       --config /opt/smo/adapter/config/adapter.conf \
+       --section default
+   fi
 fi
index 8471ce5..6707ec7 100644 (file)
@@ -114,6 +114,7 @@ services:
              kafka_host: "smo-kafka"
              kafka_port: "29092"
              log_level: "DEBUG"
+             enable_assert: "False"
   smo-collector:
          container_name: smo-collector
          build: ./collector
@@ -137,6 +138,7 @@ services:
                  collector_pass: "password"
                  collector_path: ""
                  loglevel: "ERROR"
+                 enable_assert: "False"
          depends_on:
              - smo-kafka
   smo-influxdb-connector:
@@ -153,6 +155,7 @@ services:
                  smo_kafka_host: "smo-kafka"
                  smo_kafka_port: "29092"
                  loglevel: "ERROR"
+                 enable_assert: "False"
          depends_on:
              - smo-kafka
              - smo-influxdb
index e7d0ecb..f438502 100755 (executable)
@@ -45,13 +45,27 @@ curl -X POST http://$smo_influxdb_host:$smo_influxdb_port/query \
   --data-urlencode "q=CREATE DATABASE eventsdb"
 
 if [ "$loglevel" != "" ]; then
-  python3 /opt/smo/influxdb-connector/code/influxdb_connector.py \
-    --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
-    --influxdb $smo_influxdb_host:$smo_influxdb_port \
-    --section default > /opt/smo/monitor.log 2>&1
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/influxdb-connector/code/influxdb_connector.py \
+     --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
+     --influxdb $smo_influxdb_host:$smo_influxdb_port \
+     --section default > /opt/smo/monitor.log 2>&1
+  else
+    python3 /opt/smo/influxdb-connector/code/influxdb_connector.py \
+      --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
+      --influxdb $smo_influxdb_host:$smo_influxdb_port \
+      --section default > /opt/smo/monitor.log 2>&1
+  fi
 else
-  python3 /opt/smo/influxdb-connector/code/influxdb_connector.py  \
-    --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
-    --influxdb $smo_influxdb_host:$smo_influxdb_port \
-    --section default
+  if [ "$enable_assert" != "True" ]; then
+    python3 -O /opt/smo/influxdb-connector/code/influxdb_connector.py  \
+      --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
+      --influxdb $smo_influxdb_host:$smo_influxdb_port \
+      --section default
+  else
+    python3 /opt/smo/influxdb-connector/code/influxdb_connector.py  \
+      --config /opt/smo/influxdb-connector/config/influxdb_connector.conf \
+      --influxdb $smo_influxdb_host:$smo_influxdb_port \
+      --section default
+  fi
 fi