Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2682 from Aircloak/cristian/bugfix/misc
Browse files Browse the repository at this point in the history
 Use `sample_rate` config field when loading table for virtual queries
  • Loading branch information
cristianberneanu authored May 2, 2018
2 parents 970bdac + c06d82a commit 6482985
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.2.2
18.2.3
6 changes: 3 additions & 3 deletions air/docs/book.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Aircloak User Guide – version 18.2.2",
"title": "Aircloak User Guide – version 18.2.3",
"styles": {
"website": "styles/website.css"
},
Expand All @@ -12,6 +12,6 @@
],
"language": "en",
"gitbook": "3.2.2",
"description": "This copy of the Aircloak user guide describes the features of, and how to configure and work with Aircloak Insights version 18.2.2.",
"description": "This copy of the Aircloak user guide describes the features of, and how to configure and work with Aircloak Insights version 18.2.3.",
"author": "Aircloak GmbH"
}
}
2 changes: 1 addition & 1 deletion air/docs/content/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Summary

---- Don't alter the line below. Needed as is for automated version number update
## Aircloak Insights - version 18.2.2
## Aircloak Insights - version 18.2.3
---- Don't alter the line above...

- [Introduction](README.md)
Expand Down
6 changes: 6 additions & 0 deletions air/lib/air_web/templates/changelog/changelog.html.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Version 18.2.3

### Bugfixes

- Propagates `sample_rate` config value when loading the database tables needed for virtual tables.

## Version 18.2.2

### Bugfixes
Expand Down
15 changes: 7 additions & 8 deletions cloak/lib/cloak/data_source/table.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,11 @@ defmodule Cloak.DataSource.Table do
# we need to create a virtual data source containing the real database tables referenced by those queries
virtual_tables =
tables
|> Enum.flat_map(&get_virtual_table_db_names/1)
|> Enum.uniq()
|> Enum.reduce(%{}, fn table, acc ->
if String.to_atom(table) in Map.keys(acc),
|> Enum.flat_map(&get_db_tables_for_virtual_query/1)
|> Enum.reduce(%{}, fn {table_id, table}, acc ->
if String.to_atom(table_id) in Map.keys(acc),
do: acc,
else: data_source |> load_tables(connection, {table, %{}}) |> Enum.into(acc)
else: data_source |> load_tables(connection, {table_id, table}) |> Enum.into(acc)
end)

virtual_data_source = %{data_source | tables: virtual_tables}
Expand All @@ -106,14 +105,14 @@ defmodule Cloak.DataSource.Table do

defp parse_virtual_table(table), do: table

defp get_virtual_table_db_names({_, %{query: parsed_query}}) when parsed_query != nil,
defp get_db_tables_for_virtual_query({_, %{query: parsed_query} = table}) when parsed_query != nil,
do:
Lenses.all_queries()
|> Lenses.ast_tables()
|> Lens.to_list(parsed_query)
|> Enum.map(&ast_table_name/1)
|> Enum.map(&{ast_table_name(&1), Map.take(table, [:sample_rate])})

defp get_virtual_table_db_names(_), do: []
defp get_db_tables_for_virtual_query(_), do: []

defp ast_table_name({_, name}), do: name
defp ast_table_name({table, :as, _alias}), do: ast_table_name(table)
Expand Down
2 changes: 1 addition & 1 deletion cloak/priv/datasource_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"properties": {
"db_name": {"type": "string", "minLength": 1},
"user_id": {"type": "string", "minLength": 1},
"ignore_unsupported_types": {"type": "boolean"},
"ignore_unsupported_types": {"type": "boolean", "$comment": "allowed for backward compatibility"},
"sample_rate": {"type": "integer", "minimum": 1, "maximum": 100},
"name": {"type": "string", "minLength": 1, "$comment": "allowed for backward compatibility"},
"row_id": {"type": "string", "minLength": 1, "$comment": "allowed for backward compatibility"},
Expand Down

0 comments on commit 6482985

Please sign in to comment.