Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
(Mostly) Logging fixes (#70)
Browse files Browse the repository at this point in the history
* Add Helm chart

* Add 'tracectx.transactionid' to logging, add support for logstash formatted (json) logging

* https://www.nomadproject.io/docs/internals/scheduling.html, add support for flat/text and logstash compatible logs files (to help with pushing logs to Elasticsearch), add persistent volume for Ansible RM, bump RM version

* Revert changes to docker compose script, tidy up config file

* Add missing PersistentVolume template, tidy up code

* Minor Readme update

* Minor values.yaml update

* NFV-2455 #37 support https

* Fix up logging import

* NFV-2455 #37 fix up Kubernetes service ports to include https

* NFV-2455 #37 remove bundled SSL certificate in favour of an SSL certificate "injected" by Kubernetes as a volume

* NFV-2455 #37 make SSL optional (default to http)

* NFV-2455 #37 change persistent volume directory names

* NFV-2455 #37 change persistent volume directory names

* Add README for Helm chart

* NFV-2455 #37 fix up SSL configuration switch (boolean handling)

* NFV-2455 #37 make http port the default, add information on how to install for https

* Minor updates: allow Kubernetes SSL Nodeport for Ansible RM to be set explicitly, bump version number to 1.3.0

* Output Ansible logs to "main" log, make SSL enabled by default when installing with Helm, mount SSL secret volume only if SSL is enabled

* Fix up version number to 1.3.2

* Fix up Docker image, update README

* Fix up logging levels (info reserved for informational messages only, move most logging to debug level), fix up transactionId handling from LM, make INFO default logging level

* Fix up transaction id handling (thread locals)

* Add thread name to top level log output, tidy up logs

* make sure variables are set before use, minor changes to logging statements

* Switch default logging level back to DEBUG

* Remove superfluous "@" from transactionid

* Allow Kafka replicationFactor to be configured, allow Kafka connection url to be configured, more logging based cleanup, optimize Dockerfile (create fewer layers)

* Fix up Kafka error code handling

* More logging changes (merge log statements, make log statements debug level by default)
  • Loading branch information
sglover authored and Jochen Kappel committed Mar 22, 2019
1 parent cd9d6fa commit 8a59719
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 173 deletions.
19 changes: 9 additions & 10 deletions ansible-adaptor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,25 @@ RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app/
COPY device-requirements.txt /usr/src/app/

RUN pip3 install --no-cache-dir -r requirements.txt
RUN apt-get update && apt-get install -y supervisor && \
apt-get install --reinstall -y build-essential && \
pip3 install --no-cache-dir -r requirements.txt && \
# device handling
pip3 install --no-cache-dir -r device-requirements.txt && \
# using ansible 2.6 juniper core modules + opt juniper role
ansible-galaxy install Juniper.junos && \
mkdir -p /var/log/supervisor

COPY . /usr/src/app
COPY ansible.cfg /etc/ansible/
COPY tslvault.txt /etc/ansible/
COPY ans_alm_settings.yml /etc/ansible/

# device handling
RUN pip3 install --no-cache-dir -r device-requirements.txt

# using ansible 2.6 juniper core modules + opt juniper role
RUN ansible-galaxy install Juniper.junos

# multi python process handling
RUN apt-get update && apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 8080
EXPOSE 8443
CMD ["/usr/bin/supervisord"]
#CMD ["python3","-m", "swagger_server"]
3 changes: 3 additions & 0 deletions ansible-adaptor/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ driver:
properties:
- responseKafkaConnectionUrl: "kafka:9092"
- responseKafkaTopicName: "ansible-rm"
kafka:
replicationFactor: 1

ansible:
resource_dir: "/var/alm_ansible_rm/resources"
keys_dir: "/var/alm_ansible_rm/keys"
Expand Down
14 changes: 11 additions & 3 deletions ansible-adaptor/supervisord.conf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[supervisord]
;logfile=/var/app/logs/ ; (main log file;default $CWD/supervisord.log)
;logfile=/var/app/logs/ ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
loglevel=debug ; (log level;default info; others: debug,warn,trace)
logfile_backups=5 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
Expand All @@ -15,6 +15,10 @@ command=python3 LogServer.py
user=root
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:swagger_server]
priority=5
Expand All @@ -24,3 +28,7 @@ command=python3 -m swagger_server
user=root
autostart=true
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
2 changes: 1 addition & 1 deletion ansible-adaptor/swagger_server/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
src_dir = dirname(dirname(abspath(__file__)))
try:
copy_tree(src_dir+'/driver-resources', resource_dir)
app.app.logger.info('required resources copied to :'+resource_dir)
app.app.logger.debug('required resources copied to :'+resource_dir)
except Exception as err:
app.app.logger.error(str(err))

