From a27c7a89c3bb09768dcb2d8cb57397bf2728140b Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Wed, 28 Jan 2026 15:58:24 +0200 Subject: [PATCH 1/9] WIP --- lib/plausible/clickhouse_repo.ex | 36 ++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/plausible/clickhouse_repo.ex b/lib/plausible/clickhouse_repo.ex index cf5c0dedf764..97cc3016fcc7 100644 --- a/lib/plausible/clickhouse_repo.ex +++ b/lib/plausible/clickhouse_repo.ex @@ -59,13 +59,45 @@ defmodule Plausible.ClickhouseRepo do log_comment = Jason.encode!(log_comment_data) opts = - Keyword.update(opts, :settings, [log_comment: log_comment], fn settings -> - [{:log_comment, log_comment} | settings] + opts + |> Keyword.update(:settings, [log_comment: log_comment], fn current_settings -> + [{:log_comment, log_comment} | current_settings] end) + opts = + if plausible_query do + opts + |> Keyword.update!(:settings, fn current_settings -> + Enum.concat(get_extra_connection_settings(log_comment_data), current_settings) + end) + else + opts + end + {query, opts} end + defp get_extra_connection_settings(%{params: params}) do + keys = + params + |> Map.keys() + |> Enum.filter(fn k -> + case k do + "clickhouse_readonly" -> false + "clickhouse_" <> _k -> true + _ -> false + end + end) + + Enum.map(keys, fn k -> + {String.to_atom(String.trim_leading(k, "clickhouse_")), params[k]} + end) + end + + defp get_extra_connection_settings(_) do + [] + end + def get_config_without_ch_query_execution_timeout() do {settings, config} = Plausible.ClickhouseRepo.config() |> Keyword.pop!(:settings) From 8d9c936749ae3c6908a7690e395b2f5301dc88b4 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Wed, 4 Feb 2026 15:20:52 +0200 Subject: [PATCH 2/9] Local HAProxy - mode HTTP works with cancel_http_readonly_queries_on_client_close --- CONTRIBUTING.md | 2 +- Makefile | 7 ++-- config/.env.dev | 2 +- config/.env.test | 2 +- config/runtime.exs | 4 +-- haproxy.cfg | 36 +++++++++++++++++++ .../controllers/api/stats_controller.ex | 5 +-- 7 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 haproxy.cfg diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 255e08a7e5d8..a3116800dd2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Make sure Docker, Elixir, Erlang and Node.js are all installed on your developme ### Start the environment -1. Run both `make postgres` and `make clickhouse`. +1. Run `make network`, `make postgres`, `make clickhouse`, `make ch-haproxy` 2. You can set up everything with `make install`, alternatively run each command separately: 1. Run `mix deps.get`. This will download the required Elixir dependencies. 2. Run `mix ecto.create`. This will create the required databases in both Postgres and Clickhouse. diff --git a/Makefile b/Makefile index 167706e68ac8..51fc101ee403 100644 --- a/Makefile +++ b/Makefile @@ -21,10 +21,13 @@ install: ## Run the initial setup server: ## Start the web server mix phx.server -CH_FLAGS ?= --detach -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 --name plausible_clickhouse --env CLICKHOUSE_SKIP_USER_SETUP=1 +CH_FLAGS ?= --detach -p 8123:8123 --ulimit nofile=262144:262144 --name plausible_clickhouse --env CLICKHOUSE_SKIP_USER_SETUP=1 + +network: ## Create a docker network for clickhouse and haproxy + docker network create ch-net || true clickhouse: ## Start a container with a recent version of clickhouse - docker run $(CH_FLAGS) --network host --volume=$$PWD/.clickhouse_db_vol:/var/lib/clickhouse --volume=$$PWD/.clickhouse_config:/etc/clickhouse-server/config.d clickhouse/clickhouse-server:latest-alpine + docker run $(CH_FLAGS) --network ch-net --volume=$$PWD/.clickhouse_db_vol:/var/lib/clickhouse --volume=$$PWD/.clickhouse_config:/etc/clickhouse-server/config.d clickhouse/clickhouse-server:latest-alpine clickhouse-client: ## Connect to clickhouse docker exec -it plausible_clickhouse clickhouse-client -d plausible_events_db diff --git a/config/.env.dev b/config/.env.dev index c1b5361dcecc..09a83a731f57 100644 --- a/config/.env.dev +++ b/config/.env.dev @@ -1,7 +1,7 @@ BASE_URL=http://localhost:8000 SECURE_COOKIE=false DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_dev -CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_events_db +CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8124/plausible_events_db CLICKHOUSE_MAX_BUFFER_SIZE_BYTES=1000000 SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg TOTP_VAULT_KEY=Q3BD4nddbkVJIPXgHuo5NthGKSIH0yesRfG05J88HIo= diff --git a/config/.env.test b/config/.env.test index 42a1e8552634..dba6d320cfcd 100644 --- a/config/.env.test +++ b/config/.env.test @@ -1,5 +1,5 @@ DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_test -CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_test +CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8124/plausible_test SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg TOTP_VAULT_KEY=1Jah1HEOnCEnmBE+4/OgbJRraJIppPmYCNbZoFJboZs= BASE_URL=http://localhost:8000 diff --git a/config/runtime.exs b/config/runtime.exs index 0ecd2d04d558..7f02a48f1e29 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -118,7 +118,7 @@ ch_db_url = get_var_from_path_or_env( config_dir, "CLICKHOUSE_DATABASE_URL", - "http://plausible_events_db:8123/plausible_events_db" + "http://plausible_events_db:8124/plausible_events_db" ) {ingest_pool_size, ""} = @@ -638,7 +638,7 @@ config :plausible, Plausible.ClickhouseRepo, # NB! when :timeout is overridden to be over 20s, # for it to have meaningful effect, # this must be overridden as well - max_execution_time: 20 + # max_execution_time: 20 ] config :plausible, Plausible.IngestRepo, diff --git a/haproxy.cfg b/haproxy.cfg new file mode 100644 index 000000000000..1dfaff28b88d --- /dev/null +++ b/haproxy.cfg @@ -0,0 +1,36 @@ +global + daemon + maxconn 20000 + # the default of 16384 bytes was too small + # clickhouse http_max_uri_size is 104857600 + tune.bufsize 104857600 + +defaults + # mode is inherited by sections that follow + mode http + option dontlognull + option httplog + option dontlog-normal + option abortonclose + timeout connect 10s + timeout client 100s + timeout server 100s + log global + +frontend clickhouse_http + mode http + + # receives traffic from clients + bind *:8123 + + default_backend clickhouse_http + + log /var/log/haproxy.log local0 + +backend clickhouse_http + mode http + balance roundrobin + + option httpchk GET /ping + http-check expect string Ok. + server ch1 plausible_clickhouse:8123 check diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index ff4cef88f310..2660ac7e6852 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -1523,8 +1523,9 @@ defmodule PlausibleWeb.Api.StatsController do end def current_visitors(conn, _) do - site = conn.assigns[:site] - json(conn, Stats.current_visitors(site)) + # site = conn.assigns[:site] + Plausible.ClickhouseRepo.query("SELECT 'direct_test', count(*) FROM numbers(8000000000) WHERE sipHash64(number) % 1000000 = 0") + json(conn, %{"finish" => true}) end defp google_api(), do: Application.fetch_env!(:plausible, :google_api) From 6ffa8314d0fc9e2bff07f7ba486355fb3c39005c Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Fri, 6 Feb 2026 10:38:16 +0200 Subject: [PATCH 3/9] Try workloads --- config/runtime.exs | 5 +++-- lib/plausible/clickhouse_repo.ex | 17 +++++++++++++++-- .../controllers/api/stats_controller.ex | 5 ++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 7f02a48f1e29..d6afd080ed4f 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -638,7 +638,7 @@ config :plausible, Plausible.ClickhouseRepo, # NB! when :timeout is overridden to be over 20s, # for it to have meaningful effect, # this must be overridden as well - # max_execution_time: 20 + max_execution_time: 20 ] config :plausible, Plausible.IngestRepo, @@ -650,7 +650,8 @@ config :plausible, Plausible.IngestRepo, max_buffer_size: ch_max_buffer_size, pool_size: ingest_pool_size, settings: [ - materialized_views_ignore_errors: 1 + materialized_views_ignore_errors: 1, + workload: "ingestion" ], table_settings: [ storage_policy: get_var_from_path_or_env(config_dir, "CLICKHOUSE_DEFAULT_STORAGE_POLICY") diff --git a/lib/plausible/clickhouse_repo.ex b/lib/plausible/clickhouse_repo.ex index 97cc3016fcc7..c625d9e3ff11 100644 --- a/lib/plausible/clickhouse_repo.ex +++ b/lib/plausible/clickhouse_repo.ex @@ -68,7 +68,20 @@ defmodule Plausible.ClickhouseRepo do if plausible_query do opts |> Keyword.update!(:settings, fn current_settings -> - Enum.concat(get_extra_connection_settings(log_comment_data), current_settings) + current_settings |> Enum.concat(get_extra_connection_settings(log_comment_data)) + end) + |> Keyword.update!(:settings, fn current_settings -> + should_use_workload? = + Keyword.get(current_settings, :phoenix_controller, nil) in [ + PlausibleWeb.Api.ExternalStatsController |> to_string(), + PlausibleWeb.Api.ExternalQueryApiController |> to_string() + ] + + if should_use_workload? do + [{:workload, "external_api"} | current_settings] + else + current_settings + end end) else opts @@ -90,7 +103,7 @@ defmodule Plausible.ClickhouseRepo do end) Enum.map(keys, fn k -> - {String.to_atom(String.trim_leading(k, "clickhouse_")), params[k]} + {k |> String.trim_leading("clickhouse_") |> String.to_atom(), params[k]} end) end diff --git a/lib/plausible_web/controllers/api/stats_controller.ex b/lib/plausible_web/controllers/api/stats_controller.ex index 2660ac7e6852..ff4cef88f310 100644 --- a/lib/plausible_web/controllers/api/stats_controller.ex +++ b/lib/plausible_web/controllers/api/stats_controller.ex @@ -1523,9 +1523,8 @@ defmodule PlausibleWeb.Api.StatsController do end def current_visitors(conn, _) do - # site = conn.assigns[:site] - Plausible.ClickhouseRepo.query("SELECT 'direct_test', count(*) FROM numbers(8000000000) WHERE sipHash64(number) % 1000000 = 0") - json(conn, %{"finish" => true}) + site = conn.assigns[:site] + json(conn, Stats.current_visitors(site)) end defp google_api(), do: Application.fetch_env!(:plausible, :google_api) From 91f77308f3d17610d1f122b41cd590c2545f7f29 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Fri, 6 Feb 2026 12:55:54 +0200 Subject: [PATCH 4/9] Fix prepare query --- lib/plausible/clickhouse_repo.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plausible/clickhouse_repo.ex b/lib/plausible/clickhouse_repo.ex index c625d9e3ff11..f6e493dcaa80 100644 --- a/lib/plausible/clickhouse_repo.ex +++ b/lib/plausible/clickhouse_repo.ex @@ -72,7 +72,7 @@ defmodule Plausible.ClickhouseRepo do end) |> Keyword.update!(:settings, fn current_settings -> should_use_workload? = - Keyword.get(current_settings, :phoenix_controller, nil) in [ + Map.get(plausible_query.debug_metadata, :phoenix_controller, nil) in [ PlausibleWeb.Api.ExternalStatsController |> to_string(), PlausibleWeb.Api.ExternalQueryApiController |> to_string() ] From e2777901c3db2f3af6457c52c77b31f1f531c06b Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Fri, 6 Feb 2026 15:55:17 +0200 Subject: [PATCH 5/9] Update send pageview --- lib/mix/tasks/send_pageview.ex | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/send_pageview.ex b/lib/mix/tasks/send_pageview.ex index 0ab839ff0011..6769335cd7e9 100644 --- a/lib/mix/tasks/send_pageview.ex +++ b/lib/mix/tasks/send_pageview.ex @@ -19,6 +19,8 @@ defmodule Mix.Tasks.SendPageview do @default_props "{}" @default_queryparams "" @default_interactive true + @default_batches 1 + @default_batch_size 1 @options [ ip: :string, user_agent: :string, @@ -32,7 +34,9 @@ defmodule Mix.Tasks.SendPageview do revenue_currency: :string, revenue_amount: :string, queryparams: :string, - interactive: :string + interactive: :string, + batches: :integer, + batch_size: :integer ] def run(opts) do @@ -42,7 +46,28 @@ defmodule Mix.Tasks.SendPageview do case invalid do [] -> - do_send_pageview(parsed) + batches = Keyword.get(parsed, :batches, @default_batches) + batch_size = Keyword.get(parsed, :batch_size, @default_batch_size) + + for _ <- 1..batches do + batch_ips = + 1..max(Integer.floor_div(batch_size, 20), 1) + |> Enum.map(fn _ -> Enum.map_join(1..4, ".", fn _ -> Enum.random(1..254) end) end) + + tasks = + 1..batch_size + |> Enum.map(fn i -> + Task.async(fn -> + do_send_pageview( + parsed + |> Keyword.update(:page, "#{@default_page}#{i}", fn page -> "#{page}/#{i}" end) + |> Keyword.put(:ip, Enum.random(batch_ips)) + ) + end) + end) + + Task.await_many(tasks) + end [invalid_option | _] -> {key, _val} = invalid_option From 950faae92e4b647fc2e2f92e31f1857519274892 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 12 Feb 2026 13:41:02 +0200 Subject: [PATCH 6/9] Clarify batch --- lib/mix/tasks/send_pageview.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/send_pageview.ex b/lib/mix/tasks/send_pageview.ex index 6769335cd7e9..a514016b9a02 100644 --- a/lib/mix/tasks/send_pageview.ex +++ b/lib/mix/tasks/send_pageview.ex @@ -48,10 +48,10 @@ defmodule Mix.Tasks.SendPageview do [] -> batches = Keyword.get(parsed, :batches, @default_batches) batch_size = Keyword.get(parsed, :batch_size, @default_batch_size) - + from_same_ip_limit = 20 for _ <- 1..batches do batch_ips = - 1..max(Integer.floor_div(batch_size, 20), 1) + 1..max(Integer.floor_div(batch_size, from_same_ip_limit), 1) |> Enum.map(fn _ -> Enum.map_join(1..4, ".", fn _ -> Enum.random(1..254) end) end) tasks = From b97564fcc8f77ae32ece58f3c77a497758bf8717 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 19 Feb 2026 13:14:49 +0200 Subject: [PATCH 7/9] Apply admin workload to app <-> CH readiness check --- lib/plausible_web/controllers/api/system_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plausible_web/controllers/api/system_controller.ex b/lib/plausible_web/controllers/api/system_controller.ex index 4e5c75648217..8c41abe42960 100644 --- a/lib/plausible_web/controllers/api/system_controller.ex +++ b/lib/plausible_web/controllers/api/system_controller.ex @@ -41,7 +41,7 @@ defmodule PlausibleWeb.Api.SystemController do clickhouse_health_task = Task.async(fn -> - Ecto.Adapters.SQL.query(Plausible.ClickhouseRepo, "SELECT 1", []) + Plausible.ClickhouseRepo.query("SELECT 1", [], [settings: [workload: "admin"]]) end) postgres_health = From 7d13a8fa461340d799571c468e91b4d7f3205134 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 19 Feb 2026 13:27:27 +0200 Subject: [PATCH 8/9] Set app<->CH readiness probe workload to ingestion --- lib/plausible_web/controllers/api/system_controller.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/plausible_web/controllers/api/system_controller.ex b/lib/plausible_web/controllers/api/system_controller.ex index 8c41abe42960..cbd3f5b63af8 100644 --- a/lib/plausible_web/controllers/api/system_controller.ex +++ b/lib/plausible_web/controllers/api/system_controller.ex @@ -41,7 +41,7 @@ defmodule PlausibleWeb.Api.SystemController do clickhouse_health_task = Task.async(fn -> - Plausible.ClickhouseRepo.query("SELECT 1", [], [settings: [workload: "admin"]]) + Plausible.ClickhouseRepo.query("SELECT 1", [], [settings: [workload: "ingestion"]]) end) postgres_health = From a3b6a9e523ab13b06a5aadab6157cfbd334a4b58 Mon Sep 17 00:00:00 2001 From: Artur Pata Date: Thu, 19 Feb 2026 13:39:59 +0200 Subject: [PATCH 9/9] Revert unnecessary changes --- CONTRIBUTING.md | 2 +- Makefile | 7 ++----- config/.env.dev | 2 +- config/.env.test | 2 +- config/runtime.exs | 2 +- haproxy.cfg | 36 ---------------------------------- lib/mix/tasks/send_pageview.ex | 29 ++------------------------- 7 files changed, 8 insertions(+), 72 deletions(-) delete mode 100644 haproxy.cfg diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a3116800dd2f..255e08a7e5d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,7 +10,7 @@ Make sure Docker, Elixir, Erlang and Node.js are all installed on your developme ### Start the environment -1. Run `make network`, `make postgres`, `make clickhouse`, `make ch-haproxy` +1. Run both `make postgres` and `make clickhouse`. 2. You can set up everything with `make install`, alternatively run each command separately: 1. Run `mix deps.get`. This will download the required Elixir dependencies. 2. Run `mix ecto.create`. This will create the required databases in both Postgres and Clickhouse. diff --git a/Makefile b/Makefile index 51fc101ee403..167706e68ac8 100644 --- a/Makefile +++ b/Makefile @@ -21,13 +21,10 @@ install: ## Run the initial setup server: ## Start the web server mix phx.server -CH_FLAGS ?= --detach -p 8123:8123 --ulimit nofile=262144:262144 --name plausible_clickhouse --env CLICKHOUSE_SKIP_USER_SETUP=1 - -network: ## Create a docker network for clickhouse and haproxy - docker network create ch-net || true +CH_FLAGS ?= --detach -p 8123:8123 -p 9000:9000 --ulimit nofile=262144:262144 --name plausible_clickhouse --env CLICKHOUSE_SKIP_USER_SETUP=1 clickhouse: ## Start a container with a recent version of clickhouse - docker run $(CH_FLAGS) --network ch-net --volume=$$PWD/.clickhouse_db_vol:/var/lib/clickhouse --volume=$$PWD/.clickhouse_config:/etc/clickhouse-server/config.d clickhouse/clickhouse-server:latest-alpine + docker run $(CH_FLAGS) --network host --volume=$$PWD/.clickhouse_db_vol:/var/lib/clickhouse --volume=$$PWD/.clickhouse_config:/etc/clickhouse-server/config.d clickhouse/clickhouse-server:latest-alpine clickhouse-client: ## Connect to clickhouse docker exec -it plausible_clickhouse clickhouse-client -d plausible_events_db diff --git a/config/.env.dev b/config/.env.dev index 09a83a731f57..c1b5361dcecc 100644 --- a/config/.env.dev +++ b/config/.env.dev @@ -1,7 +1,7 @@ BASE_URL=http://localhost:8000 SECURE_COOKIE=false DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_dev -CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8124/plausible_events_db +CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_events_db CLICKHOUSE_MAX_BUFFER_SIZE_BYTES=1000000 SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg TOTP_VAULT_KEY=Q3BD4nddbkVJIPXgHuo5NthGKSIH0yesRfG05J88HIo= diff --git a/config/.env.test b/config/.env.test index dba6d320cfcd..42a1e8552634 100644 --- a/config/.env.test +++ b/config/.env.test @@ -1,5 +1,5 @@ DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/plausible_test -CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8124/plausible_test +CLICKHOUSE_DATABASE_URL=http://127.0.0.1:8123/plausible_test SECRET_KEY_BASE=/njrhntbycvastyvtk1zycwfm981vpo/0xrvwjjvemdakc/vsvbrevlwsc6u8rcg TOTP_VAULT_KEY=1Jah1HEOnCEnmBE+4/OgbJRraJIppPmYCNbZoFJboZs= BASE_URL=http://localhost:8000 diff --git a/config/runtime.exs b/config/runtime.exs index d6afd080ed4f..def0f04d4aa9 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -118,7 +118,7 @@ ch_db_url = get_var_from_path_or_env( config_dir, "CLICKHOUSE_DATABASE_URL", - "http://plausible_events_db:8124/plausible_events_db" + "http://plausible_events_db:8123/plausible_events_db" ) {ingest_pool_size, ""} = diff --git a/haproxy.cfg b/haproxy.cfg deleted file mode 100644 index 1dfaff28b88d..000000000000 --- a/haproxy.cfg +++ /dev/null @@ -1,36 +0,0 @@ -global - daemon - maxconn 20000 - # the default of 16384 bytes was too small - # clickhouse http_max_uri_size is 104857600 - tune.bufsize 104857600 - -defaults - # mode is inherited by sections that follow - mode http - option dontlognull - option httplog - option dontlog-normal - option abortonclose - timeout connect 10s - timeout client 100s - timeout server 100s - log global - -frontend clickhouse_http - mode http - - # receives traffic from clients - bind *:8123 - - default_backend clickhouse_http - - log /var/log/haproxy.log local0 - -backend clickhouse_http - mode http - balance roundrobin - - option httpchk GET /ping - http-check expect string Ok. - server ch1 plausible_clickhouse:8123 check diff --git a/lib/mix/tasks/send_pageview.ex b/lib/mix/tasks/send_pageview.ex index a514016b9a02..0ab839ff0011 100644 --- a/lib/mix/tasks/send_pageview.ex +++ b/lib/mix/tasks/send_pageview.ex @@ -19,8 +19,6 @@ defmodule Mix.Tasks.SendPageview do @default_props "{}" @default_queryparams "" @default_interactive true - @default_batches 1 - @default_batch_size 1 @options [ ip: :string, user_agent: :string, @@ -34,9 +32,7 @@ defmodule Mix.Tasks.SendPageview do revenue_currency: :string, revenue_amount: :string, queryparams: :string, - interactive: :string, - batches: :integer, - batch_size: :integer + interactive: :string ] def run(opts) do @@ -46,28 +42,7 @@ defmodule Mix.Tasks.SendPageview do case invalid do [] -> - batches = Keyword.get(parsed, :batches, @default_batches) - batch_size = Keyword.get(parsed, :batch_size, @default_batch_size) - from_same_ip_limit = 20 - for _ <- 1..batches do - batch_ips = - 1..max(Integer.floor_div(batch_size, from_same_ip_limit), 1) - |> Enum.map(fn _ -> Enum.map_join(1..4, ".", fn _ -> Enum.random(1..254) end) end) - - tasks = - 1..batch_size - |> Enum.map(fn i -> - Task.async(fn -> - do_send_pageview( - parsed - |> Keyword.update(:page, "#{@default_page}#{i}", fn page -> "#{page}/#{i}" end) - |> Keyword.put(:ip, Enum.random(batch_ips)) - ) - end) - end) - - Task.await_many(tasks) - end + do_send_pageview(parsed) [invalid_option | _] -> {key, _val} = invalid_option