Skip to content

Commit

Permalink
refactor(userspace/libsinsp): cleanup chisel metrics
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <[email protected]>
  • Loading branch information
jasondellaluce authored and poiana committed Jan 22, 2024
1 parent e0a1a15 commit 9d2ff1e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
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
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

0 comments on commit 9d2ff1e

Please sign in to comment.