--- /dev/null
+..
+ This work is licensed under a Creative Commons Attribution 4.0
+ International License.
+
+=================
+Multi-Vim logging
+=================
+
+The purpose of logging is to generate machine-readable, indexable output logs and support to trace
+requests through sub-component, it need to ship logs to logging enhancement project a centralized
+logging analysis system capturing diagnostic information.
+
+
+
+Problem Description
+===================
+
+So far the logging of multi-vim is not able to support customer configuration, handler context specific logging like
+MDC[MDC_Document]_, also it dose't propagate transaction-ID in REST headers which is critical to tracing request.
+There are 4 python containers in oom project need to configure filebeat container for shipping logs.
+
+.. [MDC_Document] https://wiki.onap.org/display/DW/ONAP+Application+Logging+Guidelines+v1.1#ONAPApplicationLoggingGuidelinesv1.1-MDCs
+
+In addition the current logging is very difficult to understand behavior and performance.
+
+
+Proposed Change
+===============
+
+The proposed change will include three parts.
+
+Filebeat container
+------------------
+
+Logging architecture[Log_Architecture]_ use Filebeat collects logs from multi-vim containers and ships them to the
+centralized logging stack. To enable this feature it need to add Filebeat container in multi-vim pod that was
+deployed by OOM, as well Yaml file will be used to configure Filebeat.
+
+.. [Log_Architecture] https://wiki.onap.org/display/DW/Logging+Architecture
+
+Tracing ID
+----------
+
+ONAP logging uses a global unique "RequestID"[RequestID_Document]_ in logging to track the processing of each request
+across all the components, multi-vim will receive this id from http header by vary "X-TransactionID", then record it
+in logs.
+Meanwhile single component should generate a InvocationID that records the relationship between RequestID
+and InvocationID for proper tracing. So Mulit-vim will set unique InvocationID for each single request,also output it
+in logs.
+
+.. [RequestID_Document] https://wiki.onap.org/pages/viewpage.action?pageId=20087036#ONAPApplicationLoggingGuidelinesv1.2(Beijing)-MDC-RequestID
+
+
+python AOP logging library
+--------------------------
+
+Currently logging enhancement project just has java AOP logging library, For multi-vim which based on python need
+a python version. The basic feature of AOP logging library could provide customer configuration include retention
+policy、output location、text output format、message level and so on, support MDC context specific logging, able to
+change configuration at runtime, and make logging quite fast.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-# Copyright (c) 2017 Wind River Systems, Inc.
-# Copyright (c) 2017-2018 VMware, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at:
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-
-import time
-
-import redis
-
-from multivimbroker.pub.config.config import REDIS_HOST
-from multivimbroker.pub.config.config import REDIS_PORT
-from multivimbroker.pub.config.config import REDIS_PASSWD
-
-
-class SharedLock:
- def __init__(self, lock_key, host=REDIS_HOST, port=REDIS_PORT,
- password=REDIS_PASSWD, db=9, lock_timeout=5 * 60):
- self.lock_key = lock_key
- self.lock_timeout = lock_timeout
- self.redis = redis.Redis(host=host, port=port,
- db=db, password=password)
- self.acquire_time = -1
-
- def acquire(self):
- begin = now = int(time.time())
- while (now - begin) < self.lock_timeout:
-
- result = self.redis.setnx(self.lock_key, now +
- self.lock_timeout + 1)
- if result == 1 or result is True:
- self.acquire_time = now
- return True
-
- current_lock_timestamp = self.redis.get(self.lock_key)
- if not current_lock_timestamp:
- time.sleep(1)
- continue
-
- current_lock_timestamp = int(current_lock_timestamp)
-
- if now > current_lock_timestamp:
- next_lock_timestamp = self.redis.getset(self.lock_key, now +
- self.lock_timeout + 1)
- if not next_lock_timestamp:
- time.sleep(1)
- continue
- next_lock_timestamp = int(next_lock_timestamp)
-
- if next_lock_timestamp == current_lock_timestamp:
- self.acquire_time = now
- return True
- else:
- time.sleep(1)
- continue
- return False
-
- def release(self):
- now = int(time.time())
- if now > self.acquire_time + self.lock_timeout:
- # key expired, do nothing and let other clients handle it
- return
- self.acquire_time = None
- self.redis.delete(self.lock_key)
-
-
-def do_biz_with_share_lock(lock_name, callback):
- lock = SharedLock(lock_name)
- try:
- if not lock.acquire():
- raise Exception(lock_name + " timeout")
- callback()
- except Exception as e:
- raise e
- finally:
- lock.release()