Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

wip: chore(libsinsp): remove unused container manager method #2117

Closed
wants to merge 3 commits into from
Closed
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
26 changes: 0 additions & 26 deletions userspace/libsinsp/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,73 +551,47 @@ void sinsp_container_manager::create_engines() {
m_static_name,
m_static_image);
m_container_engines.push_back(engine);
m_container_engine_by_type[CT_STATIC] = engine;
return;
}
#if !defined(MINIMAL_BUILD) && !defined(__EMSCRIPTEN__)
#ifndef _WIN32
if(m_container_engine_mask & (1 << CT_PODMAN)) {
auto podman_engine = std::make_shared<container_engine::podman>(*this);
m_container_engines.push_back(podman_engine);
m_container_engine_by_type[CT_PODMAN] = podman_engine;
}
if(m_container_engine_mask & (1 << CT_DOCKER)) {
auto docker_engine = std::make_shared<container_engine::docker_linux>(*this);
m_container_engines.push_back(docker_engine);
m_container_engine_by_type[CT_DOCKER] = docker_engine;
}

if(m_container_engine_mask & ((1 << CT_CRI) | (1 << CT_CRIO) | (1 << CT_CONTAINERD))) {
auto cri_engine = std::make_shared<container_engine::cri>(*this);
m_container_engines.push_back(cri_engine);
m_container_engine_by_type[CT_CRI] = cri_engine;
m_container_engine_by_type[CT_CRIO] = cri_engine;
m_container_engine_by_type[CT_CONTAINERD] = cri_engine;
}
if(m_container_engine_mask & (1 << CT_LXC)) {
auto lxc_engine = std::make_shared<container_engine::lxc>(*this);
m_container_engines.push_back(lxc_engine);
m_container_engine_by_type[CT_LXC] = lxc_engine;
}
if(m_container_engine_mask & (1 << CT_LIBVIRT_LXC)) {
auto libvirt_lxc_engine = std::make_shared<container_engine::libvirt_lxc>(*this);
m_container_engines.push_back(libvirt_lxc_engine);
m_container_engine_by_type[CT_LIBVIRT_LXC] = libvirt_lxc_engine;
}
if(m_container_engine_mask & (1 << CT_MESOS)) {
auto mesos_engine = std::make_shared<container_engine::mesos>(*this);
m_container_engines.push_back(mesos_engine);
m_container_engine_by_type[CT_MESOS] = mesos_engine;
}
if(m_container_engine_mask & (1 << CT_RKT)) {
auto rkt_engine = std::make_shared<container_engine::rkt>(*this);
m_container_engines.push_back(rkt_engine);
m_container_engine_by_type[CT_RKT] = rkt_engine;
}
if(m_container_engine_mask & (1 << CT_BPM)) {
auto bpm_engine = std::make_shared<container_engine::bpm>(*this);
m_container_engines.push_back(bpm_engine);
m_container_engine_by_type[CT_BPM] = bpm_engine;
}
#endif // _WIN32
#endif // MINIMAL_BUILD
}

void sinsp_container_manager::update_container_with_size(sinsp_container_type type,
const std::string& container_id) {
auto found = m_container_engine_by_type.find(type);
if(found == m_container_engine_by_type.end()) {
libsinsp_logger()->format(sinsp_logger::SEV_ERROR,
"Container type %d not found when requesting size for %s",
type,
container_id.c_str());
return;
}

libsinsp_logger()->format(sinsp_logger::SEV_DEBUG, "Request size for %s", container_id.c_str());
found->second->update_with_size(container_id);
}

