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

cleanup(userspace/libsinsp): remove and rearrange legacy definitions #1634

Merged
merged 4 commits into from
Jan 22, 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
2 changes: 0 additions & 2 deletions userspace/chisel/chisel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ const static struct luaL_Reg ll_tool [] =
{"udp_setpeername", &lua_cbacks::udp_setpeername},
{"udp_send", &lua_cbacks::udp_send},
{"get_read_progress", &lua_cbacks::get_read_progress},
#ifdef HAS_ANALYZER
{"push_metric", &lua_cbacks::push_metric},
#endif
{NULL,NULL}
};

Expand Down
15 changes: 15 additions & 0 deletions userspace/chisel/chisel.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,21 @@ class chisel_desc
chisel_view_info m_viewinfo;
};

class chisel_metric
{
public:
void reset()
{
m_name = "";
m_value = 0;
m_tags.clear();
}

std::string m_name;
double m_value = 0;
std::map<std::string, std::string> m_tags;
};

class chiselinfo
{
public:
Expand Down
9 changes: 2 additions & 7 deletions userspace/chisel/chisel_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ limitations under the License.
#include <chisel/chisel_api.h>
#include <libsinsp/filter.h>
#include <libsinsp/filterchecks.h>
#ifdef HAS_ANALYZER
#include "analyzer.h"
#endif

#define HAS_LUA_CHISELS

Expand Down Expand Up @@ -1504,11 +1501,9 @@ int lua_cbacks::get_read_progress(lua_State *ls)
return 1;
}

#ifdef HAS_ANALYZER
int lua_cbacks::push_metric(lua_State *ls)
{
statsd_metric metric;
metric.m_type = statsd_metric::type_t::GAUGE;
chisel_metric metric;

lua_getglobal(ls, "sichisel");

Expand Down Expand Up @@ -1579,5 +1574,5 @@ int lua_cbacks::push_metric(lua_State *ls)
return 0;
}

#endif // HAS_ANALYZER

#endif // HAS_LUA_CHISELS
2 changes: 0 additions & 2 deletions userspace/chisel/chisel_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class lua_cbacks
static int udp_setpeername(lua_State *ls);
static int udp_send(lua_State *ls);
static int get_read_progress(lua_State *ls);
#ifdef HAS_ANALYZER
static int push_metric(lua_State *ls);
#endif
private:
static int get_thread_table_int(lua_State *ls, bool include_fds, bool barebone);
};
Expand Down
7 changes: 3 additions & 4 deletions userspace/libsinsp/include/sinsp_external_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* sinsp in order to start receiving appropriate callbacks.
*/

// Required until the chisel_api dependency on the analyzer can be removed
class statsd_metric;
class chisel_metric;
class sinsp;
class threadinfo;

Expand Down Expand Up @@ -40,9 +39,9 @@ class event_processor
virtual void process_event(sinsp_evt* evt, event_return rc) = 0;

/**
* Required until the chisel_api dependency on the analyzer can be removed
* Handles a metric pushed by a chisel
*/
virtual void add_chisel_metric(statsd_metric* metric) = 0;
virtual void add_chisel_metric(chisel_metric* metric) = 0;

/**
* Some event processors allocate different thread types with extra data.
Expand Down
8 changes: 0 additions & 8 deletions userspace/libsinsp/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ limitations under the License.
#include <libscap/strl.h>
#include <libsinsp/plugin_manager.h>
#include <libsinsp/sinsp_observer.h>

#ifdef SIMULATE_DROP_MODE
bool should_drop(sinsp_evt *evt);
#endif
#include <libsinsp/sinsp_int.h>

#if !defined(MINIMAL_BUILD) && !defined(__EMSCRIPTEN__)
Expand Down Expand Up @@ -3188,12 +3184,10 @@ void sinsp_parser::parse_connect_enter(sinsp_evt *evt){
//
evt->m_fdinfo->m_name = evt->get_param_as_str(1, &parstr, sinsp_evt::PF_SIMPLE);

#ifndef HAS_ANALYZER
//
// Update the FD with this tuple
//
evt->m_fdinfo->set_unix_info(packed_data);
#endif
}

//
Expand Down Expand Up @@ -3283,12 +3277,10 @@ inline void sinsp_parser::fill_client_socket_info(sinsp_evt *evt, uint8_t *packe
//
evt->m_fdinfo->m_name = evt->get_param_as_str(1, &parstr, sinsp_evt::PF_SIMPLE);

#ifndef HAS_ANALYZER
//
// Update the FD with this tuple
//
evt->m_fdinfo->set_unix_info(packed_data);
#endif
}

if(evt->m_fdinfo->is_role_none())
Expand Down
12 changes: 1 addition & 11 deletions userspace/libsinsp/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ limitations under the License.
*/

