mirror of
https://github.com/plausible/analytics.git
synced 2025-01-03 15:17:58 +03:00
Make ingest threshold configurable (#2845)
* Make ingest threshold configurable * Credo
This commit is contained in:
parent
ef73816bb5
commit
825a754976
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user