Skip to content

Commit

Permalink
chore(libsinsp): remove get_writable_layer_size impl from CRI
Browse files Browse the repository at this point in the history
Signed-off-by: Leonardo Grasso <[email protected]>
  • Loading branch information
leogr committed Oct 22, 2024
1 parent f2a81a9 commit 04fce8b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 71 deletions.
12 changes: 1 addition & 11 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 @@ -282,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
4 changes: 1 addition & 3 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 @@ -90,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
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

0 comments on commit 04fce8b

Please sign in to comment.