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

FilterX expression eval metrics #398

Merged
merged 5 commits into from
Nov 29, 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
4 changes: 2 additions & 2 deletions lib/filterx/expr-assign.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ filterx_nullv_assign_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1);

filterx_binary_op_init_instance(self, lhs, rhs);
filterx_binary_op_init_instance(self, "nullv_assign", lhs, rhs);
self->super.eval = _nullv_assign_eval;
self->super.ignore_falsy_result = TRUE;
return &self->super;
Expand All @@ -108,7 +108,7 @@ filterx_assign_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1);

filterx_binary_op_init_instance(self, lhs, rhs);
filterx_binary_op_init_instance(self, "assign", lhs, rhs);
self->super.eval = _assign_eval;
self->super.ignore_falsy_result = TRUE;
return &self->super;
Expand Down
6 changes: 3 additions & 3 deletions lib/filterx/expr-boolalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ filterx_unary_not_new(FilterXExpr *operand)

FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1);

filterx_unary_op_init_instance(self, operand);
filterx_unary_op_init_instance(self, "not", operand);
self->super.eval = _eval_not;
return &self->super;
}
Expand Down Expand Up @@ -115,7 +115,7 @@ filterx_binary_and_new(FilterXExpr *lhs, FilterXExpr *rhs)

FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1);

filterx_binary_op_init_instance(self, lhs, rhs);
filterx_binary_op_init_instance(self, "and", lhs, rhs);
if (filterx_expr_is_literal(lhs))
self->lhs = NULL;

Expand Down Expand Up @@ -171,7 +171,7 @@ filterx_binary_or_new(FilterXExpr *lhs, FilterXExpr *rhs)

FilterXBinaryOp *self = g_new0(FilterXBinaryOp, 1);

filterx_binary_op_init_instance(self, lhs, rhs);
filterx_binary_op_init_instance(self, "or", lhs, rhs);
if (filterx_expr_is_literal(lhs))
self->lhs = NULL;

Expand Down
2 changes: 1 addition & 1 deletion lib/filterx/expr-comparison.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ filterx_comparison_new(FilterXExpr *lhs, FilterXExpr *rhs, gint operator)
{
FilterXComparison *self = g_new0(FilterXComparison, 1);

filterx_binary_op_init_instance(&self->super, lhs, rhs);
filterx_binary_op_init_instance(&self->super, "comparison", lhs, rhs);
self->super.super.eval = _eval;
self->super.super.free_fn = _filterx_comparison_free;
self->operator = operator;
Expand Down
15 changes: 15 additions & 0 deletions lib/filterx/expr-compound.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "filterx/filterx-eval.h"
#include "filterx/object-primitive.h"
#include "scratch-buffers.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

#include <stdarg.h>

Expand All @@ -35,6 +37,7 @@ typedef struct _FilterXCompoundExpr
/* whether this is a statement expression */
gboolean return_value_of_last_expr;
GPtrArray *exprs;

} FilterXCompoundExpr;

