Skip to content

feat: default LQL rules for source#3433

Merged
Ziinc merged 5 commits into
Logflare:mainfrom
msmithstubbs:feat/default-lql-rules
May 8, 2026
Merged

feat: default LQL rules for source#3433
Ziinc merged 5 commits into
Logflare:mainfrom
msmithstubbs:feat/default-lql-rules

Conversation

@msmithstubbs
Copy link
Copy Markdown
Contributor

@msmithstubbs msmithstubbs commented May 5, 2026

Adds a default LQL query setting for sources. This LQL query is appended to any new source search.

  • default LQL query can be set per source.
  • any valid LQL expression can be set.
  • when starting a search the default LQL query will be appended
  • editing the query for an existing search will not append the default LQL, allowing the user to remove it.

Questions

  1. Currently all LQL rules (select, filter, etc) are supported. Is this correct?
  2. The LQL parser only removes duplicate select rules. Do we need to handle other depublication?
  3. Should the source default LQL field be available to mange through the source API?

Follows on from #3432

Closes O11Y-740

CleanShot 2026-05-06 at 09 09 53@2x

Demo

CleanShot.2026-05-06.at.09.03.58.mp4

@msmithstubbs msmithstubbs changed the title wip: default LQL rules for source feat: default LQL rules for source May 5, 2026
@msmithstubbs msmithstubbs force-pushed the feat/default-lql-rules branch from 5edc147 to c97568d Compare May 5, 2026 23:12
@msmithstubbs msmithstubbs marked this pull request as ready for review May 5, 2026 23:57
@msmithstubbs msmithstubbs force-pushed the feat/default-lql-rules branch 2 times, most recently from e14060e to 484ded4 Compare May 6, 2026 04:52
Comment thread lib/logflare_web/controllers/source_controller.ex Outdated
@msmithstubbs msmithstubbs force-pushed the feat/default-lql-rules branch from ae0da07 to f1922be Compare May 6, 2026 05:47
Comment thread lib/logflare_web/live/search_live/logs_search_lv.ex Outdated
Comment thread test/logflare_web/live/search_live/logs_search_lv_test.exs Outdated
Comment thread test/logflare_web/live/search_live/logs_search_lv_test.exs
Comment on lines +1066 to +1078
test "allows clearing default search LQL", %{conn: conn, user: user} do
source = insert(:source, user: user, default_search_lql: "s:m.level")

conn =
patch(conn, ~p"/sources/#{source}", %{
"source" => %{"default_search_lql" => ""}
})

assert redirected_to(conn, 302) =~ ~p"/sources/#{source}/edit"
assert Phoenix.Flash.get(conn.assigns.flash, :info) == "Source updated!"
assert Repo.reload(source).default_search_lql == nil
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this as a source_test.exs test would be better

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Had to enable that test case first: #3440

Comment thread lib/logflare_web/live/search_live/logs_search_lv.ex Outdated
Comment thread lib/logflare_web/live/search_live/logs_search_lv.ex
Comment thread lib/logflare_web/live/search_live/logs_search_lv.ex
@msmithstubbs msmithstubbs force-pushed the feat/default-lql-rules branch from ece8427 to 424d00b Compare May 7, 2026 01:31
@msmithstubbs msmithstubbs requested a review from Ziinc May 7, 2026 02:01
@msmithstubbs msmithstubbs force-pushed the feat/default-lql-rules branch from 424d00b to a78ee1e Compare May 7, 2026 23:39
Copy link
Copy Markdown
Contributor

@Ziinc Ziinc left a comment

Choose a reason for hiding this comment

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

nice, very elegant alternative method 💯

Comment on lines +115 to 121
const searchInput = document.getElementById("source-search-querystring")
if (searchInput && searchInput.value !== "") {
searchInput.focus()
searchInput.setSelectionRange(searchInput.value.length, searchInput.value.length)
}

await Source.main({scrollTracker: true}, {avgEventsPerSecond: <%= @source.metrics.avg %>})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this seems quite unnecessary, we can let the changeset handle this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This JS code moves the cursor to the end of the input so the user can start typing straight away.

CleanShot 2026-05-11 at 09 13 45@2x

I'm not sure how to handle it with a changeset, but maybe the intention of the code isn't clear.

@Ziinc Ziinc merged commit 8805fb7 into Logflare:main May 8, 2026
16 checks passed
djwhitt pushed a commit that referenced this pull request May 18, 2026
* test: fix and remove failing tag

* feat: default lql rules for source

* only include default_search_lql param on update

Apply suggestion from @depthfirst-app[bot]

Co-authored-by: depthfirst-app[bot] <184448029+depthfirst-app[bot]@users.noreply.github.com>

* style: format depthfirst fix

* feat: don't append default search to existing querystring

---------

Co-authored-by: depthfirst-app[bot] <184448029+depthfirst-app[bot]@users.noreply.github.com>
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