Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display source ttl #1872

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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