Skip to content

feat: add Postgres support to SearchOperations#3307

Open
msmithstubbs wants to merge 16 commits intoLogflare:mainfrom
msmithstubbs:feat/postgres-search
Open

feat: add Postgres support to SearchOperations#3307
msmithstubbs wants to merge 16 commits intoLogflare:mainfrom
msmithstubbs:feat/postgres-search

Conversation

@msmithstubbs
Copy link
Copy Markdown
Contributor

@msmithstubbs msmithstubbs commented Mar 24, 2026

Adds support for searches against a postgres backend.

  • Adds a backend_type field to %SearchOperation{}, defaults to `:bigquery', and is set automatically to default backend.
  • SearchOperations builds the search query for the appropriate backend

Intended for integration tests in CI. Part of #3239

Follows on from #3306 and #3317

  • use test_connection/1 in test setup
  • handle custom aggregates
  • unit tests in SearchOperationTest
  • unit tests in SearchLV
CleanShot 2026-03-25 at 16 01 00@2x

@msmithstubbs msmithstubbs force-pushed the feat/postgres-search branch 2 times, most recently from 693cf45 to ee679c4 Compare March 24, 2026 05:24
@msmithstubbs msmithstubbs marked this pull request as ready for review March 24, 2026 06:34
Comment on lines +622 to +623
key = if key == "count", do: "value", else: key
Map.put(acc, key, normalize_postgres_value(key, value))
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.

needs to factor in custom aggregates. chart would break for custom agg like p99 i think

@Ziinc
Copy link
Copy Markdown
Contributor

Ziinc commented Mar 24, 2026

I've added a high level search test, do we also want units tests in SearchOperationTest to mirror the BigQuery coverage?
some unit tests would be nice.

would also be good to have unit test in logs_search_lv_test.exs

|> nested_map_update()
end

{:ok, rows}
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.

We should make the returned map the same as bigquery so that we don't have to normalise in the caller

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.

An Adaptor.QueryResult struct might work to make things more standardised

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.

Handled this in a separate PR #3317

|> TestUtils.wait_for_render("#logs-list-container li")

assert view |> element("#logs-list-container") |> render() =~ matching_message
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.

Should refute non matching message

Comment on lines +1372 to +1379
bq_schema = TestUtils.build_bq_schema(%{"event_message" => matching_message})

assert {:ok, _source_schema} =
SourceSchemas.create_or_update_source_schema(source, %{
bigquery_schema: bq_schema,
schema_flat_map: SchemaUtils.bq_schema_to_flat_typemap(bq_schema)
})

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.

Can be combined into a source_schema factory so that it is a bit more ergonomic.

schema_flat_map: SchemaUtils.bq_schema_to_flat_typemap(bq_schema)
})

Cachex.clear(Logflare.SourceSchemas.Cache)
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.

Don't need to clear cache if it is inserted before source sup is started

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.

Good point, moved the insert to happen before source sup start.

end

test "generates expected SQL for all aggregate types", %{base_so: base_so} do
for agg <- [:count, :avg, :sum, :max] do
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.

We're only testing a subset of the accepted aggs?

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.

Had thought of this more as an integration test that aggregate types work since each agg is covered by postgres backend transformer test. But it's cheap test to do here, too.

Added full list: :count, :avg, :sum, :max, :countd, :p50, :p95, :p99

@msmithstubbs msmithstubbs force-pushed the feat/postgres-search branch from 44d6724 to a955253 Compare March 27, 2026 01:40
@msmithstubbs msmithstubbs force-pushed the feat/postgres-search branch from a955253 to cbd6465 Compare March 27, 2026 04:25
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