Skip to content

Comments

Replace via_rule with via_rule_id#3109

Open
bblaszkow06 wants to merge 10 commits intoLogflare:mainfrom
bblaszkow06:bb/via-rule-removal
Open

Replace via_rule with via_rule_id#3109
bblaszkow06 wants to merge 10 commits intoLogflare:mainfrom
bblaszkow06:bb/via-rule-removal

Conversation

@bblaszkow06
Copy link
Contributor

@bblaszkow06 bblaszkow06 commented Jan 23, 2026

  • Reduces the size of each LogEvent
  • Unlocks further optimizations in SourceRouter

@bblaszkow06 bblaszkow06 marked this pull request as ready for review January 23, 2026 18:38
def get_lql_rules(ids) do
Cachex.execute!(__MODULE__, fn cache ->
for id <- Enum.uniq(ids) do
ContextCache.fetch(cache, {:get_lql_rule, [id]}, fn -> Rules.get_lql_rule(id) end)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps filtering out those that need to be fetched and then fetching all in one pass with a Repo.all would be more efficient... it would definitely reduce db load.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense for the DB fetching, but not quite for caching, as we wouldn't want to duplicate entries for fetching e.g. [1, 2, 3] and [2, 3], and there's no straightforward way to fetch multiple ids from ETS cache. We could split the list, and group fetch the rest (that is missing from cache). Since get_lql_rules is removed, I'll consider it in a following PR for using in get_rules replacement

Comment on lines 30 to 38
lql_rule =
case le do
%{via_rule_id: nil} -> nil
%{via_rule_id: rule_id} -> Rules.Cache.get_lql_rule(rule_id)
end

maybe_broadcast("source:#{source.token}", "source:#{source.token}:new", %{
body: body,
via_rule: le.via_rule && Map.take(le.via_rule, [:regex]),
via_lql_rule: lql_rule,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get rid of the lql rule broadcasting, it was effectively broken (regex rules was removed a long time ago) so there is no benefit in keeping it here.

Comment on lines 471 to 483
encoded_le =
le
|> Map.take([:body, :origin_source_uuid])
|> Map.put(:via_lql_rule, lql_rule)
|> case do
%{body: %{"metadata" => %{"level" => level}}} = le
when level in ~W(debug info warning error alert critical notice emergency) ->
body = Map.put(le.body, "level", level)
%{le | body: body}

le ->
le
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

never been a fan the body manipulation logic here, lets take the opportunity to rip it out

<%= if log.via_rule do %>
<span data-toggle="tooltip" data-placement="top" title={"Matching #{ log.via_rule.lql_string } routing from #{log.origin_source_uuid }"} style="color: ##5eeb8f;">
<%= if log.via_lql_rule do %>
<span data-toggle="tooltip" data-placement="top" title={"Matching #{ log.via_lql_rule } routing from #{ log.origin_source_uuid }"} style="color: #5eeb8f;">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can just show a "Routed" icon if the log.via_rule_id is present, save us the trouble of fetching the data.

Comment on lines 82 to 87
@doc "Retrieves LQL representation of a rule"
@spec get_rule(non_neg_integer()) :: String.t() | nil
def get_lql_rule(id) do
Repo.one(from(r in Rule, where: r.id == ^id, select: r.lql_string))
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we remove the lql string rendering then we don't really need this.

@Ziinc
Copy link
Contributor

Ziinc commented Jan 27, 2026

we probably can simplify a lot of legacy code here.

@bblaszkow06 bblaszkow06 requested a review from Ziinc January 30, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants