Skip to content

cleanup(sinsp)!: add set_static_container method #2016

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions userspace/libsinsp/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,10 @@ limitations under the License.

using namespace libsinsp;

sinsp_container_manager::sinsp_container_manager(sinsp* inspector, bool static_container, const std::string static_id, const std::string static_name, const std::string static_image) :
sinsp_container_manager::sinsp_container_manager(sinsp* inspector) :
m_last_flush_time_ns(0),
m_inspector(inspector),
m_static_container(static_container),
m_static_id(static_id),
m_static_name(static_name),
m_static_image(static_image),
m_static_container(false),
m_container_engine_mask(~0ULL)
{
if (m_inspector != nullptr)
Expand Down
26 changes: 21 additions & 5 deletions userspace/libsinsp/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ class sinsp_container_manager :
* right now being "static" or not. I'm sure we will find time in the future to do this
* in a more general way. 2020/11/24
*/
sinsp_container_manager(sinsp* inspector,
bool static_container = false,
const std::string static_id = "",
const std::string static_name = "",
const std::string static_image = "");
sinsp_container_manager(sinsp* inspector);

virtual ~sinsp_container_manager() = default;

Expand Down Expand Up @@ -164,6 +160,26 @@ class sinsp_container_manager :
m_container_engine_mask = mask;
}

/**
* @brief Set static container information
* @param id the id for the static container.
* @param name the name for the static container.
* @param image the used by the static container.
*
* Note: the CRI engine handles multiple container types which can only
* be enabled or disabled together.
*
* This method *must* be called before the first container detection,
* i.e. before inspector->open()
*/
inline void set_static_container(const std::string& id, const std::string& name, const std::string& image)
{
m_static_id = id;
m_static_name = name;
m_static_image = image;
m_static_container = true;
}

void create_engines();

/**
Expand Down
4 changes: 2 additions & 2 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ int32_t on_new_entry_from_proc(void* context, char* error, int64_t tid, scap_thr
///////////////////////////////////////////////////////////////////////////////
std::atomic<int> sinsp::instance_count{0};

sinsp::sinsp(bool static_container, const std::string &static_id, const std::string &static_name, const std::string &static_image, bool with_metrics) :
sinsp::sinsp(bool with_metrics) :
m_external_event_processor(),
m_sinsp_stats_v2(with_metrics ? std::make_shared<sinsp_stats_v2>() : nullptr),
m_evt(this),
m_lastevent_ts(0),
m_host_root(scap_get_host_root()),
m_container_manager(this, static_container, static_id, static_name, static_image),
m_container_manager(this),
m_usergroup_manager(this),
m_async_events_queue(DEFAULT_ASYNC_EVENT_QUEUE_SIZE),
m_suppressed_comms(),
Expand Down
10 changes: 5 additions & 5 deletions userspace/libsinsp/sinsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,7 @@ enum sinsp_mode_t
class SINSP_PUBLIC sinsp : public capture_stats_source
{
public:
sinsp(bool static_container = false,
const std::string &static_id = "",
const std::string &static_name = "",
const std::string &static_image = "",
bool with_metrics = false);
sinsp(bool with_metrics = false);

virtual ~sinsp() override;

Expand Down Expand Up @@ -931,6 +927,10 @@ class SINSP_PUBLIC sinsp : public capture_stats_source
m_container_manager.set_container_engine_mask(mask);
}

inline void set_static_container(const std::string& id, const std::string& name, const std::string& image) {
m_container_manager.set_static_container(id, name, image);
}

// Add comm to the list of comms for which the inspector
// should not return events.
bool suppress_events_comm(const std::string &comm);
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/sinsp_with_test_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class sinsp_with_test_input : public ::testing::Test
sinsp_with_test_input();
~sinsp_with_test_input();

sinsp m_inspector = sinsp(false, "", "", "", true);
sinsp m_inspector = sinsp(true);

void open_inspector(sinsp_mode_t mode = SINSP_MODE_TEST);

Expand Down
Loading