fix(userspace/falco): set gpr log verbosity accordingly to the Falco one

Signed-off-by: Leonardo Di Donato <leodidonato@gmail.com>
This commit is contained in:
Leonardo Di Donato
2020-05-19 08:46:25 +00:00
committed by poiana
parent ade64b0ce8
commit f186e5f41f
4 changed files with 57 additions and 27 deletions

View File

@@ -12,7 +12,7 @@ jobs:
command: apt update -y command: apt update -y
- run: - run:
name: Install dependencies name: Install dependencies
command: DEBIAN_FRONTEND=noninteractive apt install libssl-dev libyaml-dev libncurses-dev libc-ares-dev libprotobuf-dev protobuf-compiler libjq-dev libyaml-cpp-dev libgrpc++-dev protobuf-compiler-grpc rpm libelf-dev cmake build-essential libcurl4-openssl-dev linux-headers-generic clang llvm -y command: DEBIAN_FRONTEND=noninteractive apt install libssl-dev libyaml-dev libncurses-dev libc-ares-dev libprotobuf-dev protobuf-compiler libjq-dev libyaml-cpp-dev libgrpc++-dev protobuf-compiler-grpc rpm libelf-dev cmake build-essential libcurl4-openssl-dev linux-headers-generic clang llvm git -y
- run: - run:
name: Prepare project name: Prepare project
command: | command: |
@@ -44,7 +44,7 @@ jobs:
command: apt update -y command: apt update -y
- run: - run:
name: Install dependencies name: Install dependencies
command: DEBIAN_FRONTEND=noninteractive apt install libssl-dev libyaml-dev libncurses-dev libc-ares-dev libprotobuf-dev protobuf-compiler libjq-dev libyaml-cpp-dev libgrpc++-dev protobuf-compiler-grpc rpm libelf-dev cmake build-essential libcurl4-openssl-dev linux-headers-generic clang llvm -y command: DEBIAN_FRONTEND=noninteractive apt install libssl-dev libyaml-dev libncurses-dev libc-ares-dev libprotobuf-dev protobuf-compiler libjq-dev libyaml-cpp-dev libgrpc++-dev protobuf-compiler-grpc rpm libelf-dev cmake build-essential libcurl4-openssl-dev linux-headers-generic clang llvm git -y
- run: - run:
name: Prepare project name: Prepare project
command: | command: |

View File

@@ -1208,7 +1208,14 @@ int falco_init(int argc, char **argv)
{ {
// TODO(fntlnz,leodido): when we want to spawn multiple threads we need to have a queue per thread, or implement // TODO(fntlnz,leodido): when we want to spawn multiple threads we need to have a queue per thread, or implement
// different queuing mechanisms, round robin, fanout? What we want to achieve? // different queuing mechanisms, round robin, fanout? What we want to achieve?
grpc_server.init(config.m_grpc_bind_address, config.m_grpc_threadiness, config.m_grpc_private_key, config.m_grpc_cert_chain, config.m_grpc_root_certs); grpc_server.init(
config.m_grpc_bind_address,
config.m_grpc_threadiness,
config.m_grpc_private_key,
config.m_grpc_cert_chain,
config.m_grpc_root_certs,
config.m_log_level
);
grpc_server_thread = std::thread([&grpc_server] { grpc_server_thread = std::thread([&grpc_server] {
grpc_server.run(); grpc_server.run();
}); });

View File

@@ -44,20 +44,22 @@ limitations under the License.
c.start(this); \ c.start(this); \
} }
static void gpr_falco_log_dispatcher_func(gpr_log_func_args* args) static void gpr_log_dispatcher_func(gpr_log_func_args* args)
{ {
int priority = LOG_INFO; int priority;
switch(args->severity)
if(args
->severity == GPR_LOG_SEVERITY_ERROR)
{ {
case GPR_LOG_SEVERITY_ERROR:
priority = LOG_ERR; priority = LOG_ERR;
} break;
if(args case GPR_LOG_SEVERITY_DEBUG:
->severity == GPR_LOG_SEVERITY_DEBUG)
{
priority = LOG_DEBUG; priority = LOG_DEBUG;
break;
default:
priority = LOG_INFO;
break;
} }
falco_logger::log(priority, args->message); falco_logger::log(priority, args->message);
} }
@@ -113,7 +115,13 @@ void falco::grpc::server::thread_process(int thread_index)
} }
} }
void falco::grpc::server::init(std::string server_addr, int threadiness, std::string private_key, std::string cert_chain, std::string root_certs) void falco::grpc::server::init(
std::string server_addr,
int threadiness,
std::string private_key,
std::string cert_chain,
std::string root_certs,
std::string log_level)
{ {
m_server_addr = server_addr; m_server_addr = server_addr;
m_threadiness = threadiness; m_threadiness = threadiness;
@@ -121,6 +129,26 @@ void falco::grpc::server::init(std::string server_addr, int threadiness, std::st
m_cert_chain = cert_chain; m_cert_chain = cert_chain;
m_root_certs = root_certs; m_root_certs = root_certs;
// Set the verbosity level of gpr logger
falco::schema::priority logging_level = falco::schema::INFORMATIONAL;
falco::schema::priority_Parse(log_level, &logging_level);
switch(logging_level)
{
case falco::schema::ERROR:
gpr_set_log_verbosity(GPR_LOG_SEVERITY_ERROR);
break;
case falco::schema::DEBUG:
gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
break;
case falco::schema::INFORMATIONAL:
default:
// note > info will always enter here since it is != from "informational"
gpr_set_log_verbosity(GPR_LOG_SEVERITY_INFO);
break;
}
gpr_log_verbosity_init();
gpr_set_log_function(gpr_log_dispatcher_func);
if(falco::utils::network::is_unix_scheme(m_server_addr)) if(falco::utils::network::is_unix_scheme(m_server_addr))
{ {
init_unix_server_builder(); init_unix_server_builder();
@@ -152,8 +180,6 @@ void falco::grpc::server::init_unix_server_builder()
void falco::grpc::server::run() void falco::grpc::server::run()
{ {
gpr_set_log_function(gpr_falco_log_dispatcher_func);
m_server_builder.RegisterService(&m_output_svc); m_server_builder.RegisterService(&m_output_svc);
m_server_builder.RegisterService(&m_version_svc); m_server_builder.RegisterService(&m_version_svc);

View File

@@ -29,20 +29,17 @@ namespace grpc
class server : public server_impl class server : public server_impl
{ {
public: public:
server() server() = default;
{
}
server(std::string server_addr, int threadiness, std::string private_key, std::string cert_chain, std::string root_certs):
m_server_addr(server_addr),
m_threadiness(threadiness),
m_private_key(private_key),
m_cert_chain(cert_chain),
m_root_certs(root_certs)
{
}
virtual ~server() = default; virtual ~server() = default;
void init(std::string server_addr, int threadiness, std::string private_key, std::string cert_chain, std::string root_certs); void init(
std::string server_addr,
int threadiness,
std::string private_key,
std::string cert_chain,
std::string root_certs,
std::string log_level
);
void thread_process(int thread_index); void thread_process(int thread_index);
void run(); void run();
void stop(); void stop();