From 93bf882d00c913b1b1bec91b2b38e5491e160410 Mon Sep 17 00:00:00 2001 From: Frederico Araujo Date: Thu, 1 Sep 2022 01:30:46 +0000 Subject: [PATCH] refactor(libs): add minloglevel to Dockerimage and minor changes to log levels Signed-off-by: Frederico Araujo --- Dockerfile | 5 +++++ src/collector/main.cpp | 2 +- src/libs/containercontext.cpp | 4 ++-- src/libs/fileflowprocessor.cpp | 4 ++-- src/libs/k8seventprocessor.cpp | 4 ++-- src/libs/logger.h | 6 +++--- src/libs/networkflowprocessor.cpp | 23 +++++++++++------------ src/libs/sfconfig.h | 2 +- src/libs/sfsockwriter.h | 3 +-- src/libs/sysflowcontext.h | 2 -- src/libs/utils.cpp | 6 +++--- 11 files changed, 31 insertions(+), 30 deletions(-) diff --git a/Dockerfile b/Dockerfile index a7f2da75..ae59a22a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -117,9 +117,14 @@ ENV DEBUG=$debug ARG gllogtostderr=1 ENV GLOG_logtostderr=$gllogtostderr +# Verbose logging (GLOG_minloglevel must be 0): 1 (DEBUG), 2 (TRACE) ARG glv= ENV GLOG_v=$glv +# 0 (INFO), 1 (WARNING), 2 (ERROR) +ARG glminlevel=0 +ENV GLOG_minloglevel=$glminlevel + ARG INSTALL_PATH=/usr/local/sysflow ARG MODPREFIX=${INSTALL_PATH}/modules diff --git a/src/collector/main.cpp b/src/collector/main.cpp index 36671003..4fa16e66 100644 --- a/src/collector/main.cpp +++ b/src/collector/main.cpp @@ -232,7 +232,7 @@ int main(int argc, char **argv) { try { CONFIGURE_LOGGER(logProps); - SF_DEBUG(logger, "Starting sysporter..."); + SF_INFO(logger, "Starting the SysFlow Collector..."); g_driver = new sysflowlibscpp::SysFlowDriver(g_config); int ret = g_driver->run(); delete g_driver; diff --git a/src/libs/containercontext.cpp b/src/libs/containercontext.cpp index 839fc89a..16fd7282 100644 --- a/src/libs/containercontext.cpp +++ b/src/libs/containercontext.cpp @@ -56,8 +56,8 @@ ContainerObj *ContainerContext::createContainer(sinsp_threadinfo *ti) { m_cxt->getInspector()->m_container_manager.get_container( ti->m_container_id); if (!container) { - SF_WARN(m_logger, "Thread has container id, but no container object. ID: " - << ti->m_container_id) + SF_DEBUG(m_logger, "Thread has container id, but no container object. ID: " + << ti->m_container_id) auto *cont = new ContainerObj(); cont->cont.name = INCOMPLETE; cont->cont.image = INCOMPLETE_IMAGE; diff --git a/src/libs/fileflowprocessor.cpp b/src/libs/fileflowprocessor.cpp index eb460b73..1b81c0a7 100644 --- a/src/libs/fileflowprocessor.cpp +++ b/src/libs/fileflowprocessor.cpp @@ -190,8 +190,8 @@ int FileFlowProcessor::handleFileFlowEvent(sinsp_evt *ev, OpFlags flag) { } if ((fdinfo->is_ipv4_socket() || fdinfo->is_ipv6_socket())) { - SF_WARN(m_logger, - "handleFileFlowEvent cannot handle ip sockets, ignoring..."); + SF_DEBUG(m_logger, + "handleFileFlowEvent cannot handle ip sockets, ignoring..."); return 1; } char restype = fdinfo->get_typechar(); diff --git a/src/libs/k8seventprocessor.cpp b/src/libs/k8seventprocessor.cpp index a3cba25f..d68b7495 100644 --- a/src/libs/k8seventprocessor.cpp +++ b/src/libs/k8seventprocessor.cpp @@ -56,10 +56,10 @@ sysflow::K8sComponent K8sEventProcessor::getK8sComponent(Json::Value &root) { } else if (type == "EventList") { comp = sysflow::K8sComponent::K8S_EVENTS; } else { - SF_WARN(m_logger, "Unknown k8s component type " << type << ". Ignoring") + SF_DEBUG(m_logger, "Unknown k8s component type " << type << ". Ignoring") } } else { - SF_WARN(m_logger, "Unknown k8s component type not found in JSON") + SF_DEBUG(m_logger, "Unknown k8s component type not found in JSON") } return comp; } diff --git a/src/libs/logger.h b/src/libs/logger.h index 3f0b4d2d..dbe29848 100644 --- a/src/libs/logger.h +++ b/src/libs/logger.h @@ -1,4 +1,4 @@ -/** Copyright (C) 2019 IBM Corporation. +/** Copyright (C) 2022 IBM Corporation. * * Authors: * Frederico Araujo @@ -32,10 +32,10 @@ #define CONFIGURE_LOGGER(logConfig) google::InitGoogleLogging(argv[0]); #define CATCH_LOGGER_EXCEPTION() +#define SF_TRACE(logger, message) VLOG(2) << message; #define SF_DEBUG(logger, message) VLOG(1) << message; -#define SF_WARN(logger, message) LOG(WARNING) << message; #define SF_INFO(logger, message) LOG(INFO) << message; +#define SF_WARN(logger, message) LOG(WARNING) << message; #define SF_ERROR(logger, message) LOG(ERROR) << message; -#define IS_DEBUG_ENABLED(logger) VLOG_IS_ON(1) #endif diff --git a/src/libs/networkflowprocessor.cpp b/src/libs/networkflowprocessor.cpp index a0782c8c..285b3477 100644 --- a/src/libs/networkflowprocessor.cpp +++ b/src/libs/networkflowprocessor.cpp @@ -210,18 +210,17 @@ int NetworkFlowProcessor::handleNetFlowEvent(sinsp_evt *ev, OpFlags flag) { nf = nfi->second; } - if (IS_DEBUG_ENABLED(m_logger)) { - string ip4tuple = - ipv4tuple_to_string(&(fdinfo->m_sockinfo.m_ipv4info), false); - SF_DEBUG(m_logger, proc->proc.exe - << " " << ip4tuple - << " Proto: " << getProtocol(fdinfo->get_l4proto()) - << " Server: " << fdinfo->is_role_server() - << " Client: " << fdinfo->is_role_client() << " " - << ev->get_name() << " " << proc->proc.oid.hpid - << " " << proc->proc.oid.createTS << " " << ti->m_tid - << " " << ev->get_fd_num()); - } + SF_DEBUG(m_logger, proc->proc.exe + << " " + << ipv4tuple_to_string( + &(fdinfo->m_sockinfo.m_ipv4info), false) + << " Proto: " << getProtocol(fdinfo->get_l4proto()) + << " Server: " << fdinfo->is_role_server() + << " Client: " << fdinfo->is_role_client() << " " + << ev->get_name() << " " << proc->proc.oid.hpid << " " + << proc->proc.oid.createTS << " " << ti->m_tid << " " + << ev->get_fd_num()); + if (nf == nullptr) { SF_DEBUG(m_logger, "Processing as new flow!"); processNewFlow(ev, proc, flag, key); diff --git a/src/libs/sfconfig.h b/src/libs/sfconfig.h index af493ced..0005080a 100644 --- a/src/libs/sfconfig.h +++ b/src/libs/sfconfig.h @@ -85,7 +85,7 @@ struct SysFlowConfig { // Callback function, required for when using a custom callback function for // SysFlow processing. SysFlowCallback callback; - // Debug mode turns on debug logging inside the library. + // Debug mode turns on debug logging inside libsinsp. bool debugMode; // K8s API URL used to retrieve K8s state and K8s events (experimental). std::string k8sAPIURL; diff --git a/src/libs/sfsockwriter.h b/src/libs/sfsockwriter.h index bc4b5d47..59e7ccb1 100644 --- a/src/libs/sfsockwriter.h +++ b/src/libs/sfsockwriter.h @@ -82,7 +82,7 @@ class SFSocketWriter : public writer::SysFlowWriter { int res = connectSocket(); if (res == 0) { SF_WARN(m_logger, - "Successful reconnected to socket " << m_sockPath.c_str()) + "Successfully reconnected to socket " << m_sockPath.c_str()) m_errTimer = 0; m_reconnectInterval = CONNECT_INTERVAL; m_reset = true; @@ -92,7 +92,6 @@ class SFSocketWriter : public writer::SysFlowWriter { SF_ERROR( m_logger, "Unable to connect to domain socket within interval. Exiting!"); - // exit(EXIT_FAILURE); pid_t myPid = getpid(); kill(myPid, SIGINT); } diff --git a/src/libs/sysflowcontext.h b/src/libs/sysflowcontext.h index 12e0ab77..27802ce1 100644 --- a/src/libs/sysflowcontext.h +++ b/src/libs/sysflowcontext.h @@ -52,7 +52,6 @@ enum ProbeType { EBPF, KMOD, NO_PROBE }; class SysFlowContext { private: - // time_t m_start{}; int m_nfExportInterval; int m_nfExpireInterval; bool m_offline; @@ -92,7 +91,6 @@ class SysFlowContext { inline int getFileDuration() { return m_config->rotateInterval; } inline bool isFilterContainers() { return m_config->filterContainers; } inline bool isStatsEnabled() { return m_config->enableStats; } - /*inline void enableStats() { m_stats = true; }*/ inline bool isProcessFlowEnabled() { return m_config->enableProcessFlow; } inline int getStatsInterval() { return m_statsInterval; } inline bool isFileOnly() { return m_config->fileOnly; } diff --git a/src/libs/utils.cpp b/src/libs/utils.cpp index 5823b3d7..256cf745 100644 --- a/src/libs/utils.cpp +++ b/src/libs/utils.cpp @@ -130,8 +130,8 @@ int64_t utils::getSyscallResult(sinsp_evt *ev) { res = *reinterpret_cast(p->m_val); break; default: - SF_WARN(m_logger, "Syscall result not of type pid!! Type: " - << param->type << " Name: " << param->name); + SF_DEBUG(m_logger, "Syscall result not of type pid! Type: " + << param->type << " Name: " << param->name); break; } } @@ -280,7 +280,7 @@ fs::path utils::getCanonicalPath(const string &fileName) { try { p = fs::weakly_canonical(p); } catch (...) { - SF_WARN(m_logger, "Unable to compute canonical path from " << fileName); + SF_DEBUG(m_logger, "Unable to compute canonical path from " << fileName); } return p; }