#pragma once

//
// Memory storage size for an entry in the event storage LIFO.
// Events bigger than SP_EVT_BUF_SIZE won't be be stored in the LIFO.
//
#define SP_EVT_BUF_SIZE 4096

//
// Controls if assertions break execution or if they are just printed to the
// log
//
#define ASSERT_TO_LOG

//
// Max size that the FD table of a process can reach
//
Expand All @@ -49,11 +44,6 @@ limitations under the License.
//
#define DEFAULT_SNAPLEN 80

//
// Maximum user event buffer size
//
#define MAX_USER_EVT_BUFFER 65536

//
// The time after which a clone should be considered stale
//
Expand Down
35 changes: 0 additions & 35 deletions userspace/libsinsp/sinsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ limitations under the License.
#include <curl/curl.h>
#endif

#ifdef HAS_ANALYZER
#include "analyzer_int.h"
#include "analyzer.h"
#endif

/**
* This is the maximum size assigned to the concurrent asynchronous event
* queue that can be used to inject async events during an event capture.
Expand Down Expand Up @@ -97,9 +92,6 @@ sinsp::sinsp(bool static_container, const std::string &static_id, const std::str
m_fds_to_remove = new std::vector<int64_t>;
m_machine_info = NULL;
m_agent_info = NULL;
#ifdef SIMULATE_DROP_MODE
m_isdropping = false;
#endif
m_snaplen = DEFAULT_SNAPLEN;
m_buffer_format = sinsp_evt::PF_NORMAL;
m_input_fd = 0;
Expand Down Expand Up @@ -1045,8 +1037,6 @@ void sinsp::refresh_ifaddr_list()
#endif
}

bool should_drop(sinsp_evt *evt, bool* stopped, bool* switched);

//
// This restarts the current event capture. This de-initializes and
// re-initializes the internal state of both sinsp and scap, and is
Expand Down Expand Up @@ -1374,35 +1364,10 @@ int32_t sinsp::next(OUT sinsp_evt **puevt)
m_fds_to_remove->clear();
}

#ifdef SIMULATE_DROP_MODE
bool sd = false;
bool sw = false;

if(m_analyzer)
{
m_analyzer->m_configuration->set_analyzer_sample_len_ns(500000000);
}

sd = should_drop(evt, &m_isdropping, &sw);
#endif

//
// Run the state engine
//
#ifdef SIMULATE_DROP_MODE
if(!sd || m_isdropping)
{
m_parser->process_event(evt);
}

if(sd && !m_isdropping)
{
*evt = NULL;
return SCAP_TIMEOUT;
}
#else
m_parser->process_event(evt);
#endif

// run plugin-implemented parsers
// note: we run the parsers even if the event has been filtered out,
Expand Down
6 changes: 0 additions & 6 deletions userspace/libsinsp/sinsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ limitations under the License.
#include <libsinsp/sinsp_suppress.h>
class sinsp_partial_transaction;
class sinsp_parser;
class sinsp_analyzer;
class sinsp_filter;
class cycle_writer;
class sinsp_plugin;
Expand Down Expand Up @@ -1103,11 +1102,6 @@ VISIBILITY_PRIVATE
//
sinsp_evt::param_fmt m_buffer_format;

//
// Some dropping infrastructure
//
bool m_isdropping;

// A queue of pending internal state events:
// * container events. Written from async
// callbacks that occur after looking up container
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/external_processor.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class sinsp_external_processor_dummy : public event_processor
{
void on_capture_start() override {}
void process_event(sinsp_evt* evt, event_return rc) override {}
void add_chisel_metric(statsd_metric* metric) override {}
void add_chisel_metric(chisel_metric* metric) override {}
};

TEST(sinsp, external_event_processor_initialization)
Expand Down
10 changes: 3 additions & 7 deletions userspace/libsinsp/threadinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2080,16 +2080,12 @@ threadinfo_map_t::ptr_t sinsp_thread_manager::get_thread_ref(int64_t tid, bool q
}
}

#ifdef HAS_ANALYZER
uint64_t ts = sinsp_utils::get_current_time_ns();
#endif
if(scap_proc_get(m_inspector->get_scap_platform(), tid, &scap_proc, scan_sockets) == SCAP_SUCCESS)
{
have_scap_proc = true;
}
#ifdef HAS_ANALYZER
{
have_scap_proc = true;
}
m_n_proc_lookups_duration_ns += sinsp_utils::get_current_time_ns() - ts;
#endif
}

if(have_scap_proc)
Expand Down