Make ingest threshold configurable (#2845)

* Make ingest threshold configurable

* Credo
This commit is contained in:
hq1 2023-04-13 13:52:54 +02:00 committed by GitHub
parent ef73816bb5
commit 825a754976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 2 deletions

View File

@ -16,4 +16,5 @@ GOOGLE_CLIENT_ID=875387135161-l8tp53dpt7fdhdg9m1pc3vl42si95rh0.apps.googleuserco
GOOGLE_CLIENT_SECRET=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
PROMEX_DISABLED=false
SITE_DEFAULT_INGEST_THRESHOLD=1000000
V2_MIGRATION_DONE=1

View File

@ -12,3 +12,4 @@ SITE_LIMIT=3
HCAPTCHA_SITEKEY=test
HCAPTCHA_SECRET=scottiger
IP_GEOLOCATION_DB=test/priv/GeoLite2-City-Test.mmdb
SITE_DEFAULT_INGEST_THRESHOLD=1000000

View File

@ -580,3 +580,17 @@ config :plausible, Plausible.PromEx,
drop_metrics_groups: [],
grafana: :disabled,
metrics_server: :disabled
if not is_selfhost do
site_default_ingest_threshold =
case System.get_env("SITE_DEFAULT_INGEST_THRESHOLD") do
threshold when byte_size(threshold) > 0 ->
{value, ""} = Integer.parse(threshold)
value
_ ->
nil
end
config :plausible, Plausible.Site, default_ingest_threshold: site_default_ingest_threshold
end

View File

@ -19,6 +19,7 @@ defmodule Plausible.Site do
field :native_stats_start_at, :naive_datetime
field :ingest_rate_limit_scale_seconds, :integer, default: 60
# default is set via changeset/2
field :ingest_rate_limit_threshold, :integer
field :domain_changed_from, :string
@ -61,6 +62,10 @@ defmodule Plausible.Site do
name: "domain_change_disallowed",
message: @domain_unique_error
)
|> put_change(
:ingest_rate_limit_threshold,
Application.get_env(:plausible, __MODULE__)[:default_ingest_threshold]
)
end
def update_changeset(site, attrs \\ %{}, opts \\ []) do

View File

@ -47,7 +47,7 @@ defmodule Plausible.Site.Domain do
changeset = Site.update_changeset(site, %{domain: new_domain}, opts)
changeset =
if Enum.empty?(changeset.changes) and is_nil(changeset.errors[:domain]) do
if is_nil(changeset.errors[:domain]) and is_nil(changeset.changes[:domain]) do
Ecto.Changeset.add_error(
changeset,
:domain,

View File

@ -107,7 +107,11 @@ defmodule PlausibleWeb.SiteControllerTest do
})
assert redirected_to(conn) == "/example.com/snippet"
assert Repo.get_by(Plausible.Site, domain: "example.com")
assert site = Repo.get_by(Plausible.Site, domain: "example.com")
assert site.domain == "example.com"
assert site.timezone == "Europe/London"
assert site.ingest_rate_limit_scale_seconds == 60
assert site.ingest_rate_limit_threshold == 1_000_000
end
test "fails to create the site if only http:// provided", %{conn: conn} do