Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.
TypeScript analyticsanalytics-dashboardclickhouseelixirgoogle-analyticsmarketingopen-source-analyticsphoenixplausible-analyticspostgresqlprivacyprivacy-friendlyself-hostedsimple-analyticsstatisticstailwindcssweb-analyticswebsite-analyticswebsite-statswebsite-tracking
Stop aggregating buffered ingest counters (#5372)
hq12c41dcd4c1a6
diff --git a/lib/plausible/ingestion/counters/telemetry_handler.ex b/lib/plausible/ingestion/counters/telemetry_handler.exindex 8caa37681e..34523a1e8c 100644--- a/lib/plausible/ingestion/counters/telemetry_handler.ex+++ b/lib/plausible/ingestion/counters/telemetry_handler.ex@@ -1,7 +1,7 @@defmodule Plausible.Ingestion.Counters.TelemetryHandler do@moduledoc """Subscribes to telemetry events emitted by `Plausible.Ingestion.Event`.- Every time a request derived event is either dispatched to clickhouse or dropped,+ Every time a request derived event is dropped,a telemetry event is emitted respectively. That event is captured here,its metadata is extracted and sent for internal stats aggregation via`Counters.Buffer` interface.@@ -10,9 +10,8 @@ defmodule Plausible.Ingestion.Counters.TelemetryHandler doalias Plausible.Ingestion.Event@event_dropped Event.telemetry_event_dropped()- @event_buffered Event.telemetry_event_buffered()- @telemetry_events [@event_dropped, @event_buffered]+ @telemetry_events [@event_dropped]@telemetry_handler &__MODULE__.handle_event/4@spec install(Counters.Buffer.t()) :: :ok@@ -48,18 +47,4 @@ defmodule Plausible.Ingestion.Counters.TelemetryHandler do:okend-- def handle_event(- @event_buffered,- _measurements,- %{- domain: domain,- request_timestamp: timestamp,- tracker_script_version: tracker_script_version- },- buffer- ) do- Counters.Buffer.aggregate(buffer, "buffered", domain, timestamp, tracker_script_version)- :ok- endenddiff --git a/test/plausible/ingestion/counters/telemetry_handler_test.exs b/test/plausible/ingestion/counters/telemetry_handler_test.exsindex 084fb31ab7..8a668f9c62 100644--- a/test/plausible/ingestion/counters/telemetry_handler_test.exs+++ b/test/plausible/ingestion/counters/telemetry_handler_test.exs@@ -19,11 +19,6 @@ defmodule Plausible.Ingestion.Counters.TelemetryHandlerTest dohandler.config == buffer andhandler.event_name == Event.telemetry_event_dropped()end)-- assert Enum.find(all_handlers, fn handler ->- handler.config == buffer and- handler.event_name == Event.telemetry_event_buffered()- end)endtest "handles ingest events by aggregating the counts", %{test: test} do@@ -44,14 +39,8 @@ defmodule Plausible.Ingestion.Counters.TelemetryHandlerTest dorequest: %{timestamp: NaiveDateTime.utc_now(), tracker_script_version: 137}}- e3 = %{- domain: "c.example.com",- request: %{timestamp: NaiveDateTime.utc_now(), tracker_script_version: 137}- }-:ok = Event.emit_telemetry_dropped(e1, :invalid):ok = Event.emit_telemetry_dropped(e2, :not_found)- :ok = Event.emit_telemetry_buffered(e3):ok = Event.emit_telemetry_dropped(e2, :not_found)future = DateTime.utc_now() |> DateTime.add(120, :second)@@ -60,6 +49,5 @@ defmodule Plausible.Ingestion.Counters.TelemetryHandlerTest doassert Enum.find(aggregates, &match?({_, "dropped_invalid", "a.example.com", 137, 1}, &1))assert Enum.find(aggregates, &match?({_, "dropped_not_found", "b.example.com", 137, 2}, &1))- assert Enum.find(aggregates, &match?({_, "buffered", "c.example.com", 137, 1}, &1))endenddiff --git a/test/plausible/ingestion/counters_test.exs b/test/plausible/ingestion/counters_test.exsindex e60d091a25..06ec462942 100644--- a/test/plausible/ingestion/counters_test.exs+++ b/test/plausible/ingestion/counters_test.exs@@ -38,12 +38,8 @@ defmodule Plausible.Ingestion.CountersTest do{:ok, dropped} = emit_dropped_request(at: now){:ok, _dropped} = emit_dropped_request(domain: dropped.domain, at: now)- {:ok, buffered} = emit_buffered_request(at: now)verify_record_written(dropped.domain, "dropped_not_found", 2)-- site_id = Plausible.Sites.get_by_domain(buffered.domain).id- verify_record_written(buffered.domain, "buffered", 1, site_id)endtest "the database eventually sums the records within 1-minute buckets", %{test: test} do@@ -126,25 +122,6 @@ defmodule Plausible.Ingestion.CountersTest do{:ok, dropped}end- defp emit_buffered_request(opts) do- domain = Keyword.get(opts, :domain, random_domain())- at = Keyword.get(opts, :at, @ts)-- site = new_site(domain: domain)-- payload = %{- name: "pageview",- url: "http://#{site.domain}",- v: 137- }-- conn = build_conn(:post, "/api/event", payload)- assert {:ok, request} = Request.build(conn, at)- assert {:ok, %{buffered: [buffered]}} = Event.build_and_buffer(request)-- {:ok, buffered}- end-defp start_counters(opts) doopts = Keyword.put(opts, :force_start?, true)%{start: {m, f, a}} = Counters.child_spec(opts)