Skip to content

Commit

Permalink
fix(userspace/libsinsp): address review comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Di Pierro <[email protected]>

Co-authored-by: Jason Dellaluce <[email protected]>
  • Loading branch information
2 people authored and poiana committed Nov 29, 2024
1 parent 14dd3df commit bb27230
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions userspace/libsinsp/dumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void sinsp_dumper::open(sinsp* inspector, const std::string& filename, bool comp
// ask registered ASYNC plugins for a dump of their state
for(auto& p : inspector->m_plugin_manager->plugins()) {
if(p->caps() & CAP_ASYNC) {
p->dump(*this);
p->dump_state(*this);
}
}

Expand All @@ -99,7 +99,7 @@ void sinsp_dumper::fdopen(sinsp* inspector, int fd, bool compress) {
// ask registered ASYNC plugins for a dump of their state
for(auto& p : inspector->m_plugin_manager->plugins()) {
if(p->caps() & CAP_ASYNC) {
p->dump(*this);
p->dump_state(*this);
}
}

Expand Down
6 changes: 3 additions & 3 deletions userspace/libsinsp/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ bool sinsp_plugin::set_async_event_handler(async_event_handler_t handler) {
return rc == SS_PLUGIN_SUCCESS;
}

bool sinsp_plugin::dump(sinsp_dumper& dumper) {
bool sinsp_plugin::dump_state(sinsp_dumper& dumper) {
if(!m_inited) {
throw sinsp_exception(std::string(s_not_init_err) + ": " + m_name);
}
Expand All @@ -1185,7 +1185,7 @@ bool sinsp_plugin::dump(sinsp_dumper& dumper) {
throw sinsp_exception("plugin " + m_name + "without async events cap used as dumper");
}

if(!m_handle->api.dump) {
if(!m_handle->api.dump_state) {
return false;
}

Expand Down Expand Up @@ -1239,7 +1239,7 @@ bool sinsp_plugin::dump(sinsp_dumper& dumper) {
return SS_PLUGIN_SUCCESS;
};

if(m_handle->api.dump(m_state, this, callback) != SS_PLUGIN_SUCCESS) {
if(m_handle->api.dump_state(m_state, this, callback) != SS_PLUGIN_SUCCESS) {
throw sinsp_exception("dump error for plugin '" + m_name + "' : " + m_last_owner_err);
}
return true;
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class sinsp_plugin {
sinsp_thread_pool::routine_id_t subscribe_routine(ss_plugin_routine_fn_t routine_fn,
ss_plugin_routine_state_t* routine_state);
bool unsubscribe_routine(sinsp_thread_pool::routine_id_t routine_id);
bool dump(sinsp_dumper& dumper);
bool dump_state(sinsp_dumper& dumper);

/** Event Sourcing **/
inline uint32_t id() const { return m_id; }
Expand Down
8 changes: 8 additions & 0 deletions userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ class plugin_test_event_processor : public libsinsp::event_processor {
};

// scenario: a plugin with dump capability is requested a dump and then the capture file is read.
// * register a plugin with async event capability
// * open inspector in no driver mode
// * request a scap file dump to a temporary text file
// * at this stage, the plugin will be requested to dump its state; in our test case, the plugin
// will just dump 10 fake events
// * open a replay inspector to read the generated scap file
// * register our event processor that just counts number of PPME_ASYNC_EVENT_E
// * remove the test scap file
// note: emscripten has trouble with the nodriver engine and async events
#if !defined(__EMSCRIPTEN__)
TEST_F(sinsp_with_test_input, plugin_dump) {
Expand Down
8 changes: 4 additions & 4 deletions userspace/libsinsp/test/plugins/syscall_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ ss_plugin_rc plugin_set_async_event_handler(ss_plugin_t* s,
return SS_PLUGIN_SUCCESS;
}

ss_plugin_rc plugin_dump(ss_plugin_t* s,
ss_plugin_owner_t* owner,
const ss_plugin_async_event_handler_t handler) {
ss_plugin_rc plugin_dump_state(ss_plugin_t* s,
ss_plugin_owner_t* owner,
const ss_plugin_async_event_handler_t handler) {
static uint8_t evt_buf[256];
static ss_plugin_event* evt;
char err[PLUGIN_MAX_ERRLEN];
Expand Down Expand Up @@ -240,5 +240,5 @@ void get_plugin_api_sample_syscall_async(plugin_api& out) {
out.get_async_event_sources = plugin_get_async_event_sources;
out.get_async_events = plugin_get_async_events;
out.set_async_event_handler = plugin_set_async_event_handler;
out.dump = plugin_dump;
out.dump_state = plugin_dump_state;
}
6 changes: 3 additions & 3 deletions userspace/plugin/plugin_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1069,9 +1069,9 @@ typedef struct {
// pointer is not retained by the handler after it returns.
//
// Return value: A ss_plugin_rc with values SS_PLUGIN_SUCCESS or SS_PLUGIN_FAILURE.
ss_plugin_rc (*dump)(ss_plugin_t* s,
ss_plugin_owner_t* owner,
const ss_plugin_async_event_handler_t handler);
ss_plugin_rc (*dump_state)(ss_plugin_t* s,
ss_plugin_owner_t* owner,
const ss_plugin_async_event_handler_t handler);
};

// Sets a new plugin configuration when provided by the framework.
Expand Down
2 changes: 1 addition & 1 deletion userspace/plugin/plugin_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ plugin_handle_t* plugin_load(const char* path, char* err) {
SYM_RESOLVE(ret, get_async_event_sources);
SYM_RESOLVE(ret, get_async_events);
SYM_RESOLVE(ret, set_async_event_handler);
SYM_RESOLVE(ret, dump);
SYM_RESOLVE(ret, dump_state);
SYM_RESOLVE(ret, set_config);
SYM_RESOLVE(ret, get_metrics);
SYM_RESOLVE(ret, capture_open);
Expand Down

0 comments on commit bb27230

Please sign in to comment.