Skip to content

Commit

Permalink
Merge pull request #1872 from Logflare/feat/display-source-ttl
Browse files Browse the repository at this point in the history
feat: display source ttl
  • Loading branch information
Ziinc authored Dec 4, 2023
2 parents 24bdbe9 + c7946fa commit a23b5bf
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/logflare/billing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,8 @@
</small>
<small class="source-details">
cached: <%= @source.metrics.recent %></span>
</small>
<small class="source-details tw-inline-block">
ttl: <%= @source_ttl_days %> day</span>
</small>
</div>
2 changes: 1 addition & 1 deletion lib/logflare_web/templates/source/dashboard.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</span>
</div>
</div>
<%= 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)) %>
</li>
<% end %>
</ul>
Expand Down
14 changes: 14 additions & 0 deletions lib/logflare_web/views/source_view.ex
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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}, _plan) do
round(ttl / :timer.hours(24))
end
end
3 changes: 3 additions & 0 deletions test/logflare_web/controllers/source_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a23b5bf

Please sign in to comment.