summaryrefslogtreecommitdiffstats
path: root/mgr
diff options
context:
space:
mode:
authorying.yunlong <ying.yunlong@zte.com.cn>2018-03-22 17:18:55 +0800
committerying.yunlong <ying.yunlong@zte.com.cn>2018-03-23 09:19:03 +0800
commit091bf532af44c16d4b21f149f5b0d3a76f70a48c (patch)
tree17ef0b7d752cf01e35f743166ea1544c6f4b9d79 /mgr
parent2614dcb18906b84d975bad6688dd517649ef538f (diff)
Add vfc-vnfmgr log integration config
Change-Id: I492453c20de02319cd28f601baf924dc9bfa2e42 Issue-ID: VFC-839 Signed-off-by: ying.yunlong <ying.yunlong@zte.com.cn>
Diffstat (limited to 'mgr')
-rw-r--r--mgr/mgr/log.yml50
-rw-r--r--mgr/mgr/middleware.py60
-rw-r--r--mgr/mgr/pub/config/config.py5
-rw-r--r--mgr/mgr/settings.py68
-rw-r--r--mgr/requirements.txt5
5 files changed, 158 insertions, 30 deletions
diff --git a/mgr/mgr/log.yml b/mgr/mgr/log.yml
new file mode 100644
index 0000000..e9fd1e4
--- /dev/null
+++ b/mgr/mgr/log.yml
@@ -0,0 +1,50 @@
+version: 1
+disable_existing_loggers: False
+
+loggers:
+ mgr:
+ handlers: [vnfmgrlocal_handler, vnfmgr_handler]
+ level: "DEBUG"
+ propagate: False
+ django:
+ handlers: [django_handler]
+ level: "DEBUG"
+ propagate: False
+handlers:
+ vnfmgrlocal_handler:
+ level: "DEBUG"
+ class:
+ "logging.handlers.RotatingFileHandler"
+ filename: "logs/runtime_mgr.log"
+ formatter:
+ "standard"
+ maxBytes: 52428800
+ backupCount: 10
+ vnfmgr_handler:
+ level: "DEBUG"
+ class:
+ "logging.handlers.RotatingFileHandler"
+ filename: "/var/log/onap/vfc-gvnfm-vnfmgr/runtime_mgr.log"
+ formatter:
+ "mdcFormat"
+ maxBytes: 52428800
+ backupCount: 10
+ django_handler:
+ level: "DEBUG"
+ class:
+ "logging.handlers.RotatingFileHandler"
+ filename: "logs/django.log"
+ formatter:
+ "standard"
+ maxBytes: 52428800
+ backupCount: 10
+formatters:
+ standard:
+ format:
+ "%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s"
+ mdcFormat:
+ format:
+ "%(asctime)s|||||%(name)s||%(thread)s||%(funcName)s||%(levelname)s||%(message)s||||%(mdc)s \t"
+ mdcfmt: "{requestID} {invocationID} {serviceName} {serviceIP}"
+ datefmt: "%Y-%m-%d %H:%M:%S"
+ (): onaplogging.mdcformatter.MDCFormatter
diff --git a/mgr/mgr/middleware.py b/mgr/mgr/middleware.py
new file mode 100644
index 0000000..10e8ba6
--- /dev/null
+++ b/mgr/mgr/middleware.py
@@ -0,0 +1,60 @@
+# Copyright (c) 2017-2018 ZTE, 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 uuid
+from onaplogging.mdcContext import MDC
+
+from mgr.pub.config.config import FORWARDED_FOR_FIELDS, SERVICE_NAME
+
+
+class LogContextMiddleware(object):
+ # the last IP behind multiple proxies, if no exist proxies
+ # get local host ip.
+ def _getLastIp(self, request):
+
+ ip = ""
+ try:
+ for field in FORWARDED_FOR_FIELDS:
+ if field in request.META:
+ if ',' in request.META[field]:
+ parts = request.META[field].split(',')
+ ip = parts[-1].strip().split(":")[0]
+ else:
+ ip = request.META[field].split(":")[0]
+
+ if ip == "":
+ ip = request.META.get("HTTP_HOST").split(":")[0]
+
+ except Exception:
+ pass
+
+ return ip
+
+ def process_request(self, request):
+ # Fetch TRANSACTIONID Id and pass to plugin server
+ ReqeustID = request.META.get("HTTP_X_TRANSACTIONID", None)
+ if ReqeustID is None:
+ ReqeustID = uuid.uuid3(uuid.NAMESPACE_URL, SERVICE_NAME)
+ request.META["HTTP_X_TRANSACTIONID"] = ReqeustID
+ MDC.put("requestID", ReqeustID)
+ # generate the unique id
+ InovocationID = uuid.uuid3(uuid.NAMESPACE_DNS, SERVICE_NAME)
+ MDC.put("invocationID", InovocationID)
+ MDC.put("serviceName", SERVICE_NAME)
+ # access ip
+ MDC.put("serviceIP", self._getLastIp(request))
+
+ return None
+
+ def process_response(self, request, response):
+ MDC.clear()
+ return response
diff --git a/mgr/mgr/pub/config/config.py b/mgr/mgr/pub/config/config.py
index 542dbd8..9bdb193 100644
--- a/mgr/mgr/pub/config/config.py
+++ b/mgr/mgr/pub/config/config.py
@@ -28,6 +28,11 @@ DB_NAME = "gvnfm"
DB_USER = "gvnfm"
DB_PASSWD = "gvnfm"
+# [MDC]
+SERVICE_NAME = "vnfmgr"
+FORWARDED_FOR_FIELDS = ["HTTP_X_FORWARDED_FOR", "HTTP_X_FORWARDED_HOST",
+ "HTTP_X_FORWARDED_SERVER"]
+
# [register]
REG_TO_MSB_WHEN_START = True
REG_TO_MSB_REG_URL = "/api/microservices/v1/services"
diff --git a/mgr/mgr/settings.py b/mgr/mgr/settings.py
index 37c1636..ddedd75 100644
--- a/mgr/mgr/settings.py
+++ b/mgr/mgr/settings.py
@@ -19,6 +19,9 @@ import redisco
from mgr.pub.config.config import REDIS_HOST, REDIS_PORT, REDIS_PASSWD
from mgr.pub.config.config import DB_NAME, DB_IP, DB_USER, DB_PASSWD, DB_PORT
+from logging import config
+from onaplogging import monkey
+monkey.patch_all()
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
@@ -57,6 +60,7 @@ MIDDLEWARE_CLASSES = [
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
+ 'mgr.middleware.LogContextMiddleware',
]
ROOT_URLCONF = 'mgr.urls'
@@ -118,36 +122,42 @@ TIME_ZONE = 'UTC'
# https://docs.djangoproject.com/en/1.6/howto/static-files/
STATIC_URL = '/static/'
+#
+# LOGGING = {
+# 'version': 1,
+# 'disable_existing_loggers': True,
+# 'formatters': {
+# 'standard': {
+# 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
+# },
+# },
+# 'filters': {
+# },
+# 'handlers': {
+# 'mgr_handler': {
+# 'level': 'DEBUG',
+# 'class': 'logging.handlers.RotatingFileHandler',
+# 'filename': os.path.join(BASE_DIR, 'logs/runtime_mgr.log'),
+# 'formatter': 'standard',
+# 'maxBytes': 1024 * 1024 * 50,
+# 'backupCount': 5,
+# },
+# },
+#
+# 'loggers': {
+# 'mgr': {
+# 'handlers': ['mgr_handler'],
+# 'level': 'DEBUG',
+# 'propagate': False
+# },
+# }
+# }
+
+LOGGING_CONFIG = None
+# yaml configuration of logging
+LOGGING_FILE = os.path.join(BASE_DIR, 'mgr/log.yml')
+config.yamlConfig(filepath=LOGGING_FILE, watchDog=True)
-LOGGING = {
- 'version': 1,
- 'disable_existing_loggers': True,
- 'formatters': {
- 'standard': {
- 'format': '%(asctime)s:[%(name)s]:[%(filename)s]-[%(lineno)d] [%(levelname)s]:%(message)s',
- },
- },
- 'filters': {
- },
- 'handlers': {
- 'mgr_handler': {
- 'level': 'DEBUG',
- 'class': 'logging.handlers.RotatingFileHandler',
- 'filename': os.path.join(BASE_DIR, 'logs/runtime_mgr.log'),
- 'formatter': 'standard',
- 'maxBytes': 1024 * 1024 * 50,
- 'backupCount': 5,
- },
- },
-
- 'loggers': {
- 'mgr': {
- 'handlers': ['mgr_handler'],
- 'level': 'DEBUG',
- 'propagate': False
- },
- }
-}
if 'test' in sys.argv:
from mgr.pub.config import config
diff --git a/mgr/requirements.txt b/mgr/requirements.txt
index 6ed7b1b..274c597 100644
--- a/mgr/requirements.txt
+++ b/mgr/requirements.txt
@@ -23,4 +23,7 @@ unittest_xml_reporting==1.12.0
# for auto swagger
drf-yasg>=1.2.2
flex>=6.11.1
-swagger-spec-validator>=2.1.0 \ No newline at end of file
+swagger-spec-validator>=2.1.0
+
+# for onap logging
+onappylog>=1.0.6 \ No newline at end of file