Skip to content

Commit

Permalink
cleanup(sinsp): add a set_static_container method
Browse files Browse the repository at this point in the history
This change splits configuration of the static container data away from
the sinsp constructor and into a separate set_static_container method.

The motivation behind this change is two fold:
- Configuration of other container engines is handled by a call to
  set_container_engine_mask() before starting the inspector, the new
  method is closer to this implementation.
- Enabling metrics collection should not require adopters to pass in 4
  unrelated arguments to the sinsp constructor.

These changes will require some modifications into the Falco main repo,
as far as I can tell they should be relatively straight forward.

Signed-off-by: Mauro Ezequiel Moltrasio <mmoltras@redhat.com>
  • Loading branch information
Molter73 authored and poiana committed Aug 20, 2024
1 parent 1dc7459 commit fb6cef6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
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

0 comments on commit fb6cef6

Please sign in to comment.