void sinsp_container_manager::cleanup() {
for(auto& eng : m_container_engines) {
eng->cleanup();
Expand Down
9 changes: 0 additions & 9 deletions userspace/libsinsp/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ class sinsp_container_manager : public libsinsp::container_engine::container_cac

void create_engines();

/**
* Update the container_info associated with the given type and container_id
* to include the size of the container layer. This is not filled in the
* initial request because it can easily take seconds.
*/
void update_container_with_size(sinsp_container_type type, const std::string& container_id);
void cleanup();

void set_docker_socket_path(std::string socket_path);
Expand Down Expand Up @@ -254,9 +248,6 @@ class sinsp_container_manager : public libsinsp::container_engine::container_cac

std::list<std::shared_ptr<libsinsp::container_engine::container_engine_base>>
m_container_engines;
std::map<sinsp_container_type,
std::shared_ptr<libsinsp::container_engine::container_engine_base>>
m_container_engine_by_type;

sinsp* m_inspector;
std::shared_ptr<sinsp_stats_v2> m_sinsp_stats_v2;
Expand Down
4 changes: 0 additions & 4 deletions userspace/libsinsp/container_engine/container_engine_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace container_engine {

container_engine_base::container_engine_base(container_cache_interface &cache): m_cache(cache) {}

void container_engine_base::update_with_size(const std::string &container_id) {
SINSP_DEBUG("Updating container size not supported for this container type.");
}

void container_engine_base::cleanup() {}

} // namespace container_engine
Expand Down
7 changes: 0 additions & 7 deletions userspace/libsinsp/container_engine/container_engine_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ class container_engine_base {
*/
virtual bool resolve(sinsp_threadinfo* tinfo, bool query_os_for_missing_info) = 0;

/**
* Update an existing container with the size of the container layer.
* The size is not requested as the part of the initial request (in resolve)
* because determining the size can take seconds.
*/
virtual void update_with_size(const std::string& container_id);

virtual void cleanup();

protected:
Expand Down
40 changes: 1 addition & 39 deletions userspace/libsinsp/container_engine/cri.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2024 The Falco Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -272,34 +272,6 @@ bool cri::resolve(sinsp_threadinfo *tinfo, bool query_os_for_missing_info) {
return true;
}

void cri::update_with_size(const std::string &container_id) {
sinsp_container_info::ptr_t existing = container_cache().get_container(container_id);
if(!existing) {
libsinsp_logger()->format(sinsp_logger::SEV_ERROR,
"cri (%s): Failed to locate existing container data",
container_id.c_str());
ASSERT(false);
return;
}

std::optional<int64_t> writable_layer_size = get_writable_layer_size(existing->m_full_id);

if(!writable_layer_size.has_value()) {
return;
}

// Make a mutable copy of the existing container_info
shared_ptr<sinsp_container_info> updated(std::make_shared<sinsp_container_info>(*existing));
updated->m_size_rw_bytes = *writable_layer_size;

if(existing->m_size_rw_bytes == updated->m_size_rw_bytes) {
// no data has changed
return;
}

container_cache().replace_container(updated);
}

sinsp_container_type cri::get_cri_runtime_type() const {
if(m_cri_v1) {
return m_cri_v1->get_cri_runtime_type();
Expand All @@ -310,16 +282,6 @@ sinsp_container_type cri::get_cri_runtime_type() const {
}
}

std::optional<int64_t> cri::get_writable_layer_size(const string &container_id) {
if(m_cri_v1) {
return m_cri_v1->get_writable_layer_size(container_id);
} else if(m_cri_v1alpha2) {
return m_cri_v1alpha2->get_writable_layer_size(container_id);
} else {
return std::nullopt;
}
}

bool cri_async_source::parse(const cri_async_source::key_type &key,
sinsp_container_info &container) {
if(m_cri_v1) {
Expand Down
5 changes: 1 addition & 4 deletions userspace/libsinsp/container_engine/cri.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2024 The Falco Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -80,7 +80,6 @@ class cri : public container_engine_base {
public:
cri(container_cache_interface& cache);
bool resolve(sinsp_threadinfo* tinfo, bool query_os_for_missing_info) override;
void update_with_size(const std::string& container_id) override;
void cleanup() override;
static void set_cri_socket_path(const std::string& path);
static void add_cri_socket_path(const std::string& path);
Expand All @@ -91,8 +90,6 @@ class cri : public container_engine_base {
private:
[[nodiscard]] sinsp_container_type get_cri_runtime_type() const;

std::optional<int64_t> get_writable_layer_size(const std::string& container_id);

std::unique_ptr<cri_async_source> m_async_source;
std::unique_ptr<::libsinsp::cri::cri_interface_v1alpha2> m_cri_v1alpha2;
std::unique_ptr<::libsinsp::cri::cri_interface_v1> m_cri_v1;
Expand Down
24 changes: 0 additions & 24 deletions userspace/libsinsp/container_engine/docker/docker_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,3 @@ bool docker_linux::resolve(sinsp_threadinfo* tinfo, bool query_os_for_missing_in
docker_lookup_request(container_id, s_docker_sock, CT_DOCKER, 0, false),
query_os_for_missing_info);
}

void docker_linux::update_with_size(const std::string& container_id) {
auto cb = [this](const docker_lookup_request& instruction, const sinsp_container_info& res) {
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"docker_async (%s): with size callback result=%d",
instruction.container_id.c_str(),
res.get_lookup_status());

sinsp_container_info::ptr_t updated = std::make_shared<sinsp_container_info>(res);
container_cache().replace_container(updated);
};

libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"docker_async size request (%s)",
container_id.c_str());

sinsp_container_info result;
docker_lookup_request instruction(container_id,
s_docker_sock,
CT_DOCKER,
0,
true /*request rw size*/);
(void)m_docker_info_source->lookup(instruction, result, cb);
}
2 changes: 0 additions & 2 deletions userspace/libsinsp/container_engine/docker/docker_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class docker_linux : public docker_base {
// implement container_engine_base
bool resolve(sinsp_threadinfo* tinfo, bool query_os_for_missing_info) override;

void update_with_size(const std::string& container_id) override;

private:
static std::string s_docker_sock;
};
Expand Down
10 changes: 1 addition & 9 deletions userspace/libsinsp/cri.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2024 The Falco Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -216,14 +216,6 @@ class cri_interface {
*/
std::string get_container_image_id(const std::string &image_ref);

/**
* @brief get the size of the container's writable layer via ContainerStat API calls
* @param container_id container ID
* @note currently unused
* @return the size of the writable layer in bytes. Returns an empty option on error
*/
std::optional<int64_t> get_writable_layer_size(const std::string &container_id);

///////////////////////////////////////////////////////////
// CRI response (ContainerStatusResponse) parsers helpers
///////////////////////////////////////////////////////////
Expand Down
49 changes: 1 addition & 48 deletions userspace/libsinsp/cri.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
/*
Copyright (C) 2023 The Falco Authors.
Copyright (C) 2024 The Falco Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -163,53 +163,6 @@ inline std::string cri_interface<api>::get_container_image_id(const std::string
return "";
}

template<typename api>
inline std::optional<int64_t> cri_interface<api>::get_writable_layer_size(
const std::string &container_id) {
// Synchronously get the stats response and update the container table.
// Note that this needs to use the full id.
typename api::ContainerStatsResponse resp;
grpc::Status status = get_container_stats_resp(container_id, resp);

libsinsp_logger()->format(
sinsp_logger::SEV_DEBUG,
"cri (%s): Status from ContainerStats: (%s)",
container_id.c_str(),
status.error_message().empty() ? "SUCCESS" : status.error_message().c_str());

if(!status.ok()) {
return std::nullopt;
}

if(!resp.has_stats()) {
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"cri (%s): Failed to update size: stats() not found",
container_id.c_str());
ASSERT(false);
return std::nullopt;
}

const auto &resp_stats = resp.stats();

if(!resp_stats.has_writable_layer()) {
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"cri (%s): Failed to update size: writable_layer() not found",
container_id.c_str());
ASSERT(false);
return std::nullopt;
}

if(!resp_stats.writable_layer().has_used_bytes()) {
libsinsp_logger()->format(sinsp_logger::SEV_DEBUG,
"cri (%s): Failed to update size: used_bytes() not found",
container_id.c_str());
ASSERT(false);
return std::nullopt;
}

return resp_stats.writable_layer().used_bytes().value();
}

/////////////////////////////
// Generic parsers helpers
/////////////////////////////
Expand Down
Loading