From 7dd74a2d03aedade30a2fea415081afa0d1b910b Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Mon, 4 Dec 2023 07:43:12 +0800 Subject: [PATCH 1/3] feat: display source ttl --- lib/logflare/billing.ex | 2 +- lib/logflare/sources.ex | 1 + .../shared/dashboard_source_metadata.html.eex | 3 +++ .../templates/source/dashboard.html.eex | 2 +- lib/logflare_web/views/source_view.ex | 14 ++++++++++++++ .../controllers/source_controller_test.exs | 3 +++ 6 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/logflare/billing.ex b/lib/logflare/billing.ex index 3785d8b3d..bff3e8265 100644 --- a/lib/logflare/billing.ex +++ b/lib/logflare/billing.ex @@ -304,7 +304,7 @@ defmodule Logflare.Billing do raise "No Free Plan created yet in database." is_nil(plan) -> - Logger.error( + Logger.warning( "Customer is on a Stripe plan which doesn't exist in our plan list, defaulting to Free" ) diff --git a/lib/logflare/sources.ex b/lib/logflare/sources.ex index dc36c24ae..de4898da0 100644 --- a/lib/logflare/sources.ex +++ b/lib/logflare/sources.ex @@ -19,6 +19,7 @@ defmodule Logflare.Sources do alias Logflare.Source.BigQuery.SchemaBuilder alias Logflare.SourceSchemas alias Logflare.User + alias Logflare.Billing require Logger diff --git a/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex b/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex index 61bd9e428..ee0da00a7 100644 --- a/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex +++ b/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex @@ -44,5 +44,8 @@ cached: <%= @source.metrics.recent %> + + + ttl: <%= @source_ttl_days %> day diff --git a/lib/logflare_web/templates/source/dashboard.html.eex b/lib/logflare_web/templates/source/dashboard.html.eex index ed7115b4d..f259d80ba 100644 --- a/lib/logflare_web/templates/source/dashboard.html.eex +++ b/lib/logflare_web/templates/source/dashboard.html.eex @@ -113,7 +113,7 @@ - <%= render(LogflareWeb.SharedView, "dashboard_source_metadata.html", conn: @conn, source: source) %> + <%= render(LogflareWeb.SharedView, "dashboard_source_metadata.html", conn: @conn, source: source, source_ttl_days: source_ttl_to_days(source, @plan)) %> <% end %> diff --git a/lib/logflare_web/views/source_view.ex b/lib/logflare_web/views/source_view.ex index 974a78f46..215781b6c 100644 --- a/lib/logflare_web/views/source_view.ex +++ b/lib/logflare_web/views/source_view.ex @@ -1,6 +1,8 @@ defmodule LogflareWeb.SourceView do import LogflareWeb.Helpers.Forms alias LogflareWeb.Router.Helpers, as: Routes + alias Logflare.Billing.Plan + alias Logflare.Source use LogflareWeb, :view def log_url(route) do @@ -17,4 +19,16 @@ defmodule LogflareWeb.SourceView do end |> URI.to_string() end + + @doc """ + Formats a source TTL to the specified unit + """ + @spec source_ttl_to_days(Source.t(), Plan.t()) :: integer() + def source_ttl_to_days(%Source{bigquery_table_ttl: nil} = source, %Plan{} = plan) do + source_ttl_to_days(%{source | bigquery_table_ttl: plan.limit_source_ttl}, :day) + end + + def source_ttl_to_days(%Source{bigquery_table_ttl: ttl} = source, _plan) do + round(ttl / :timer.hours(24)) + end end diff --git a/test/logflare_web/controllers/source_controller_test.exs b/test/logflare_web/controllers/source_controller_test.exs index 41f148f69..8294fdf5e 100644 --- a/test/logflare_web/controllers/source_controller_test.exs +++ b/test/logflare_web/controllers/source_controller_test.exs @@ -41,6 +41,9 @@ defmodule LogflareWeb.SourceControllerTest do assert html =~ "Saved Searches" assert html =~ "Dashboard" assert html =~ source.name + + # default ttl + assert html =~ "ttl: 3 day" end test "show source", %{conn: conn, source: source} do From e1579896a67d54abfd7794cd41433c612b8f5614 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Mon, 4 Dec 2023 07:45:32 +0800 Subject: [PATCH 2/3] style: tweak display of source ttl --- .../templates/shared/dashboard_source_metadata.html.eex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex b/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex index ee0da00a7..00851b8b1 100644 --- a/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex +++ b/lib/logflare_web/templates/shared/dashboard_source_metadata.html.eex @@ -45,7 +45,7 @@ cached: <%= @source.metrics.recent %> - + ttl: <%= @source_ttl_days %> day From c7946fac2fddc22737fafb07fd43e4f702632948 Mon Sep 17 00:00:00 2001 From: TzeYiing Date: Mon, 4 Dec 2023 08:54:07 +0800 Subject: [PATCH 3/3] chore: compilation warnings --- lib/logflare/sources.ex | 1 - lib/logflare_web/views/source_view.ex | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/logflare/sources.ex b/lib/logflare/sources.ex index de4898da0..dc36c24ae 100644 --- a/lib/logflare/sources.ex +++ b/lib/logflare/sources.ex @@ -19,7 +19,6 @@ defmodule Logflare.Sources do alias Logflare.Source.BigQuery.SchemaBuilder alias Logflare.SourceSchemas alias Logflare.User - alias Logflare.Billing require Logger diff --git a/lib/logflare_web/views/source_view.ex b/lib/logflare_web/views/source_view.ex index 215781b6c..e3ae59c2f 100644 --- a/lib/logflare_web/views/source_view.ex +++ b/lib/logflare_web/views/source_view.ex @@ -28,7 +28,7 @@ defmodule LogflareWeb.SourceView do source_ttl_to_days(%{source | bigquery_table_ttl: plan.limit_source_ttl}, :day) end - def source_ttl_to_days(%Source{bigquery_table_ttl: ttl} = source, _plan) do + def source_ttl_to_days(%Source{bigquery_table_ttl: ttl}, _plan) do round(ttl / :timer.hours(24)) end end