Drop events when classified as datacenter IP (#3647)

This commit is contained in:
Cenk Kücük 2023-12-21 08:49:00 +01:00 committed by GitHub
parent 9d97dc1912
commit 147597cd98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -144,8 +144,7 @@ defmodule Plausible.Ingestion.Event do
defp put_ip_classification(%__MODULE__{} = event) do
case event.request.ip_classification do
"dc_ip" ->
emit_telemetry_dropped(event, :dc_ip)
event
drop(event, :dc_ip)
_any ->
event

View File

@ -100,6 +100,23 @@ defmodule Plausible.Ingestion.EventTest do
assert dropped.drop_reason == :throttle
end
test "event pipeline drops a request when header x-plausible-ip-type is dc_ip" do
site = insert(:site)
payload = %{
name: "pageview",
url: "http://dummy.site",
domain: site.domain
}
conn = build_conn(:post, "/api/events", payload)
conn = Plug.Conn.put_req_header(conn, "x-plausible-ip-type", "dc_ip")
assert {:ok, request} = Request.build(conn)
assert {:ok, %{buffered: [], dropped: [dropped]}} = Event.build_and_buffer(request)
assert dropped.drop_reason == :dc_ip
end
test "event pipeline drops events for site with accept_trafic_until in the past" do
yesterday = NaiveDateTime.add(NaiveDateTime.utc_now(), -1, :day)
site = insert(:site, ingest_rate_limit_threshold: 1, accept_traffic_until: yesterday)