feat: add Postgres support to SearchOperations#3307
Conversation
693cf45 to
ee679c4
Compare
| key = if key == "count", do: "value", else: key | ||
| Map.put(acc, key, normalize_postgres_value(key, value)) |
There was a problem hiding this comment.
needs to factor in custom aggregates. chart would break for custom agg like p99 i think
would also be good to have unit test in logs_search_lv_test.exs |
b385b5a to
87671ca
Compare
| |> nested_map_update() | ||
| end | ||
|
|
||
| {:ok, rows} |
There was a problem hiding this comment.
We should make the returned map the same as bigquery so that we don't have to normalise in the caller
There was a problem hiding this comment.
An Adaptor.QueryResult struct might work to make things more standardised
| |> TestUtils.wait_for_render("#logs-list-container li") | ||
|
|
||
| assert view |> element("#logs-list-container") |> render() =~ matching_message | ||
| end |
There was a problem hiding this comment.
Should refute non matching message
| 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) | ||
| }) | ||
|
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Don't need to clear cache if it is inserted before source sup is started
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
We're only testing a subset of the accepted aggs?
There was a problem hiding this comment.
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
a955253 to
cbd6465
Compare
3bda886 to
b9b809f
Compare
b9b809f to
ead7a22
Compare
Ziinc
left a comment
There was a problem hiding this comment.
@msmithstubbs can you make the test adjustments in a follow up? 🙏
| PostgresAdaptor | ||
| |> expect(:execute_query, fn ^backend, %Ecto.Query{}, [query_type: :search] -> | ||
| rows = [%{"count" => 2, "timestamp" => unix_timestamp}] | ||
| {:ok, QueryResult.new(rows, %{total_rows: length(rows)})} | ||
| end) | ||
|
|
||
| PostgresAdaptor | ||
| |> expect(:ecto_to_sql, fn %Ecto.Query{}, [] -> | ||
| {:ok, {"SELECT count(*) FROM test_table", []}} | ||
| end) |
There was a problem hiding this comment.
Let's not stub this so thar we have a full integration test
| |> expect(:get_default_backend, fn _user -> backend end) | ||
|
|
||
| PostgresAdaptor | ||
| |> expect(:execute_query, fn ^backend, %Ecto.Query{}, [query_type: :search] -> |
There was a problem hiding this comment.
Simulating a raise (like bad connection) would be preferred
| end) | ||
|
|
||
| PostgresAdaptor | ||
| |> expect(:execute_query, fn ^backend, %Ecto.Query{} = query, opts -> |
There was a problem hiding this comment.
Mock here is not referred for comprehensiveness
| end | ||
|
|
||
| describe "postgres backend adaptor integration" do | ||
| setup %{user: user} do |
There was a problem hiding this comment.
See the SingleTenant test module, there is some test macros that should be used when dealing with single tenant mode that will help with all this provisioning so that we don't need to mock anything
* refactor: backend execute_query/3 returns Adaptor.QueryResult * feat: PostgresAdaptor include total_rows in result * refactor: decouple SearchLV LQL from BigQuery TableSchema * fix: dialyzer warnings * feat: add Postgres support to SearchOperations * style: alias nested modules (credo) * implement PostgresAdaptor.test_connection/1 * fix: postgres adaptor aggregates * fix: execute_query can return error (dialyzer) * test: SearchOperations postgres unit tests * test: SearchLV postgres backend search * test tidy up * refactor: move postgres result normalisation to PostgresAdaptor * test: refute non matching message * test: full list of aggregate types * bump ci * test: put_sql_string matches on backend_type --------- Co-authored-by: Ziinc <Ziinc@users.noreply.github.com>
Adds support for searches against a postgres backend.
backend_typefield to%SearchOperation{}, defaults to `:bigquery', and is set automatically to default backend.SearchOperationsbuilds the search query for the appropriate backendIntended for integration tests in CI. Part of #3239
Follows on from #3306 and #3317
test_connection/1in test setup