From aede35a33a743fda4ae3357da5b396133acd50d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nelson=20Estev=C3=A3o?= Date: Tue, 7 Apr 2026 16:41:21 +0100 Subject: [PATCH] chore: remove dialyzer warnings on logflare/pubsub_rates/cache.ex --- .dialyzer_ignore.exs | 8 -------- lib/logflare/google/bigquery/bigquery.ex | 4 ++-- lib/logflare/pubsub_rates/cache.ex | 4 ++-- lib/logflare/user.ex | 6 +++--- test/logflare_web/controllers/user_controller_test.exs | 3 +-- 5 files changed, 8 insertions(+), 17 deletions(-) diff --git a/.dialyzer_ignore.exs b/.dialyzer_ignore.exs index 91813191bf..054614d4f6 100644 --- a/.dialyzer_ignore.exs +++ b/.dialyzer_ignore.exs @@ -9,7 +9,6 @@ {"lib/logflare/backends/adaptor/bigquery_adaptor.ex", :pattern_match}, {"lib/logflare/backends/adaptor/bigquery_adaptor.ex", :pattern_match_cov}, {"lib/logflare/backends/adaptor/clickhouse_adaptor.ex", :pattern_match}, - {"lib/logflare/backends/adaptor/clickhouse_adaptor/provisioner.ex", :pattern_match}, {"lib/logflare/backends/adaptor/clickhouse_adaptor/query_connection_sup.ex", :unknown_type}, {"lib/logflare/backends/adaptor/loki_adaptor.ex", :no_return}, {"lib/logflare/backends/adaptor/loki_adaptor.ex", :call}, @@ -17,8 +16,6 @@ {"lib/logflare/billing/stripe.ex", :call}, {"lib/logflare/endpoints.ex", :no_return}, {"lib/logflare/endpoints.ex", :call}, - {"lib/logflare/google/bigquery/bigquery.ex", :no_return}, - {"lib/logflare/google/bigquery/bigquery.ex", :call}, {"lib/logflare/google/bigquery/bigquery.ex", :pattern_match}, {"lib/logflare/google/cloud_resource_manager.ex", :call}, {"lib/logflare/google/cloud_resource_manager.ex", :pattern_match}, @@ -33,9 +30,6 @@ {"lib/logflare/logs/search_query_executor.ex", :no_return}, {"lib/logflare/lql/parser.ex", :no_return}, {"lib/logflare/lql/parser.ex", :unused_fun}, - {"lib/logflare/pubsub_rates/cache.ex", :invalid_contract}, - {"lib/logflare/pubsub_rates/cache.ex", :no_return}, - {"lib/logflare/pubsub_rates/cache.ex", :call}, {"lib/logflare/sources.ex", :no_return}, {"lib/logflare/sources.ex", :call}, {"lib/logflare/sources/source/bigquery/pipeline.ex", :pattern_match}, @@ -46,11 +40,9 @@ {"lib/logflare/sources/source/slack_hook_server/slack_hook_server.ex", :unused_fun}, {"lib/logflare/sources/source/supervisor.ex", :pattern_match}, {"lib/logflare/sources/source/supervisor.ex", :pattern_match_cov}, - {"lib/logflare/sources/source/supervisor.ex", :no_return}, {"lib/logflare/sources/source/webhook_notification_server/webhook_notification_server.ex", :unused_fun}, {"lib/logflare/sql/dialect_translation.ex", :pattern_match}, - {"lib/logflare/sql/dialect_translation.ex", :guard_fail}, {"lib/logflare_web/controllers/api/endpoint_controller.ex", :pattern_match}, {"lib/logflare_web/controllers/billing_controller.ex", :unused_fun}, {"lib/logflare_web/controllers/billing_controller.ex", :pattern_match_cov}, diff --git a/lib/logflare/google/bigquery/bigquery.ex b/lib/logflare/google/bigquery/bigquery.ex index 68aab553f0..388f5af8d7 100644 --- a/lib/logflare/google/bigquery/bigquery.ex +++ b/lib/logflare/google/bigquery/bigquery.ex @@ -22,7 +22,7 @@ defmodule Logflare.Google.BigQuery do @type ok_err_tup :: {:ok, term} | {:error, term} - @spec init_table!(pos_integer(), atom(), String.t(), integer(), String.t(), String.t()) :: + @spec init_table!(User.id(), atom(), String.t(), integer(), String.t(), String.t()) :: ok_err_tup def init_table!(user_id, source, project_id, ttl, dataset_location, dataset_id) when is_integer(user_id) and is_atom(source) and is_binary(project_id) and is_integer(ttl) and @@ -228,7 +228,7 @@ defmodule Logflare.Google.BigQuery do @doc """ Creates dataset, accepts user_id, dataset_id, dataset_location, project_id """ - @spec create_dataset(String.t(), String.t(), String.t(), String.t()) :: + @spec create_dataset(User.id(), String.t(), String.t(), String.t()) :: {:ok, Model.Dataset.t()} | {:error, Tesla.Env.t()} def create_dataset( user_id, diff --git a/lib/logflare/pubsub_rates/cache.ex b/lib/logflare/pubsub_rates/cache.ex index df504e9bba..af94238361 100644 --- a/lib/logflare/pubsub_rates/cache.ex +++ b/lib/logflare/pubsub_rates/cache.ex @@ -90,7 +90,7 @@ defmodule Logflare.PubSubRates.Cache do @doc """ Returns a node mapping of buffer lengths across the cluster. """ - @spec get_buffers(non_neg_integer() | :consolidated, non_neg_integer() | nil) :: map() + @spec get_buffers(non_neg_integer() | :consolidated, non_neg_integer() | nil) :: {atom(), map()} def get_buffers(source_id, backend_id) do Cachex.get(__MODULE__, {source_id, backend_id, "buffers"}) end @@ -108,7 +108,7 @@ defmodule Logflare.PubSubRates.Cache do Returns the sum of all buffers across the cluster for a given source and backend combination. """ @spec get_cluster_buffers(non_neg_integer()) :: non_neg_integer() - @spec get_cluster_buffers(non_neg_integer(), non_neg_integer()) :: non_neg_integer() + @spec get_cluster_buffers(non_neg_integer(), non_neg_integer() | nil) :: non_neg_integer() def get_cluster_buffers(source_id, backend_id \\ nil) when is_integer(source_id) do case get_buffers(source_id, backend_id) do {:ok, node_buffers} when node_buffers != nil -> merge_buffers(node_buffers) diff --git a/lib/logflare/user.ex b/lib/logflare/user.ex index 0d1d3a4d42..00e2e3edfb 100644 --- a/lib/logflare/user.ex +++ b/lib/logflare/user.ex @@ -16,6 +16,8 @@ defmodule Logflare.User do alias Logflare.Partners.Partner alias Logflare.Alerting.AlertQuery + @type id :: pos_integer() + @derive {Jason.Encoder, only: [ :email, @@ -228,8 +230,6 @@ defmodule Logflare.User do def validate_gcp_project(changeset, field, options \\ []) do validate_change(changeset, field, fn _, bigquery_project_id -> - user_id = Integer.to_string(options[:user_id]) - dataset_id = changeset.changes[:bigquery_dataset_id] || "#{options[:user_id]}" <> GCPConfig.dataset_id_append() @@ -239,7 +239,7 @@ defmodule Logflare.User do project_id = bigquery_project_id || bq_project_id() case BigQuery.create_dataset( - user_id, + options[:user_id], dataset_id, location, project_id diff --git a/test/logflare_web/controllers/user_controller_test.exs b/test/logflare_web/controllers/user_controller_test.exs index 0e3dc79920..e7681ac7c7 100644 --- a/test/logflare_web/controllers/user_controller_test.exs +++ b/test/logflare_web/controllers/user_controller_test.exs @@ -140,8 +140,7 @@ defmodule LogflareWeb.UserControllerTest do ) TestUtils.retry_assert(fn -> - u_id = to_string(u1_id) - assert_received {{:user_id, :project_id}, {^u_id, ^bq_project_id}} + assert_received {{:user_id, :project_id}, {^u1_id, ^bq_project_id}} end) TestUtils.retry_assert(fn ->