From e4e4ae46c6090da1ac489d57e0b29764f0b19c0e Mon Sep 17 00:00:00 2001 From: Grzegorz Nosek Date: Tue, 5 Feb 2019 18:57:38 +0100 Subject: [PATCH] Make extra CRI queries configurable (enabled by default) --- userspace/libsinsp/container.cpp | 7 +++++++ userspace/libsinsp/container.h | 1 + userspace/libsinsp/container_engine/cri.cpp | 12 ++++++++++-- userspace/libsinsp/container_engine/cri.h | 1 + userspace/libsinsp/cri.cpp | 1 + userspace/libsinsp/cri.h | 1 + userspace/libsinsp/sinsp.cpp | 5 +++++ userspace/libsinsp/sinsp.h | 2 ++ 8 files changed, 28 insertions(+), 2 deletions(-) diff --git a/userspace/libsinsp/container.cpp b/userspace/libsinsp/container.cpp index 4c0b5d966e..869a6f6654 100644 --- a/userspace/libsinsp/container.cpp +++ b/userspace/libsinsp/container.cpp @@ -366,6 +366,13 @@ void sinsp_container_manager::set_query_docker_image_info(bool query_image_info) libsinsp::container_engine::docker::set_query_image_info(query_image_info); } +void sinsp_container_manager::set_cri_extra_queries(bool extra_queries) +{ +#if defined(HAS_CAPTURE) + libsinsp::container_engine::cri::set_extra_queries(extra_queries); +#endif +} + void sinsp_container_manager::set_cri_socket_path(const std::string &path) { #if defined(HAS_CAPTURE) diff --git a/userspace/libsinsp/container.h b/userspace/libsinsp/container.h index f741b2d0a7..4e3a6ff164 100644 --- a/userspace/libsinsp/container.h +++ b/userspace/libsinsp/container.h @@ -65,6 +65,7 @@ class sinsp_container_manager void cleanup(); void set_query_docker_image_info(bool query_image_info); + void set_cri_extra_queries(bool extra_queries); void set_cri_socket_path(const std::string& path); void set_cri_timeout(int64_t timeout_ms); sinsp* get_inspector() { return m_inspector; } diff --git a/userspace/libsinsp/container_engine/cri.cpp b/userspace/libsinsp/container_engine/cri.cpp index 34082e12b8..ce7787a873 100644 --- a/userspace/libsinsp/container_engine/cri.cpp +++ b/userspace/libsinsp/container_engine/cri.cpp @@ -114,8 +114,11 @@ bool parse_cri(sinsp_container_manager *manager, sinsp_container_info *container return true; } - container->m_container_ip = get_container_ip(container->m_id); - container->m_imageid = get_container_image_id(resp_container.image_ref()); + if(s_cri_extra_queries) + { + container->m_container_ip = get_container_ip(container->m_id); + container->m_imageid = get_container_image_id(resp_container.image_ref()); + } return true; } @@ -171,6 +174,7 @@ void cri::cleanup() { s_cri.reset(nullptr); s_cri_image.reset(nullptr); + s_cri_extra_queries = true; } void cri::set_cri_socket_path(const std::string& path) @@ -183,6 +187,10 @@ void cri::set_cri_timeout(int64_t timeout_ms) s_cri_timeout = timeout_ms; } +void cri::set_extra_queries(bool extra_queries) { + s_cri_extra_queries = extra_queries; +} + bool cri::resolve(sinsp_container_manager* manager, sinsp_threadinfo* tinfo, bool query_os_for_missing_info) { sinsp_container_info container_info; diff --git a/userspace/libsinsp/container_engine/cri.h b/userspace/libsinsp/container_engine/cri.h index ab47c4abce..f8ff272d91 100644 --- a/userspace/libsinsp/container_engine/cri.h +++ b/userspace/libsinsp/container_engine/cri.h @@ -37,6 +37,7 @@ class cri static void cleanup(); static void set_cri_socket_path(const std::string& path); static void set_cri_timeout(int64_t timeout_ms); + static void set_extra_queries(bool extra_queries); }; } } diff --git a/userspace/libsinsp/cri.cpp b/userspace/libsinsp/cri.cpp index c837a28dfe..5c45cbc026 100644 --- a/userspace/libsinsp/cri.cpp +++ b/userspace/libsinsp/cri.cpp @@ -40,6 +40,7 @@ std::unique_ptr s_cri = nullptr; std::unique_ptr s_cri_image = nullptr; int64_t s_cri_timeout = 1000; sinsp_container_type s_cri_runtime_type = CT_CRI; +bool s_cri_extra_queries = true; sinsp_container_type get_cri_runtime_type(const std::string &runtime_name) { diff --git a/userspace/libsinsp/cri.h b/userspace/libsinsp/cri.h index e56a52a740..cb32eef310 100644 --- a/userspace/libsinsp/cri.h +++ b/userspace/libsinsp/cri.h @@ -34,6 +34,7 @@ extern std::unique_ptr s_cri; extern std::unique_ptr s_cri_image; extern int64_t s_cri_timeout; extern sinsp_container_type s_cri_runtime_type; +extern bool s_cri_extra_queries; sinsp_container_type get_cri_runtime_type(const std::string &runtime_name); diff --git a/userspace/libsinsp/sinsp.cpp b/userspace/libsinsp/sinsp.cpp index a49cff3872..e837d0f303 100644 --- a/userspace/libsinsp/sinsp.cpp +++ b/userspace/libsinsp/sinsp.cpp @@ -1596,6 +1596,11 @@ void sinsp::set_query_docker_image_info(bool query_image_info) m_container_manager.set_query_docker_image_info(query_image_info); } +void sinsp::set_cri_extra_queries(bool extra_queries) +{ + m_container_manager.set_cri_extra_queries(extra_queries); +} + void sinsp::set_cri_socket_path(const std::string& path) { m_container_manager.set_cri_socket_path(path); diff --git a/userspace/libsinsp/sinsp.h b/userspace/libsinsp/sinsp.h index fd8995b6c5..c6ec5d060d 100644 --- a/userspace/libsinsp/sinsp.h +++ b/userspace/libsinsp/sinsp.h @@ -879,6 +879,8 @@ class SINSP_PUBLIC sinsp void set_query_docker_image_info(bool query_image_info); + void set_cri_extra_queries(bool extra_queries); + void set_fullcapture_port_range(uint16_t range_start, uint16_t range_end); void set_cri_socket_path(const std::string& path);