Expand Down
6 changes: 3 additions & 3 deletions ansible-adaptor/swagger_server/controllers/ans_cassandra.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def __del__(self):
def get_session(self):
""" get a DB conenction """
if self.dbSession:
app.logger.info('using cassandra session to ' + self.keyspace)
app.logger.debug('using cassandra session to ' + self.keyspace)
else:
app.logger.info('creating cassandra session ' + self.keyspace)
app.logger.debug('creating cassandra session ' + self.keyspace)

try:
self.cluster = Cluster([self.config.cassandra_uri])

self.dbSession = self.cluster.connect()
app.logger.info('connected to cassandra, keyspace: ' + self.keyspace)
app.logger.debug('connected to cassandra, keyspace: ' + self.keyspace)
except ConnectionRefusedError as err:
app.logger.error("No connection error: {0}".format(err))
self.dbSession = None
Expand Down
12 changes: 8 additions & 4 deletions ansible-adaptor/swagger_server/controllers/ans_driver_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,27 @@ def __init__(self):
app.logger.critical('configuration file config.yml not found')
raise FileNotFoundError

app.logger.info('loading configuration')
app.logger.debug('loading configuration')
self.driver_name = cfg['driver']['name']
self.driver_version = cfg['driver']['version']
self.requests_ttl = os.environ.get('cassandra_ttl', None) or cfg['cassandra']['ttl']
self.cassandra_uri = os.environ.get('cassandra_uri', None) or cfg['cassandra']['uri']
self.kafka_replicationFactor = int(os.environ.get('kafka_replicationFactor')) or int(cfg['driver']['kafka']['replicationFactor'])

self.resource_dir = os.environ.get('ansible_resource_dir', None) or cfg['ansible']['resource_dir']
app.logger.debug('check for resource folder: ' + self.resource_dir)
# check if configured directory exists:
if not os.path.isdir(self.resource_dir):
app.logger.warning('resource folder ' + self.resource_dir + ' does not exist')
app.logger.info('creating resource folder ' + self.resource_dir)
app.logger.debug('creating resource folder ' + self.resource_dir)
os.mkdir(self.resource_dir)

self.keys_dir = os.environ.get('ansible_keys_dir', None) or cfg['ansible']['keys_dir']
app.logger.debug('check for keys folder: ' + self.keys_dir)
# check if configured directory exists:
if not os.path.isdir(self.keys_dir):
app.logger.warning('keys folder ' + self.keys_dir + ' does not exist')
app.logger.info('creating keys folder ' + self.keys_dir)
app.logger.debug('creating keys folder ' + self.keys_dir)
os.mkdir(self.keys_dir)

tmp = os.environ.get('ssl_enabled', None)
Expand Down Expand Up @@ -79,12 +80,15 @@ def getKeysDir(self):
""" get keypair directory """
return self.keys_dir

def getKafkaReplicationFactor(self):
return self.kafka_replicationFactor

def getDriverProperties(self, property):
""" get driver properties """
if property == None:
return self.supported_properties
else:
return self.supported_properties[property]
return os.environ.get('driver_' + property, None) or self.supported_properties[property]

def getSupportedFeatures(self):
""" get supported features """
Expand Down
Loading

0 comments on commit 8a59719

Please sign in to comment.