Skip to content

Commit

Permalink
filterx/filterx-metrics: optimize once
Browse files Browse the repository at this point in the history
If optimization did not succeed, probably it won't
in the future, so just skip it.

Signed-off-by: Attila Szakacs <[email protected]>
  • Loading branch information
alltilla committed Aug 6, 2024
1 parent a3a3e89 commit 78fd0e0
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lib/filterx/filterx-metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,21 @@ _is_const(FilterXMetrics *self)
return !self->key.expr && (!self->labels || filterx_metrics_labels_is_const(self->labels));
}

static gboolean
static void
_optimize(FilterXMetrics *self)
{
if (!self->key.str || !filterx_metrics_labels_is_const(self->labels))
return TRUE;
return;

ScratchBuffersMarker marker;
scratch_buffers_mark(&marker);

StatsClusterKey sck;
if (!_format_sck(self, &sck))
{
msg_debug("FilterX: Failed to optimize metrics, continuing unoptimized");
scratch_buffers_reclaim_marked(marker);
return FALSE;
return;
}

stats_lock();
Expand All @@ -133,8 +134,6 @@ _optimize(FilterXMetrics *self)

filterx_metrics_labels_free(self->labels);
self->labels = NULL;

return TRUE;
}

gboolean
Expand All @@ -151,11 +150,7 @@ filterx_metrics_get_stats_counter(FilterXMetrics *self, StatsCounterItem **count
* as we don't have stats options when FilterXExprs are being created.
*/
if (!self->is_optimized)
{
if (!_optimize(self))
return FALSE;
self->is_optimized = TRUE;
}
_optimize(self);

if (_is_const(self))
{
Expand Down

0 comments on commit 78fd0e0

Please sign in to comment.