Skip to content

Commit

Permalink
refactor(libs): add minloglevel to Dockerimage and minor changes to l…
Browse files Browse the repository at this point in the history
…og levels

Signed-off-by: Frederico Araujo <[email protected]>
  • Loading branch information
araujof committed Sep 1, 2022
1 parent 3e6cf9c commit 93bf882
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 30 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/collector/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/containercontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/fileflowprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/libs/k8seventprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/logger.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** Copyright (C) 2019 IBM Corporation.
/** Copyright (C) 2022 IBM Corporation.
*
* Authors:
* Frederico Araujo <[email protected]>
Expand Down Expand Up @@ -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
23 changes: 11 additions & 12 deletions src/libs/networkflowprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/sfconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/libs/sfsockwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
2 changes: 0 additions & 2 deletions src/libs/sysflowcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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; }
Expand Down
6 changes: 3 additions & 3 deletions src/libs/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ int64_t utils::getSyscallResult(sinsp_evt *ev) {
res = *reinterpret_cast<int64_t *>(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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 93bf882

Please sign in to comment.