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

fix(libsinsp): do not invalidate thread manager cache when using plugin state api #2257

Merged
merged 2 commits into from
Jan 24, 2025
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
69 changes: 39 additions & 30 deletions userspace/libsinsp/test/plugins.ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,9 +862,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand All @@ -890,14 +898,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {
ASSERT_NE(dfield, subtable->dynamic_fields()->fields().end());
auto dfieldacc = dfield->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -918,7 +921,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -928,7 +931,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down Expand Up @@ -960,9 +963,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand All @@ -985,14 +996,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {
ASSERT_EQ(dfield->second.info(), libsinsp::state::typeinfo::of<std::string>());
auto dfieldacc = dfield->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1010,7 +1016,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1020,7 +1026,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down Expand Up @@ -1053,9 +1059,17 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

ASSERT_EQ(table->entries_count(), 0);

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
// note: we need to do this before adding our artificial threadinfo because
// the threads table is cleared up upon inspectors being opened
open_inspector();

// add a new entry to the thread table
ASSERT_NE(table->add_entry(5, table->new_entry()), nullptr);
auto entry = table->get_entry(5);
int64_t tid = 5;
ASSERT_NE(table->add_entry(tid, table->new_entry()), nullptr);
auto entry = table->get_entry(tid);
ASSERT_NE(entry, nullptr);
ASSERT_EQ(table->entries_count(), 1);

Expand Down Expand Up @@ -1087,14 +1101,9 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {
ASSERT_EQ(dfield_second->second.info(), libsinsp::state::typeinfo::of<std::string>());
auto dfield_second_acc = dfield_second->second.new_accessor<std::string>();

// start the event capture
// we coordinate with the plugin by sending open events: for each one received,
// the plugin will take a subsequent action on which we then assert the status
open_inspector();

// step #0: the plugin should populate the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1114,7 +1123,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

// step #1: the plugin should remove one entry from the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand All @@ -1124,7 +1133,7 @@ TEST_F(sinsp_with_test_input, plugin_subtables_array_pair) {

// step #2: the plugin should cleae the fdtable
add_event_advance_ts(increasing_ts(),
0,
tid,
PPME_SYSCALL_OPEN_E,
3,
"/tmp/the_file",
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/test/plugins/syscall_subtables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,

ss_plugin_table_t* fdtable = nullptr;

key.s64 = 0;
key.s64 = ev->evt->tid;
entry = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!entry) {
ps->lasterr = "can't get table entry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
ss_plugin_state_data out;
ss_plugin_state_data data;

key.s64 = 0;
key.s64 = ev->evt->tid;
ss_plugin_table_entry_t* tinfo = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!tinfo) {
ps->lasterr = "can't get table entry";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ss_plugin_rc plugin_parse_event(ss_plugin_t* s,
ss_plugin_state_data out;
ss_plugin_state_data data;

key.s64 = 0;
key.s64 = ev->evt->tid;
ss_plugin_table_entry_t* tinfo = in->table_reader_ext->get_table_entry(ps->thread_table, &key);
if(!tinfo) {
ps->lasterr = "can't get table entry";
Expand Down
2 changes: 1 addition & 1 deletion userspace/libsinsp/threadinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ class SINSP_PUBLIC sinsp_thread_manager : public libsinsp::state::table<int64_t>
}

std::shared_ptr<libsinsp::state::table_entry> get_entry(const int64_t& key) override {
return find_thread(key, false);
return find_thread(key, true);
}

std::shared_ptr<libsinsp::state::table_entry> add_entry(
Expand Down
Loading