-
Notifications
You must be signed in to change notification settings - Fork 20
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: update_metric()
#220
Conversation
d3d37cc
to
db74448
Compare
27789cc
to
5a8a604
Compare
Ready for review. |
5a8a604
to
496b2a0
Compare
496b2a0
to
595a7d2
Compare
rebased to main |
lib/filterx/filterx-metrics-labels.c
Outdated
gboolean | ||
filterx_metrics_labels_format(FilterXMetricsLabels *self, StatsClusterLabel **labels, gsize *len) | ||
{ | ||
metrics_cache_reset_labels(metrics_tls_cache()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a point in saving the metrics_tls_cache() value and not do it 3x?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in a new commit.
lib/filterx/filterx-metrics-labels.c
Outdated
return FALSE; | ||
} | ||
|
||
StatsClusterLabel *label = metrics_cache_alloc_label(metrics_tls_cache()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it might even make sense to cache the metrics_tls_cache() across the entire iteration. Getting the value of a TLS variable is not free, especially when wrapped into an external function, like in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, I meant that it would make sense to pass the value around to callbacks that iterate possibly multiple times per message to avoid the TLS overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not think about the overhead. Thanks, fixed this in a new commit.
return FALSE; | ||
} | ||
|
||
self->key.str = g_strdup(filterx_string_get_value(key_obj, NULL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably filterx_object_extract_string() would make sense here (depends on PR #229)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the plan is to merge this first, in that case of course #229 should address this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this specific scenario, we don't need to call the extract function, as we check before that it is a literal, and there are no literal message values.
lib/filterx/filterx-metrics.c
Outdated
} | ||
|
||
GString *name_buffer = scratch_buffers_alloc(); | ||
g_string_append(name_buffer, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you were trying to avoid a g_strdup() here. in that case, it makes sense to use g_string_append_len(), otherwise you'd be doing an strlen() as a part of the copy, while the length is already available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed and squashed to the original commit.
return TRUE; | ||
} | ||
|
||
FilterXObject *increment_obj = filterx_expr_eval_typed(self->increment.expr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract_integer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would depend on #229, so depends on merge order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
exit: | ||
if (!success) | ||
{ | ||
msg_error("FilterX: Failed to process update_metric()", filterx_format_last_error()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is a bad idea to start generating a message in these cases. I think it'd be much better to add an "error" counter along with all update_metric() counters and increment that every time something fails.
With that we could even add limits on how many counters we would be adding in case there's a cardinality explosion.
it does not need to be done now, just an idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, changed the log level to debug in a new commit. We can introduce a counter later.
lib/filterx/filterx-metrics.c
Outdated
*/ | ||
if (!self->is_optimized) | ||
{ | ||
if (!_optimize(self)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be protected by a lock, quite probably we can reuse the starts_lock() in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Fixed in a new commit.
595a7d2
to
16a8251
Compare
Thanks for the thorough review @bazsi. I have fixed all the comments, most of them went to new commits to make it easier to review, starting with the commit filterx/metrics-labels: reduce the number of tls cache acquirals The order of this PR and #229 is undecided, I will update the one which gets merged later. |
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
This class is responsible for formatting a `FilterXExpr` to an array of `StatsClusterLabel`s. The expression must be evaluate to a `Dict[str, Any]`. The formatting is cached wherever it is possible. The implementation uses TLS metrics cache, as `FilterXExpr`s must be stateless currently, but if the need arises, the code can be easily changed to use an arbitrary metrics cache. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
This class is responsible for managing `StatsCounterItem`s based on `key` and `labels` `FilterXExpr`s. `key` must evaluate to a `str`. `labels` must evaluate to a `Dict[str, Any]` is handled by `FilterXMetricsLabels`. The implementation uses TLS metrics cache, as `FilterXExpr`s must be stateless currently, but if the need arises, the code can be easily changed to use an arbitrary metrics cache Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
We need to delay the optimization to the first get() call as we don't have stats options when FilterXExprs are being created. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
It is not used anywhere. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
This could easily flood the logs if something is incorrectly configured. Signed-off-by: Attila Szakacs <[email protected]>
If optimization did not succeed, probably it won't in the future, so just skip it. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
16a8251
to
ab668f7
Compare
Example: