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

Add StatsD counters for media resolution results #405

Merged
merged 1 commit into from
Dec 23, 2020
Merged
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
5 changes: 5 additions & 0 deletions lib/ret_web/controllers/api/v1/media_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule RetWeb.Api.V1.MediaController do
use RetWeb, :controller
use Retry
alias Ret.Statix

def create(conn, %{"media" => %{"url" => url, "quality" => quality}, "version" => version}),
do: resolve_and_render(conn, url, version, String.to_atom(quality))
Expand Down Expand Up @@ -92,19 +93,23 @@ defmodule RetWeb.Api.V1.MediaController do

case Cachex.fetch(:media_urls, query) do
{_status, nil} ->
Statix.increment("ret.media_resolver.404")
conn |> send_resp(404, "")

{_status, %Ret.ResolvedMedia{ttl: ttl} = resolved_media} ->
if ttl do
Cachex.expire(:media_urls, query, :timer.seconds(ttl / 1000))
end

Statix.increment("ret.media_resolver.ok")
render_resolved_media(conn, resolved_media)

{:error, e} ->
Statix.increment("ret.media_resolver.500")
conn |> send_resp(500, e)

_ ->
Statix.increment("ret.media_resolver.500")
conn |> send_resp(500, "Error resolving media")
end
end
Expand Down