static gboolean
Expand Down Expand Up @@ -148,6 +151,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
}
}

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_compound_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -156,6 +165,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXCompoundExpr *self = (FilterXCompoundExpr *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_compound_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

for (gint i = 0; i < self->exprs->len; i++)
{
FilterXExpr *expr = g_ptr_array_index(self->exprs, i);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "filterx/expr-literal.h"
#include "filterx/object-primitive.h"
#include "scratch-buffers.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXConditional FilterXConditional;

Expand Down Expand Up @@ -57,6 +59,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
return FALSE;
}

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_condition_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -66,6 +74,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXConditional *self = (FilterXConditional *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_condition_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit(self->condition, cfg);
filterx_expr_deinit(self->true_branch, cfg);
filterx_expr_deinit(self->false_branch, cfg);
Expand Down
15 changes: 15 additions & 0 deletions lib/filterx/expr-function.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "plugin.h"
#include "cfg.h"
#include "mainloop.h"
#include "stats/stats-cluster-single.h"

GQuark
filterx_function_error_quark(void)
Expand Down Expand Up @@ -227,12 +228,26 @@ filterx_simple_function_new(const gchar *function_name, FilterXFunctionArgs *arg
gboolean
filterx_function_init_method(FilterXFunction *s, GlobalConfig *cfg)
{
stats_lock();
StatsClusterKey sc_key;
StatsClusterLabel labels[] = { stats_cluster_label("name", s->function_name) };
stats_cluster_single_key_set(&sc_key, "fx_func_evals_total", labels, G_N_ELEMENTS(labels));
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &s->super.eval_count);
stats_unlock();

return filterx_expr_init_method(&s->super, cfg);
}

void
filterx_function_deinit_method(FilterXFunction *s, GlobalConfig *cfg)
{
stats_lock();
StatsClusterKey sc_key;
StatsClusterLabel labels[] = { stats_cluster_label("name", s->function_name) };
stats_cluster_single_key_set(&sc_key, "fx_func_evals_total", labels, G_N_ELEMENTS(labels));
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &s->super.eval_count);
stats_unlock();

filterx_expr_deinit_method(&s->super, cfg);
}

Expand Down
1 change: 1 addition & 0 deletions lib/filterx/expr-function.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "filterx/filterx-expr.h"
#include "filterx/filterx-object.h"
#include "filterx/expr-generator.h"
#include "stats/stats-registry.h"
#include "generic-number.h"
#include "plugin.h"

Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-get-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
#include "filterx/expr-get-subscript.h"
#include "filterx/filterx-eval.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXGetSubscript
{
Expand Down Expand Up @@ -117,6 +119,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
return FALSE;
}

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_get_subscript_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -125,6 +133,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXGetSubscript *self = (FilterXGetSubscript *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_get_subscript_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit(self->operand, cfg);
filterx_expr_deinit(self->key, cfg);
filterx_expr_deinit_method(s, cfg);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-getattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "filterx/expr-getattr.h"
#include "filterx/object-string.h"
#include "filterx/filterx-eval.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXGetAttr
{
Expand Down Expand Up @@ -98,6 +100,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
if (!filterx_expr_init(self->operand, cfg))
return FALSE;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_getattr_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -106,6 +114,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXGetAttr *self = (FilterXGetAttr *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_getattr_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit(self->operand, cfg);
filterx_expr_deinit_method(s, cfg);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/filterx/expr-isset.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FilterXExpr *
filterx_isset_new(FilterXExpr *expr)
{
FilterXUnaryOp *self = g_new0(FilterXUnaryOp, 1);
filterx_unary_op_init_instance(self, expr);
filterx_unary_op_init_instance(self, "isset", expr);
self->super.eval = _eval;
return &self->super;
}
2 changes: 1 addition & 1 deletion lib/filterx/expr-null-coalesce.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ filterx_null_coalesce_new(FilterXExpr *lhs, FilterXExpr *rhs)
}

FilterXNullCoalesce *self = g_new0(FilterXNullCoalesce, 1);
filterx_binary_op_init_instance(&self->super, lhs, rhs);
filterx_binary_op_init_instance(&self->super, "null_coalesce", lhs, rhs);
self->super.super.eval = _eval;
return &self->super.super;
}
2 changes: 1 addition & 1 deletion lib/filterx/expr-plus.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ FilterXExpr *
filterx_operator_plus_new(FilterXExpr *lhs, FilterXExpr *rhs)
{
FilterXOperatorPlus *self = g_new0(FilterXOperatorPlus, 1);
filterx_binary_op_init_instance(&self->super, lhs, rhs);
filterx_binary_op_init_instance(&self->super, "plus", lhs, rhs);
self->super.super.eval = _eval;
self->super.super.free_fn = _filterx_operator_plus_free;

Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-set-subscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "filterx/object-null.h"
#include "filterx/object-message-value.h"
#include "scratch-buffers.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXSetSubscript
{
Expand Down Expand Up @@ -167,6 +169,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
return FALSE;
}

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_set_subscript_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -175,6 +183,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXSetSubscript *self = (FilterXSetSubscript *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_set_subscript_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit(self->object, cfg);
filterx_expr_deinit(self->new_value, cfg);
filterx_expr_deinit(self->key, cfg);
Expand Down
14 changes: 14 additions & 0 deletions lib/filterx/expr-setattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "filterx/object-null.h"
#include "filterx/object-message-value.h"
#include "scratch-buffers.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXSetAttr
{
Expand Down Expand Up @@ -143,6 +145,12 @@ _init(FilterXExpr *s, GlobalConfig *cfg)
return FALSE;
}

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_setattr_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

Expand All @@ -151,6 +159,12 @@ _deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXSetAttr *self = (FilterXSetAttr *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_setattr_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit(self->object, cfg);
filterx_expr_deinit(self->new_value, cfg);
filterx_expr_deinit_method(s, cfg);
Expand Down
32 changes: 32 additions & 0 deletions lib/filterx/expr-template.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "filterx/filterx-eval.h"
#include "template/templates.h"
#include "scratch-buffers.h"
#include "stats/stats-registry.h"
#include "stats/stats-cluster-single.h"

typedef struct _FilterXTemplate
{
Expand Down Expand Up @@ -63,13 +65,43 @@ _free(FilterXExpr *s)
filterx_expr_free_method(s);
}

static gboolean
_template_init(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXTemplate *self = (FilterXTemplate *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_template_evals_total", NULL, 0);
stats_register_counter(STATS_LEVEL3, &sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

return filterx_expr_init_method(s, cfg);
}

static void
_template_deinit(FilterXExpr *s, GlobalConfig *cfg)
{
FilterXTemplate *self = (FilterXTemplate *) s;

stats_lock();
StatsClusterKey sc_key;
stats_cluster_single_key_set(&sc_key, "fx_template_evals_total", NULL, 0);
stats_unregister_counter(&sc_key, SC_TYPE_SINGLE_VALUE, &self->super.eval_count);
stats_unlock();

filterx_expr_deinit_method(s, cfg);
}

/* NOTE: takes the object reference */
FilterXExpr *
filterx_template_new(LogTemplate *template)
{
FilterXTemplate *self = g_new0(FilterXTemplate, 1);

filterx_expr_init_instance(&self->super);
self->super.init = _template_init;
self->super.deinit = _template_deinit;
self->super.eval = _eval;
self->super.free_fn = _free;
self->template = template;
Expand Down
Loading